[ADD] improved scaffolding, controllers scaffolding

alter tutorial module to use scaffolded structure
This commit is contained in:
Xavier Morel 2014-02-05 15:54:50 +01:00
parent f41fde480d
commit 68eb0983f6
23 changed files with 362 additions and 252 deletions

View File

@ -22,31 +22,15 @@ In OpenERP, doing things takes the form of creating modules, and these modules
customize the behavior of the OpenERP installation. The first step is thus to
create a module:
.. todo:: code generator in oe?
.. code:: shell-session
* Create empty module (mandatory name, category)
* Create controller (parent class?)
* Create model (concrete/abstract? Inherit?)
* Add field?
> oe scaffold Academy
* Create a new folder called :file:`academy` in a module directory, inside it
create an empty file called :file:`__openerp__.py` with the following
content:
.. patch::
:hidden:
.. patch::
* Create a second file :file:`controllers.py`. This is where the code
interacting directly with your web browser will live. For starters, just
include the following in it:
.. patch::
* Finally, create a third file :file:`__init__.py` containing just:
.. patch::
This makes :file:`controllers.py` "visible" to openerp (by running the code
it holds).
This builds a basic module for you, ignore anything in the ``models`` and
``security`` directories for now.
.. todo::
@ -66,8 +50,8 @@ display). Let's prettify things a bit: instead of returning just a bit of
text, we can return a page, and use a tool/library like bootstrap_ to get a
nicer rendering than the default.
Change the string returned by the ``index`` method to get a more page-ish
output:
Go to :file:`academy/controllers/my_controller.py` and change the string
returned by the ``index`` method to get a more page-ish output:
.. patch::

View File

@ -1,15 +0,0 @@
# HG changeset patch
# Parent 458a542843918f6899fe64bfe1cead00972ef68a
diff --git a/controllers.py b/controllers.py
new file mode 100644
--- /dev/null
+++ b/controllers.py
@@ -0,0 +1,7 @@
+from openerp import http
+from openerp.addons.web.controllers import main
+
+class Home(main.Home):
+ @http.route('/', auth='none')
+ def index(self):
+ return "Hello, world!"

View File

@ -1,11 +1,11 @@
# HG changeset patch
# Parent b377930cec8f9445882bb3268f9f5fac71dd8c15
# Parent a76a9a0e0668f4191bdc383a0d4b3173f44b39b1
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -4,4 +4,21 @@ from openerp.addons.web.controllers impo
class Home(main.Home):
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -6,4 +6,16 @@ from openerp.addons.web.controllers impo
class my_controller(main.Home):
@http.route('/', auth='none')
def index(self):
- return "Hello, world!"
@ -18,12 +18,7 @@ diff --git a/controllers.py b/controllers.py
+ <body class="container">
+ <h1>Introduction to a thing</h1>
+ <h2>Course description</h2>
+ <p>
+ This course will provide a basic introduction to a thing, for
+ motivated students with no prior experience in things. The course
+ will focus on the discovery of things and the planning and
+ organization necessary to handle things.
+ </p>
+ <p>Course introduction</p>
+ </body>
+</html>
+"""

View File

@ -1,11 +1,12 @@
# HG changeset patch
# Parent 2af29a429acda61e5e567997dad78a673e011796
# Parent 8799d7578ebf7aa0d81f0dbafa959f8abd106dff
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -5,7 +5,9 @@
@@ -19,8 +19,10 @@
'data': [
'ir.model.access.csv',
'security/ir.model.access.csv',
'views/templates.xml',
- 'data/teaching_assistants.xml',
- 'data/lectures.xml',
@ -13,8 +14,9 @@ diff --git a/__openerp__.py b/__openerp__.py
+ 'demo': [
+ 'demo/teaching_assistants.xml',
+ 'demo/lectures.xml',
]
}
],
'tests': [
],
diff --git a/data/lectures.xml b/demo/lectures.xml
rename from data/lectures.xml
rename to demo/lectures.xml

View File

@ -1,11 +1,12 @@
# HG changeset patch
# Parent 419f2476f7485ffc81eced5233f323c3bea76100
# Parent f8963c3ab009d422767aaaaa29f8ce08f84ac299
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -5,6 +5,7 @@
@@ -19,6 +19,7 @@
'data': [
'ir.model.access.csv',
'security/ir.model.access.csv',
'views/templates.xml',
+ 'data/views.xml',
],

View File

@ -1,21 +1,22 @@
# HG changeset patch
# Parent 65912bc56408d6bf61b2023a79a48e06a22fe9e2
# Parent 9042ace1e3e8175155d9dbed75657222a371cdb6
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -6,5 +6,6 @@
'ir.model.access.csv',
@@ -20,6 +20,7 @@
'security/ir.model.access.csv',
'views/templates.xml',
'data/teaching_assistants.xml',
+ 'data/lectures.xml',
]
}
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -4,10 +4,15 @@ from openerp.addons.web.controllers impo
class Home(main.Home):
],
'tests': [
],
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -6,10 +6,15 @@ from openerp.addons.web.controllers impo
class my_controller(main.Home):
@http.route('/', auth='public')
def index(self):
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
@ -59,17 +60,10 @@ new file mode 100644
+ </record>
+ </data>
+</openerp>
diff --git a/ir.model.access.csv b/ir.model.access.csv
--- a/ir.model.access.csv
+++ b/ir.model.access.csv
@@ -1,2 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0
+access_academy_lectures,access_academy_lectures,model_academy_lectures,,1,0,0,0
diff --git a/models.py b/models.py
--- a/models.py
+++ b/models.py
@@ -9,3 +9,12 @@ class TeachingAssistants(orm.Model):
diff --git a/models/my_model.py b/models/my_model.py
--- a/models/my_model.py
+++ b/models/my_model.py
@@ -8,3 +8,12 @@ class TeachingAssistants(orm.Model):
'name': fields.char(),
'biography': fields.html(),
}
@ -82,6 +76,14 @@ diff --git a/models.py b/models.py
+ 'name': fields.char(required=True),
+ 'date': fields.date(required=True),
+ }
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
--- a/security/ir.model.access.csv
+++ b/security/ir.model.access.csv
@@ -1,2 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0
+access_academy_lectures,access_academy_lectures,model_academy_lectures,,1,0,0,0
\ No newline at end of file
diff --git a/views/templates.xml b/views/templates.xml
--- a/views/templates.xml
+++ b/views/templates.xml

View File

@ -1,11 +1,90 @@
# HG changeset patch
# Parent 0000000000000000000000000000000000000000
diff --git a/__init__.py b/__init__.py
new file mode 100644
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+import controllers
+import models
+
diff --git a/__openerp__.py b/__openerp__.py
new file mode 100644
--- /dev/null
+++ b/__openerp__.py
@@ -0,0 +1,4 @@
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+{
+ 'name': "Academy",
+ 'category': "Tools",
+ # short description, used as subtitles on modules listings
+ 'summary': "",
+ # long description of module purpose
+ 'description': """
+""",
+ # Who you are
+ 'author': "",
+ 'website': "",
+
+ # categories can be used to filter modules in modules listing
+ 'category': 'Uncategorized',
+ 'version': '0.1',
+
+ # any module necessary for this one to work correctly
+ 'depends': ['web'],
+ 'data': ['security/ir.model.access.csv'],
+ 'tests': [
+ ],
+}
diff --git a/controllers/__init__.py b/controllers/__init__.py
new file mode 100644
--- /dev/null
+++ b/controllers/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import my_controller
+
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
new file mode 100644
--- /dev/null
+++ b/controllers/my_controller.py
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+
+from openerp import http
+from openerp.addons.web.controllers import main
+
+class my_controller(main.Home):
+ @http.route('/', auth='none')
+ def index(self):
+ return "Hello, world!"
diff --git a/models/__init__.py b/models/__init__.py
new file mode 100644
--- /dev/null
+++ b/models/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import my_model
+
diff --git a/models/my_model.py b/models/my_model.py
new file mode 100644
--- /dev/null
+++ b/models/my_model.py
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+from openerp.osv import orm, fields
+
+class my_model(orm.Model):
+ _name = "academy.my_model"
+
+ _columns = {
+ 'name': fields.char(),
+ }
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
new file mode 100644
--- /dev/null
+++ b/security/ir.model.access.csv
@@ -0,0 +1,2 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_academy_my_model,access_academy_my_model,model_academy_my_model,,1,0,0,0

View File

@ -1,8 +0,0 @@
# HG changeset patch
# Parent 2d3441ff4321c4a931940e64fcfb2fe54bd0ad17
diff --git a/__init__.py b/__init__.py
new file mode 100644
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,1 @@
+import controllers

View File

@ -1,6 +1,4 @@
manifest
basic-controller
module-init
basic-page
ta-controller
url-pattern

View File

@ -1,10 +1,10 @@
# HG changeset patch
# Parent 30a859b5dc378c0da751537b1342e8d22775ad44
# Parent a615de71be483d88acca032ad5d35072c87999c0
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -1,9 +1,22 @@
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -3,9 +3,22 @@
from openerp import http
from openerp.addons.web.controllers import main
@ -16,7 +16,7 @@ diff --git a/controllers.py b/controllers.py
+ {'name': "Tanya Harris"},
+]
+
class Home(main.Home):
class my_controller(main.Home):
@http.route('/', auth='none')
def index(self):
+ tas = [
@ -27,10 +27,10 @@ diff --git a/controllers.py b/controllers.py
return """<!doctype html>
<html>
<head>
@@ -19,6 +32,26 @@ class Home(main.Home):
will focus on the discovery of things and the planning and
organization necessary to handle things.
</p>
@@ -16,6 +29,26 @@ class my_controller(main.Home):
<h1>Introduction to a thing</h1>
<h2>Course description</h2>
<p>Course introduction</p>
+ <h2>Teaching Assistants</h2>
+ <ul>
+ %(tas)s

View File

@ -1,16 +1,17 @@
# HG changeset patch
# Parent 94316d8049d7453cf70aff198b2d7ad1c04bf089
# Parent a35b5f4903087b1b31a4ecf33bfe655dc3ad5663
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -5,5 +5,6 @@
@@ -19,6 +19,7 @@
'data': [
'ir.model.access.csv',
'security/ir.model.access.csv',
'views/templates.xml',
+ 'data/teaching_assistants.xml',
]
}
],
'tests': [
],
diff --git a/data/teaching_assistants.xml b/data/teaching_assistants.xml
new file mode 100644
--- /dev/null

View File

@ -1,9 +1,10 @@
# HG changeset patch
# Parent e603b52f5a0484822964f6cefd7e5b389d44399b
diff --git a/models.py b/models.py
--- a/models.py
+++ b/models.py
@@ -7,4 +7,5 @@ class TeachingAssistants(orm.Model):
# Parent 8cbdbbeaf1d89c9a4e4d03e2392ddcc79a648206
diff --git a/models/my_model.py b/models/my_model.py
--- a/models/my_model.py
+++ b/models/my_model.py
@@ -6,4 +6,5 @@ class TeachingAssistants(orm.Model):
_columns = {
'name': fields.char(),

View File

@ -1,27 +1,10 @@
# HG changeset patch
# Parent 9735c655933b94f5e9017d0aac0b6e579f23adba
# Parent b6ba23a3c284db481f14d9ea573e0baf8d3320e8
diff --git a/__init__.py b/__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -1,1 +1,2 @@
import controllers
+import models
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -3,6 +3,7 @@
'category': "Tools",
'depends': ['website'],
'data': [
+ 'ir.model.access.csv',
'views/templates.xml',
]
}
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -1,19 +1,13 @@
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -3,19 +3,13 @@
from openerp import http
from openerp.addons.web.controllers import main
@ -33,7 +16,7 @@ diff --git a/controllers.py b/controllers.py
- {'name': "Tanya Harris"},
-]
-
class Home(main.Home):
class my_controller(main.Home):
@http.route('/', auth='public')
def index(self):
+ tas = http.request.registry['academy.tas'].search_read(
@ -44,25 +27,24 @@ diff --git a/controllers.py b/controllers.py
})
@http.route('/tas/<int:id>/', auth='public', website=True)
diff --git a/ir.model.access.csv b/ir.model.access.csv
new file mode 100644
--- /dev/null
+++ b/ir.model.access.csv
@@ -0,0 +1,2 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0
diff --git a/models.py b/models.py
new file mode 100644
--- /dev/null
+++ b/models.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+
+from openerp.osv import orm, fields
+
diff --git a/models/my_model.py b/models/my_model.py
--- a/models/my_model.py
+++ b/models/my_model.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from openerp.osv import orm, fields
-class my_model(orm.Model):
- _name = "academy.my_model"
+class TeachingAssistants(orm.Model):
+ _name = 'academy.tas'
+
+ _columns = {
+ 'name': fields.char(),
+ }
+ _name = "academy.tas"
_columns = {
'name': fields.char(),
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
--- a/security/ir.model.access.csv
+++ b/security/ir.model.access.csv
@@ -1,2 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
-access_academy_my_model,access_academy_my_model,model_academy_my_model,,1,0,0,0
+access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0

View File

@ -1,19 +1,19 @@
# HG changeset patch
# Parent d757ab6e2223e63f283b31815c8ff650ea42e2e7
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -10,6 +10,8 @@ class Home(main.Home):
# Parent fa3e25d0315e54de4bd983ad8532044b5e2df233
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -12,6 +12,8 @@ class my_controller(main.Home):
'tas': tas,
})
- @http.route('/tas/<int:id>/', auth='public', website=True)
- def ta(self, id):
- return http.request.website.render('academy.ta', teaching_assistants[id])
+ @http.route('/tas/<model("academy.tas"):ta>/', auth='public', website=True)
+ def ta(self, ta):
def ta(self, id):
- return http.request.website.render('academy.ta', teaching_assistants[id])
+ return http.request.website.render('academy.ta', {
+ 'ta': ta
+ 'ta': ta,
+ })
diff --git a/views/templates.xml b/views/templates.xml
--- a/views/templates.xml

View File

@ -1,21 +1,25 @@
# HG changeset patch
# Parent 0e882bf90a845788e155b437baf2b42c98901216
# Parent 170cc87a26983d34df5cd3bb27d3259722c586e5
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -1,4 +1,7 @@
{
'name': "Academy",
'category': "Tools",
@@ -16,7 +16,10 @@
# any module necessary for this one to work correctly
'depends': ['web'],
- 'data': ['security/ir.model.access.csv'],
+ 'data': [
+ 'security/ir.model.access.csv',
+ 'views/templates.xml',
+ ]
+ ],
'tests': [
],
}
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -17,41 +17,10 @@ class Home(main.Home):
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -19,36 +19,10 @@ class my_controller(main.Home):
for i, ta in enumerate(teaching_assistants)
]
@ -28,12 +32,7 @@ diff --git a/controllers.py b/controllers.py
- <body class="container">
- <h1>Introduction to a thing</h1>
- <h2>Course description</h2>
- <p>
- This course will provide a basic introduction to a thing, for
- motivated students with no prior experience in things. The course
- will focus on the discovery of things and the planning and
- organization necessary to handle things.
- </p>
- <p>Course introduction</p>
- <h2>Teaching Assistants</h2>
- <ul>
- %(tas)s

View File

@ -1,9 +1,10 @@
# HG changeset patch
# Parent a436864e066f91e51d30cc47f03fc42401c4296a
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -13,7 +13,7 @@ class Home(main.Home):
# Parent 1d6a01fae0bb650ea0de8437b3983a29f66463ed
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -15,7 +15,7 @@ class my_controller(main.Home):
@http.route('/', auth='none')
def index(self):
tas = [
@ -12,7 +13,7 @@ diff --git a/controllers.py b/controllers.py
for i, ta in enumerate(teaching_assistants)
]
@@ -42,7 +42,7 @@ class Home(main.Home):
@@ -39,7 +39,7 @@ class my_controller(main.Home):
'tas': '\n'.join(tas)
}
@ -21,7 +22,7 @@ diff --git a/controllers.py b/controllers.py
def ta(self, id):
return """<!doctype html>
<html>
@@ -54,4 +54,4 @@ class Home(main.Home):
@@ -51,4 +51,4 @@ class my_controller(main.Home):
<h1>%(name)s</h1>
</body>
</html>

View File

@ -1,24 +1,25 @@
# HG changeset patch
# Parent 77db36690ddd8ad5065cab77837deec9da3df502
# Parent 5426218c6da91a13911e64eeb18a0cc2e19083c7
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -1,6 +1,7 @@
{
'name': "Academy",
'category': "Tools",
@@ -15,7 +15,7 @@
'version': '0.1',
# any module necessary for this one to work correctly
- 'depends': ['web'],
+ 'depends': ['website'],
'data': [
'security/ir.model.access.csv',
'views/templates.xml',
]
diff --git a/controllers.py b/controllers.py
--- a/controllers.py
+++ b/controllers.py
@@ -10,17 +10,12 @@ teaching_assistants = [
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
--- a/controllers/my_controller.py
+++ b/controllers/my_controller.py
@@ -12,17 +12,12 @@ teaching_assistants = [
]
class Home(main.Home):
class my_controller(main.Home):
- @http.route('/', auth='none')
+ @http.route('/', auth='public')
def index(self):

View File

@ -2,25 +2,46 @@
Generate an OpenERP module skeleton.
"""
import functools
import keyword
import os
import re
import sys
import jinja2
# FIXME: add logging
def run(args):
env = jinja2.Environment(loader=jinja2.PackageLoader(
'openerpcommand', 'templates'))
env.filters['snake'] = snake
assert args.module
module = args.module
args.dependency = 'web' if args.controller else 'base'
if os.path.exists(module):
print "The path `%s` already exists."
sys.exit(1)
module = functools.partial(os.path.join, snake(args.module))
os.mkdir(module)
os.mkdir(os.path.join(module, 'models'))
with open(os.path.join(module, '__openerp__.py'), 'w') as h:
h.write(MANIFEST)
with open(os.path.join(module, '__init__.py'), 'w') as h:
h.write(INIT_PY)
with open(os.path.join(module, 'models', '__init__.py'), 'w') as h:
h.write(MODELS_PY % (module,))
if os.path.exists(module()):
message = "The path `%s` already exists." % module()
die(message)
dump(env, '__openerp__.jinja2', module('__openerp__.py'), config=args)
dump(env, '__init__.jinja2', module('__init__.py'), modules=[
args.controller and 'controllers',
args.model and 'models'
])
dump(env, 'ir.model.access.jinja2', module('security', 'ir.model.access.csv'), config=args)
if args.controller:
controller_module = snake(args.controller)
dump(env, '__init__.jinja2', module('controllers', '__init__.py'), modules=[controller_module])
dump(env, 'controllers.jinja2',
module('controllers', '%s.py' % controller_module),
config=args)
if args.model:
model_module = snake(args.model)
dump(env, '__init__.jinja2', module('models', '__init__.py'), modules=[model_module])
dump(env, 'models.jinja2', module('models', '%s.py' % model_module), config=args)
def add_parser(subparsers):
parser = subparsers.add_parser('scaffold',
@ -28,50 +49,64 @@ def add_parser(subparsers):
parser.add_argument('module', metavar='MODULE',
help='the name of the generated module')
parser.set_defaults(run=run)
controller = parser.add_mutually_exclusive_group()
controller.add_argument('--controller', type=identifier,
help="The name of the controller to generate (default: %(default)s)")
controller.add_argument('--no-controller', dest='controller',
action='store_const', const=None, help="Do not generate a controller")
MANIFEST = """\
# -*- coding: utf-8 -*-
{
'name': '<Module name>',
'version': '0.0',
'category': '<Category>',
'description': '''
<Long description>
''',
'author': '<author>',
'maintainer': '<maintainer>',
'website': 'http://<website>',
# Add any module that are necessary for this module to correctly work in
# the `depends` list.
'depends': ['base'],
'data': [
],
'test': [
],
# Set to False if you want to prevent the module to be known by OpenERP
# (and thus appearing in the list of modules).
'installable': True,
# Set to True if you want the module to be automatically whenever all its
# dependencies are installed.
'auto_install': False,
}
"""
model = parser.add_mutually_exclusive_group()
model.add_argument('--model', type=identifier,
help="The name of the model to generate (default: %(default)s)")
model.add_argument('--no-model', dest='model',
action='store_const', const=None, help="Do not generate a model")
INIT_PY = """\
# -*- coding: utf-8 -*-
import models
"""
mod = parser.add_argument_group("Module information",
"these are added to the module metadata and displayed on e.g. "
"apps.openerp.com. For company-backed modules, the company "
"information should be used")
mod.add_argument('--name', dest='author_name', default="",
help="Name of the module author")
mod.add_argument('--website', dest='author_website', default="",
help="Website of the module author")
mod.add_argument('--category', default="Uncategorized",
help="Broad categories to which the module belongs, used for "
"filtering within OpenERP and on apps.openerp.com. "
"Defaults to %(default)s")
mod.add_argument('--summary', default="",
help="Short (1 phrase/line) summary of the module's purpose, used as "
"subtitle on modules listing or apps.openerp.com")
MODELS_PY = """\
# -*- coding: utf-8 -*-
import openerp
parser.set_defaults(run=run, controller='my_controller', model='my_model')
# Define a new model.
class my_model(openerp.osv.osv.Model):
def snake(s):
""" snake cases ``s``
_name = '%s.my_model'
:param str s:
:return: str
"""
# insert a space before each uppercase character preceded by a
# non-uppercase letter
s = re.sub(r'(?<=[^A-Z])\B([A-Z])', r' \1', s)
# lowercase everything, split on whitespace and join
return '_'.join(s.lower().split())
_columns = {
}
"""
def dump(env, template, dest, **kwargs):
outdir = os.path.dirname(dest)
if not os.path.exists(outdir):
os.makedirs(outdir)
env.get_template(template).stream(**kwargs).dump(dest)
# add trailing newline which jinja removes
with open(dest, 'a') as f:
f.write('\n')
def identifier(s):
if keyword.iskeyword(s):
die("%s is a Python keyword and can not be used as a name" % s)
if not re.match('[A-Za-z_][A-Za-z0-9_]*', s):
die("%s is not a valid Python identifier" % s)
return s
def die(message, code=1):
print >>sys.stderr, message
sys.exit(code)

View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
{% for module in modules if module -%}
import {{ module }}
{% endfor %}

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
{
'name': "{{ config.module }}",
# short description, used as subtitles on modules listings
'summary': "{{ config.summary }}",
# long description of module purpose
'description': """
""",
# Who you are
'author': "{{ config.author_name }}",
'website': "{{ config.author_website }}",
# categories can be used to filter modules in modules listing
'category': '{{ config.category }}',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['{{ config.dependency }}'],
'data': [
{{- "'security/ir.model.access.csv'" if config.model -}}
],
'tests': [
],
}

View File

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
from openerp import http
from openerp.addons.web.controllers import main
class {{ config.controller }}(main.Home):
@http.route('/', auth='none')
def index(self):
return "Hello, world!"

View File

@ -0,0 +1,6 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
{% if config.model -%}
access_{{ config.module|snake }}_{{ config.model|snake }},{{- '' -}}
access_{{ config.module|snake }}_{{ config.model|snake }},{{- '' -}}
model_{{ config.module|snake }}_{{ config.model|snake }},,1,0,0,0
{%- endif %}

View File

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
from openerp.osv import orm, fields
class {{ config.model }}(orm.Model):
_name = "{{ config.module|snake }}.{{ config.model|snake }}"
_columns = {
'name': fields.char(),
}