# HG changeset patch
# User Sylvain <syt@logilab.fr>
# Date 1229616554 -3600
#      Thu Dec 18 17:09:14 2008 +0100
# Node ID eaa65c0bdafbb7310a0a87dc9a8e4278ff15ce61
# Parent  0000000000000000000000000000000000000000
turn into a cube

diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include *.py
+
+recursive-include i18n *.pot *.po
+recursive-include migration *.sql *.py 
diff --git a/__init__.py b/__init__.py
new file mode 100644
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,4 @@
+"""cubicweb-fresh application package
+
+expense reporting application
+"""
diff --git a/__pkginfo__.py b/__pkginfo__.py
new file mode 100644
--- /dev/null
+++ b/__pkginfo__.py
@@ -0,0 +1,55 @@
+# pylint: disable-msg=W0622
+"""cubicweb-fresh application packaging information"""
+
+distname = 'cubicweb-fresh'
+
+numversion = (0, 1, 0)
+version = '.'.join(str(num) for num in numversion)
+
+license = 'LCL'
+copyright = '''Copyright (c) 2008 LOGILAB S.A. (Paris, FRANCE).
+http://www.logilab.fr/ -- mailto:contact@logilab.fr'''
+
+author = 'Logilab'
+author_email = 'contact@logilab.fr'
+
+short_desc = 'expense reporting application'
+long_desc = '''expense reporting application'''
+
+from os import listdir as _listdir
+from os.path import join, isdir
+
+web, ftp = '', ''
+
+pyversions = ['2.4']
+
+#from cubicweb.devtools.pkginfo import get_distutils_datafiles
+TEMPLATES_DIR = join('share', 'cubicweb', 'cubes')
+THIS_TEMPLATE_DIR = join(TEMPLATES_DIR, 'fresh')
+
+def listdir(dirpath):
+    return [join(dirpath, fname) for fname in _listdir(dirpath)
+            if fname[0] != '.' and not fname.endswith('.pyc')
+            and not fname.endswith('~')]
+
+try:
+    data_files = [
+        # common files
+        [THIS_TEMPLATE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']],
+
+        # client (web) files
+        [join(THIS_TEMPLATE_DIR, 'i18n'),  listdir('i18n')],
+        # Note: here, you'll need to add views' subdirectories if you want
+        # them to be included in the debian package
+        
+        # server files
+        [join(THIS_TEMPLATE_DIR, 'migration'), listdir('migration')],
+        ]
+except OSError:
+    # we are in an installed directory
+    pass
+
+
+cube_eid = None # <=== FIXME if you need direct bug-subscription
+__use__ = ('expense', 'workcase')
+
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,6 @@
+cubicweb-fresh (0.1.0-1) unstable; urgency=low
+
+  * initial release
+
+ -- 
+
diff --git a/debian/compat b/debian/compat
new file mode 100644
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1,1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,19 @@
+Source: cubicweb-fresh
+Section: web
+Priority: optional
+Maintainer: Logilab Packaging Team <contact@logilab.fr>
+Uploaders: Sylvain Thenault <sylvain.thenault@logilab.fr> 
+Build-Depends: debhelper (>= 5.0.37.1), python (>=2.4), python-dev (>=2.4)
+Standards-Version: 3.8.0
+
+
+Package: cubicweb-fresh
+Architecture: all
+Conflicts: erudi-fresh, erudi-fresh-client, erudi-fresh-server, erudi-fresh-comp
+Replaces: erudi-fresh, erudi-fresh-client, erudi-fresh-server, erudi-fresh-comp
+Depends: cubicweb-common (>= 2.99.0)
+Description: expense reporting application
+ CubicWeb is a entities / relations bases knowledge management system
+ developed at Logilab.
+ .
+ expense reporting application
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,14 @@
+This package was debianized by Logilab <contact@logilab.fr>
+
+Upstream Author: 
+
+  Logilab <contact@logilab.fr>
+
+Copyright:
+
+Copyright (c) 2008 LOGILAB S.A. (Paris, FRANCE).
+http://www.logilab.fr/ -- mailto:contact@logilab.fr
+
+Logilab Closed source License. This code is *NOT* open-source. Usage of this
+code is subject to a licence agreement. If you want to use it, you should
+contact logilab's sales service at commercial@logilab.fr .
diff --git a/debian/cubicweb-fresh.prerm b/debian/cubicweb-fresh.prerm
new file mode 100644
--- /dev/null
+++ b/debian/cubicweb-fresh.prerm
@@ -0,0 +1,27 @@
+#!/bin/sh -e
+
+delete_pyo_pyc () {
+  find /usr/share/cubicweb/cubes/fresh -name "*.pyc" | xargs rm -f
+  find /usr/share/cubicweb/cubes/fresh -name "*.pyo" | xargs rm -f
+}
+
+
+case "$1" in
+    failed-upgrade|abort-install|abort-upgrade|disappear)
+    ;;
+    upgrade)
+    delete_pyo_pyc
+    ;;
+    remove)
+    delete_pyo_pyc
+    ;;
+    purge)
+    ;;
+
+    *)
+        echo "postrm called with unknown argument \`$1'" >&2
+        exit 1
+
+esac
+
+#DEBHELPER#
diff --git a/debian/rules b/debian/rules
new file mode 100755
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,51 @@
+#!/usr/bin/make -f
+# Sample debian/rules that uses debhelper.
+# GNU copyright 1997 to 1999 by Joey Hess.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+build: build-stamp
+build-stamp: 
+	dh_testdir
+	python setup.py -q build
+	touch build-stamp
+
+clean: 
+	dh_testdir
+	dh_testroot
+	rm -f build-stamp configure-stamp
+	rm -rf build
+	find . -name "*.pyc" | xargs rm -f
+	dh_clean
+
+install: build
+	dh_testdir
+	dh_testroot
+	dh_clean -k
+	dh_installdirs -i
+	python setup.py -q install --no-compile --prefix=debian/cubicweb-fresh/usr/
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+	dh_testdir
+	dh_testroot
+	dh_install -i
+	dh_installchangelogs -i
+	dh_installexamples -i
+	dh_installdocs -i
+	dh_installman -i
+	dh_link -i
+	dh_compress -i -X.py -X.ini -X.xml -Xtest
+	dh_fixperms -i
+	dh_installdeb -i
+	dh_gencontrol -i 
+	dh_md5sums -i
+	dh_builddeb -i
+
+
+# Build architecture-dependent files here.
+binary-arch: 
+
+binary: binary-indep 
+.PHONY: build clean binary-arch binary-indep binary
diff --git a/entities.py b/entities.py
new file mode 100644
--- /dev/null
+++ b/entities.py
@@ -0,0 +1,16 @@
+"""this contains the template-specific entities' classes"""
+
+from eexpense.entities import Expense as BaseExpense, ExpenseLine as BaseExpenseLine
+
+class Expense(BaseExpense):
+
+    __rtags__ = {'spent_for' : 'primary'}
+    widgets = {'spent_for' : 'RestrictedAutoCompletionWidget'}
+    autocomplete_initfuncs = {'spent_for' : 'get_concerned_by'}
+    
+
+class ExpenseLine(BaseExpenseLine):
+
+    __rtags__ = {
+        'paid_by' : 'primary',
+        }
diff --git a/i18n/en.po b/i18n/en.po
new file mode 100644
--- /dev/null
+++ b/i18n/en.po
@@ -0,0 +1,7 @@
+msgid ""
+msgstr ""
+"Content-Type: text/plain; charset=ISO-8859-1\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: pygettext.py 1.5\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
diff --git a/i18n/fr.po b/i18n/fr.po
new file mode 100644
--- /dev/null
+++ b/i18n/fr.po
@@ -0,0 +1,13 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: 2.0\n"
+"POT-Creation-Date: 2006-01-12 17:35+CET\n"
+"PO-Revision-Date: 2008-02-15 12:55+0100\n"
+"Last-Translator: Logilab\n"
+"Language-Team: French <devel@logilab.fr.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=ISO-8859-15\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: pygettext.py 1.5\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
diff --git a/migration/postcreate.py b/migration/postcreate.py
new file mode 100644
--- /dev/null
+++ b/migration/postcreate.py
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+# postcreate script. You could setup a workflow here for example
+
+for login in (u'alf', u'syt', u'nico', u'jphc', u'ocy', u'auc', u'katia',
+              u'graz', u'dede', u'juj', u'ludal', u'steph', u'arthur',
+              u'david', u'joel', u'gaston', u'adim'):
+    rql('INSERT EUser E: E login %(login)s, E upassword %(login)s, E in_group G '
+        'WHERE G name "users"', {'login' : login})
+    rql('INSERT PaidByAccount P: P label %(label)s, P associated_to U WHERE U login %(login)s',
+        {'label' : u"refund account - %s" % login, 'login': login})
+    rql('INSERT PaidForAccount P: P label %(label)s', {'label' : u"charge account - %s" % login})
+
+
+for label in (u'Logilab - CB Nicolas', u'Logilab - CB Alexandre', u'Logilab - CB Olivier',
+              u'Logilab - Espèces'):
+    rql('INSERT PaidByAccount P: P label %(label)s', {'label' : label})
diff --git a/migration/precreate.py b/migration/precreate.py
new file mode 100644
--- /dev/null
+++ b/migration/precreate.py
@@ -0,0 +1,3 @@
+# Instructions here will be read before reading the schema
+# You could create your own groups here, like in :
+#   add_entity('EGroup', name=u'mygroup')
diff --git a/schema.py b/schema.py
new file mode 100644
--- /dev/null
+++ b/schema.py
@@ -0,0 +1,4 @@
+# template's specific schema
+Expense = import_erschema('Expense')
+Expense.add_relation(SubjectRelation('Workcase', cardinality='?*'), name='spent_for')
+
diff --git a/setup.py b/setup.py
new file mode 100644
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# pylint: disable-msg=W0404,W0622,W0704,W0613,W0152
+# Copyright (c) 2003-2004 LOGILAB S.A. (Paris, FRANCE).
+# http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+""" Generic Setup script, takes package info from __pkginfo__.py file """
+
+import os
+import sys
+import shutil
+from distutils.core import setup
+from distutils import command
+from distutils.command import install_lib
+from os.path import isdir, exists, join, walk
+
+# import required features
+from __pkginfo__ import distname, version, license, short_desc, long_desc, \
+     web, author, author_email
+try:
+    from __pkginfo__ import scripts
+except ImportError:
+    scripts = []
+try:
+    from __pkginfo__ import data_files
+except ImportError:
+    data_files = None
+    
+def ensure_scripts(linux_scripts):
+    """creates the proper script names required for each platform
+    (taken from 4Suite)
+    """
+    from distutils import util
+    if util.get_platform()[:3] == 'win':
+        scripts_ = [script + '.bat' for script in linux_scripts]
+    else:
+        scripts_ = linux_scripts
+    return scripts_
+
+def install(**kwargs):
+    """setup entry point"""
+    return setup(name=distname,
+                 version=version,
+                 license =license,
+                 description=short_desc,
+                 long_description=long_desc,
+                 author=author,
+                 author_email=author_email,
+                 url=web,
+                 scripts=ensure_scripts(scripts),
+                 data_files=data_files,
+                 **kwargs)
+            
+if __name__ == '__main__' :
+    install()
diff --git a/test/data/bootstrap_cubes b/test/data/bootstrap_cubes
new file mode 100644
--- /dev/null
+++ b/test/data/bootstrap_cubes
@@ -0,0 +1,1 @@
+fresh
diff --git a/test/test_fresh.py b/test/test_fresh.py
new file mode 100644
--- /dev/null
+++ b/test/test_fresh.py
@@ -0,0 +1,16 @@
+"""template automatic tests"""
+
+from logilab.common.testlib import TestCase, unittest_main
+
+class DefaultTC(TestCase):
+    def test_something(self):
+        self.skip('this component has no test')
+
+## uncomment the import if you want to activate automatic test for your
+## template
+
+# from cubicweb.devtools.testlib import AutomaticWebTest
+
+
+if __name__ == '__main__':
+    unittest_main()
diff --git a/views.py b/views.py
new file mode 100644
--- /dev/null
+++ b/views.py
@@ -0,0 +1,14 @@
+"""Specific controllers for CRM.
+
+:organization: Logilab
+:copyright: 2003-2007 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+"""
+__docformat__ = "restructuredtext en"
+
+from cubicweb.web.views.basecontrollers import JSonController
+
+def js_get_concerned_by(self):
+    return self.req.execute('DISTINCT Any W,R WHERE W ref R ORDERBY R').rows
+
+JSonController.js_get_concerned_by = js_get_concerned_by