summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-02-05 15:54:50 +0100
committerXavier Morel <xmo@openerp.com>2014-05-19 08:32:09 +0200
commit68eb0983f68a41a1d389f565df65f94a544f43da (patch)
treeaf17e41ac1bfe71e4a72819907929b63561618a7
parentf41fde480d3780a31b744ec0653e044458c31661 (diff)
[ADD] improved scaffolding, controllers scaffolding
alter tutorial module to use scaffolded structure
-rw-r--r--doc/howto/howto_website.rst32
-rw-r--r--doc/howto/howto_website/basic-controller15
-rw-r--r--doc/howto/howto_website/basic-page19
-rw-r--r--doc/howto/howto_website/data-to-demo12
-rw-r--r--doc/howto/howto_website/lectures-action-and-menus7
-rw-r--r--doc/howto/howto_website/lectures-model-add44
-rw-r--r--doc/howto/howto_website/manifest83
-rw-r--r--doc/howto/howto_website/module-init8
-rw-r--r--doc/howto/howto_website/series2
-rw-r--r--doc/howto/howto_website/ta-controller20
-rw-r--r--doc/howto/howto_website/ta-data11
-rw-r--r--doc/howto/howto_website/ta-html-biography11
-rw-r--r--doc/howto/howto_website/ta-model70
-rw-r--r--doc/howto/howto_website/ta-view-fix18
-rw-r--r--doc/howto/howto_website/templates-basic31
-rw-r--r--doc/howto/howto_website/url-pattern15
-rw-r--r--doc/howto/howto_website/website-dependency23
-rw-r--r--openerpcommand/scaffold.py143
-rw-r--r--openerpcommand/templates/__init__.jinja24
-rw-r--r--openerpcommand/templates/__openerp__.jinja224
-rw-r--r--openerpcommand/templates/controllers.jinja29
-rw-r--r--openerpcommand/templates/ir.model.access.jinja26
-rw-r--r--openerpcommand/templates/models.jinja29
23 files changed, 363 insertions, 253 deletions
diff --git a/doc/howto/howto_website.rst b/doc/howto/howto_website.rst
index 0ca53e49610..7eccd24935f 100644
--- a/doc/howto/howto_website.rst
+++ b/doc/howto/howto_website.rst
@@ -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::
-
-* 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::
+.. patch::
+ :hidden:
- 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::
diff --git a/doc/howto/howto_website/basic-controller b/doc/howto/howto_website/basic-controller
deleted file mode 100644
index 4415d9516bc..00000000000
--- a/doc/howto/howto_website/basic-controller
+++ /dev/null
@@ -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!"
diff --git a/doc/howto/howto_website/basic-page b/doc/howto/howto_website/basic-page
index 5a60c346acf..9e6c9d9abc7 100644
--- a/doc/howto/howto_website/basic-page
+++ b/doc/howto/howto_website/basic-page
@@ -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>
+"""
diff --git a/doc/howto/howto_website/data-to-demo b/doc/howto/howto_website/data-to-demo
index 4c0797f0543..2be34f484cf 100644
--- a/doc/howto/howto_website/data-to-demo
+++ b/doc/howto/howto_website/data-to-demo
@@ -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
diff --git a/doc/howto/howto_website/lectures-action-and-menus b/doc/howto/howto_website/lectures-action-and-menus
index 2f851491c9a..3ca5c055f39 100644
--- a/doc/howto/howto_website/lectures-action-and-menus
+++ b/doc/howto/howto_website/lectures-action-and-menus
@@ -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',
],
diff --git a/doc/howto/howto_website/lectures-model-add b/doc/howto/howto_website/lectures-model-add
index dd53130721d..a467817faad 100644
--- a/doc/howto/howto_website/lectures-model-add
+++ b/doc/howto/howto_website/lectures-model-add
@@ -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
diff --git a/doc/howto/howto_website/manifest b/doc/howto/howto_website/manifest
index 3cf359c9b30..3c81585b522 100644
--- a/doc/howto/howto_website/manifest
+++ b/doc/howto/howto_website/manifest
@@ -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
diff --git a/doc/howto/howto_website/module-init b/doc/howto/howto_website/module-init
deleted file mode 100644
index 4484236edc9..00000000000
--- a/doc/howto/howto_website/module-init
+++ /dev/null
@@ -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
diff --git a/doc/howto/howto_website/series b/doc/howto/howto_website/series
index e8b52f313a3..d34c6476bb7 100644
--- a/doc/howto/howto_website/series
+++ b/doc/howto/howto_website/series
@@ -1,6 +1,4 @@
manifest
-basic-controller
-module-init
basic-page
ta-controller
url-pattern
diff --git a/doc/howto/howto_website/ta-controller b/doc/howto/howto_website/ta-controller
index 5b8d0b799d5..080111bb4d4 100644
--- a/doc/howto/howto_website/ta-controller
+++ b/doc/howto/howto_website/ta-controller
@@ -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
diff --git a/doc/howto/howto_website/ta-data b/doc/howto/howto_website/ta-data
index c38eae470ed..395b5a2b430 100644
--- a/doc/howto/howto_website/ta-data
+++ b/doc/howto/howto_website/ta-data
@@ -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
diff --git a/doc/howto/howto_website/ta-html-biography b/doc/howto/howto_website/ta-html-biography
index 5d9dbc0ab09..23da32b1e4e 100644
--- a/doc/howto/howto_website/ta-html-biography
+++ b/doc/howto/howto_website/ta-html-biography
@@ -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(),
diff --git a/doc/howto/howto_website/ta-model b/doc/howto/howto_website/ta-model
index 7b9917cb85a..83a74c83c51 100644
--- a/doc/howto/howto_website/ta-model
+++ b/doc/howto/howto_website/ta-model
@@ -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
diff --git a/doc/howto/howto_website/ta-view-fix b/doc/howto/howto_website/ta-view-fix
index 88fcdef1787..dac105dba9e 100644
--- a/doc/howto/howto_website/ta-view-fix
+++ b/doc/howto/howto_website/ta-view-fix
@@ -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
diff --git a/doc/howto/howto_website/templates-basic b/doc/howto/howto_website/templates-basic
index ebce6f468bd..b0e5d85c487 100644
--- a/doc/howto/howto_website/templates-basic
+++ b/doc/howto/howto_website/templates-basic
@@ -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
diff --git a/doc/howto/howto_website/url-pattern b/doc/howto/howto_website/url-pattern
index 8f37b1bdcda..72be995a7b8 100644
--- a/doc/howto/howto_website/url-pattern
+++ b/doc/howto/howto_website/url-pattern
@@ -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>
diff --git a/doc/howto/howto_website/website-dependency b/doc/howto/howto_website/website-dependency
index 51bc6a6c9df..6910aff199e 100644
--- a/doc/howto/howto_website/website-dependency
+++ b/doc/howto/howto_website/website-dependency
@@ -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):
diff --git a/openerpcommand/scaffold.py b/openerpcommand/scaffold.py
index e590653c91b..845122dcb75 100644
--- a/openerpcommand/scaffold.py
+++ b/openerpcommand/scaffold.py
@@ -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'
+
+ module = functools.partial(os.path.join, snake(args.module))
+
+ if os.path.exists(module()):
+ message = "The path `%s` already exists." % module()
+ die(message)
- if os.path.exists(module):
- print "The path `%s` already exists."
- sys.exit(1)
+ 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)
- 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 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)
-
-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,
-}
-"""
+ 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")
-INIT_PY = """\
-# -*- coding: utf-8 -*-
-import models
-"""
+ 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")
-MODELS_PY = """\
-# -*- coding: utf-8 -*-
-import openerp
+ 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")
-# Define a new model.
-class my_model(openerp.osv.osv.Model):
+ parser.set_defaults(run=run, controller='my_controller', model='my_model')
- _name = '%s.my_model'
+def snake(s):
+ """ snake cases ``s``
- _columns = {
- }
-"""
+ :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())
+
+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)
diff --git a/openerpcommand/templates/__init__.jinja2 b/openerpcommand/templates/__init__.jinja2
new file mode 100644
index 00000000000..0124cdd2d93
--- /dev/null
+++ b/openerpcommand/templates/__init__.jinja2
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+{% for module in modules if module -%}
+import {{ module }}
+{% endfor %}
diff --git a/openerpcommand/templates/__openerp__.jinja2 b/openerpcommand/templates/__openerp__.jinja2
new file mode 100644
index 00000000000..d37a6f33334
--- /dev/null
+++ b/openerpcommand/templates/__openerp__.jinja2
@@ -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': [
+ ],
+}
diff --git a/openerpcommand/templates/controllers.jinja2 b/openerpcommand/templates/controllers.jinja2
new file mode 100644
index 00000000000..3cc47365d40
--- /dev/null
+++ b/openerpcommand/templates/controllers.jinja2
@@ -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!"
diff --git a/openerpcommand/templates/ir.model.access.jinja2 b/openerpcommand/templates/ir.model.access.jinja2
new file mode 100644
index 00000000000..e5e2fb35fe7
--- /dev/null
+++ b/openerpcommand/templates/ir.model.access.jinja2
@@ -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 %}
diff --git a/openerpcommand/templates/models.jinja2 b/openerpcommand/templates/models.jinja2
new file mode 100644
index 00000000000..878bf9be4f6
--- /dev/null
+++ b/openerpcommand/templates/models.jinja2
@@ -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(),
+ }