[ADD] improved scaffolding, controllers scaffolding
alter tutorial module to use scaffolded structure
This commit is contained in:
parent
f41fde480d
commit
68eb0983f6
|
@ -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
|
customize the behavior of the OpenERP installation. The first step is thus to
|
||||||
create a module:
|
create a module:
|
||||||
|
|
||||||
.. todo:: code generator in oe?
|
.. code:: shell-session
|
||||||
|
|
||||||
* Create empty module (mandatory name, category)
|
> oe scaffold Academy
|
||||||
* Create controller (parent class?)
|
|
||||||
* Create model (concrete/abstract? Inherit?)
|
|
||||||
* Add field?
|
|
||||||
|
|
||||||
* Create a new folder called :file:`academy` in a module directory, inside it
|
.. patch::
|
||||||
create an empty file called :file:`__openerp__.py` with the following
|
:hidden:
|
||||||
content:
|
|
||||||
|
|
||||||
.. patch::
|
This builds a basic module for you, ignore anything in the ``models`` and
|
||||||
|
``security`` directories for now.
|
||||||
* 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).
|
|
||||||
|
|
||||||
.. todo::
|
.. 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
|
text, we can return a page, and use a tool/library like bootstrap_ to get a
|
||||||
nicer rendering than the default.
|
nicer rendering than the default.
|
||||||
|
|
||||||
Change the string returned by the ``index`` method to get a more page-ish
|
Go to :file:`academy/controllers/my_controller.py` and change the string
|
||||||
output:
|
returned by the ``index`` method to get a more page-ish output:
|
||||||
|
|
||||||
.. patch::
|
.. patch::
|
||||||
|
|
||||||
|
|
|
@ -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!"
|
|
|
@ -1,11 +1,11 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent b377930cec8f9445882bb3268f9f5fac71dd8c15
|
# Parent a76a9a0e0668f4191bdc383a0d4b3173f44b39b1
|
||||||
|
|
||||||
diff --git a/controllers.py b/controllers.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
--- a/controllers.py
|
--- a/controllers/my_controller.py
|
||||||
+++ b/controllers.py
|
+++ b/controllers/my_controller.py
|
||||||
@@ -4,4 +4,21 @@ from openerp.addons.web.controllers impo
|
@@ -6,4 +6,16 @@ from openerp.addons.web.controllers impo
|
||||||
class Home(main.Home):
|
class my_controller(main.Home):
|
||||||
@http.route('/', auth='none')
|
@http.route('/', auth='none')
|
||||||
def index(self):
|
def index(self):
|
||||||
- return "Hello, world!"
|
- return "Hello, world!"
|
||||||
|
@ -18,12 +18,7 @@ diff --git a/controllers.py b/controllers.py
|
||||||
+ <body class="container">
|
+ <body class="container">
|
||||||
+ <h1>Introduction to a thing</h1>
|
+ <h1>Introduction to a thing</h1>
|
||||||
+ <h2>Course description</h2>
|
+ <h2>Course description</h2>
|
||||||
+ <p>
|
+ <p>Course introduction</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>
|
|
||||||
+ </body>
|
+ </body>
|
||||||
+</html>
|
+</html>
|
||||||
+"""
|
+"""
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 2af29a429acda61e5e567997dad78a673e011796
|
# Parent 8799d7578ebf7aa0d81f0dbafa959f8abd106dff
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
+++ b/__openerp__.py
|
+++ b/__openerp__.py
|
||||||
@@ -5,7 +5,9 @@
|
@@ -19,8 +19,10 @@
|
||||||
'data': [
|
'data': [
|
||||||
'ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'views/templates.xml',
|
'views/templates.xml',
|
||||||
- 'data/teaching_assistants.xml',
|
- 'data/teaching_assistants.xml',
|
||||||
- 'data/lectures.xml',
|
- 'data/lectures.xml',
|
||||||
|
@ -13,8 +14,9 @@ diff --git a/__openerp__.py b/__openerp__.py
|
||||||
+ 'demo': [
|
+ 'demo': [
|
||||||
+ 'demo/teaching_assistants.xml',
|
+ 'demo/teaching_assistants.xml',
|
||||||
+ 'demo/lectures.xml',
|
+ 'demo/lectures.xml',
|
||||||
]
|
],
|
||||||
}
|
'tests': [
|
||||||
|
],
|
||||||
diff --git a/data/lectures.xml b/demo/lectures.xml
|
diff --git a/data/lectures.xml b/demo/lectures.xml
|
||||||
rename from data/lectures.xml
|
rename from data/lectures.xml
|
||||||
rename to demo/lectures.xml
|
rename to demo/lectures.xml
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 419f2476f7485ffc81eced5233f323c3bea76100
|
# Parent f8963c3ab009d422767aaaaa29f8ce08f84ac299
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
+++ b/__openerp__.py
|
+++ b/__openerp__.py
|
||||||
@@ -5,6 +5,7 @@
|
@@ -19,6 +19,7 @@
|
||||||
'data': [
|
'data': [
|
||||||
'ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'views/templates.xml',
|
'views/templates.xml',
|
||||||
+ 'data/views.xml',
|
+ 'data/views.xml',
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 65912bc56408d6bf61b2023a79a48e06a22fe9e2
|
# Parent 9042ace1e3e8175155d9dbed75657222a371cdb6
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
+++ b/__openerp__.py
|
+++ b/__openerp__.py
|
||||||
@@ -6,5 +6,6 @@
|
@@ -20,6 +20,7 @@
|
||||||
'ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'views/templates.xml',
|
'views/templates.xml',
|
||||||
'data/teaching_assistants.xml',
|
'data/teaching_assistants.xml',
|
||||||
+ 'data/lectures.xml',
|
+ 'data/lectures.xml',
|
||||||
]
|
],
|
||||||
}
|
'tests': [
|
||||||
diff --git a/controllers.py b/controllers.py
|
],
|
||||||
--- a/controllers.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
+++ b/controllers.py
|
--- a/controllers/my_controller.py
|
||||||
@@ -4,10 +4,15 @@ from openerp.addons.web.controllers impo
|
+++ b/controllers/my_controller.py
|
||||||
class Home(main.Home):
|
@@ -6,10 +6,15 @@ from openerp.addons.web.controllers impo
|
||||||
|
class my_controller(main.Home):
|
||||||
@http.route('/', auth='public')
|
@http.route('/', auth='public')
|
||||||
def index(self):
|
def index(self):
|
||||||
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
|
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
|
||||||
|
@ -59,17 +60,10 @@ new file mode 100644
|
||||||
+ </record>
|
+ </record>
|
||||||
+ </data>
|
+ </data>
|
||||||
+</openerp>
|
+</openerp>
|
||||||
diff --git a/ir.model.access.csv b/ir.model.access.csv
|
diff --git a/models/my_model.py b/models/my_model.py
|
||||||
--- a/ir.model.access.csv
|
--- a/models/my_model.py
|
||||||
+++ b/ir.model.access.csv
|
+++ b/models/my_model.py
|
||||||
@@ -1,2 +1,3 @@
|
@@ -8,3 +8,12 @@ class TeachingAssistants(orm.Model):
|
||||||
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):
|
|
||||||
'name': fields.char(),
|
'name': fields.char(),
|
||||||
'biography': fields.html(),
|
'biography': fields.html(),
|
||||||
}
|
}
|
||||||
|
@ -82,6 +76,14 @@ diff --git a/models.py b/models.py
|
||||||
+ 'name': fields.char(required=True),
|
+ 'name': fields.char(required=True),
|
||||||
+ 'date': fields.date(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
|
diff --git a/views/templates.xml b/views/templates.xml
|
||||||
--- a/views/templates.xml
|
--- a/views/templates.xml
|
||||||
+++ b/views/templates.xml
|
+++ b/views/templates.xml
|
||||||
|
|
|
@ -1,11 +1,90 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 0000000000000000000000000000000000000000
|
# 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
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/__openerp__.py
|
+++ b/__openerp__.py
|
||||||
@@ -0,0 +1,4 @@
|
@@ -0,0 +1,22 @@
|
||||||
|
+# -*- coding: utf-8 -*-
|
||||||
+{
|
+{
|
||||||
+ 'name': "Academy",
|
+ '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
|
||||||
|
|
|
@ -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
|
|
|
@ -1,6 +1,4 @@
|
||||||
manifest
|
manifest
|
||||||
basic-controller
|
|
||||||
module-init
|
|
||||||
basic-page
|
basic-page
|
||||||
ta-controller
|
ta-controller
|
||||||
url-pattern
|
url-pattern
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 30a859b5dc378c0da751537b1342e8d22775ad44
|
# Parent a615de71be483d88acca032ad5d35072c87999c0
|
||||||
|
|
||||||
diff --git a/controllers.py b/controllers.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
--- a/controllers.py
|
--- a/controllers/my_controller.py
|
||||||
+++ b/controllers.py
|
+++ b/controllers/my_controller.py
|
||||||
@@ -1,9 +1,22 @@
|
@@ -3,9 +3,22 @@
|
||||||
from openerp import http
|
from openerp import http
|
||||||
from openerp.addons.web.controllers import main
|
from openerp.addons.web.controllers import main
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ diff --git a/controllers.py b/controllers.py
|
||||||
+ {'name': "Tanya Harris"},
|
+ {'name': "Tanya Harris"},
|
||||||
+]
|
+]
|
||||||
+
|
+
|
||||||
class Home(main.Home):
|
class my_controller(main.Home):
|
||||||
@http.route('/', auth='none')
|
@http.route('/', auth='none')
|
||||||
def index(self):
|
def index(self):
|
||||||
+ tas = [
|
+ tas = [
|
||||||
|
@ -27,10 +27,10 @@ diff --git a/controllers.py b/controllers.py
|
||||||
return """<!doctype html>
|
return """<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@@ -19,6 +32,26 @@ class Home(main.Home):
|
@@ -16,6 +29,26 @@ class my_controller(main.Home):
|
||||||
will focus on the discovery of things and the planning and
|
<h1>Introduction to a thing</h1>
|
||||||
organization necessary to handle things.
|
<h2>Course description</h2>
|
||||||
</p>
|
<p>Course introduction</p>
|
||||||
+ <h2>Teaching Assistants</h2>
|
+ <h2>Teaching Assistants</h2>
|
||||||
+ <ul>
|
+ <ul>
|
||||||
+ %(tas)s
|
+ %(tas)s
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 94316d8049d7453cf70aff198b2d7ad1c04bf089
|
# Parent a35b5f4903087b1b31a4ecf33bfe655dc3ad5663
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
+++ b/__openerp__.py
|
+++ b/__openerp__.py
|
||||||
@@ -5,5 +5,6 @@
|
@@ -19,6 +19,7 @@
|
||||||
'data': [
|
'data': [
|
||||||
'ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'views/templates.xml',
|
'views/templates.xml',
|
||||||
+ 'data/teaching_assistants.xml',
|
+ 'data/teaching_assistants.xml',
|
||||||
]
|
],
|
||||||
}
|
'tests': [
|
||||||
|
],
|
||||||
diff --git a/data/teaching_assistants.xml b/data/teaching_assistants.xml
|
diff --git a/data/teaching_assistants.xml b/data/teaching_assistants.xml
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent e603b52f5a0484822964f6cefd7e5b389d44399b
|
# Parent 8cbdbbeaf1d89c9a4e4d03e2392ddcc79a648206
|
||||||
diff --git a/models.py b/models.py
|
|
||||||
--- a/models.py
|
diff --git a/models/my_model.py b/models/my_model.py
|
||||||
+++ b/models.py
|
--- a/models/my_model.py
|
||||||
@@ -7,4 +7,5 @@ class TeachingAssistants(orm.Model):
|
+++ b/models/my_model.py
|
||||||
|
@@ -6,4 +6,5 @@ class TeachingAssistants(orm.Model):
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char(),
|
'name': fields.char(),
|
||||||
|
|
|
@ -1,27 +1,10 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 9735c655933b94f5e9017d0aac0b6e579f23adba
|
# Parent b6ba23a3c284db481f14d9ea573e0baf8d3320e8
|
||||||
|
|
||||||
diff --git a/__init__.py b/__init__.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
--- a/__init__.py
|
--- a/controllers/my_controller.py
|
||||||
+++ b/__init__.py
|
+++ b/controllers/my_controller.py
|
||||||
@@ -1,1 +1,2 @@
|
@@ -3,19 +3,13 @@
|
||||||
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 @@
|
|
||||||
from openerp import http
|
from openerp import http
|
||||||
from openerp.addons.web.controllers import main
|
from openerp.addons.web.controllers import main
|
||||||
|
|
||||||
|
@ -33,7 +16,7 @@ diff --git a/controllers.py b/controllers.py
|
||||||
- {'name': "Tanya Harris"},
|
- {'name': "Tanya Harris"},
|
||||||
-]
|
-]
|
||||||
-
|
-
|
||||||
class Home(main.Home):
|
class my_controller(main.Home):
|
||||||
@http.route('/', auth='public')
|
@http.route('/', auth='public')
|
||||||
def index(self):
|
def index(self):
|
||||||
+ tas = http.request.registry['academy.tas'].search_read(
|
+ 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)
|
@http.route('/tas/<int:id>/', auth='public', website=True)
|
||||||
diff --git a/ir.model.access.csv b/ir.model.access.csv
|
diff --git a/models/my_model.py b/models/my_model.py
|
||||||
new file mode 100644
|
--- a/models/my_model.py
|
||||||
--- /dev/null
|
+++ b/models/my_model.py
|
||||||
+++ b/ir.model.access.csv
|
@@ -1,8 +1,8 @@
|
||||||
@@ -0,0 +1,2 @@
|
# -*- coding: utf-8 -*-
|
||||||
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
from openerp.osv import orm, fields
|
||||||
+access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0
|
|
||||||
diff --git a/models.py b/models.py
|
-class my_model(orm.Model):
|
||||||
new file mode 100644
|
- _name = "academy.my_model"
|
||||||
--- /dev/null
|
|
||||||
+++ b/models.py
|
|
||||||
@@ -0,0 +1,10 @@
|
|
||||||
+# -*- coding: utf-8 -*-
|
|
||||||
+
|
|
||||||
+from openerp.osv import orm, fields
|
|
||||||
+
|
|
||||||
+class TeachingAssistants(orm.Model):
|
+class TeachingAssistants(orm.Model):
|
||||||
+ _name = 'academy.tas'
|
+ _name = "academy.tas"
|
||||||
+
|
|
||||||
+ _columns = {
|
_columns = {
|
||||||
+ 'name': fields.char(),
|
'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
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent d757ab6e2223e63f283b31815c8ff650ea42e2e7
|
# Parent fa3e25d0315e54de4bd983ad8532044b5e2df233
|
||||||
diff --git a/controllers.py b/controllers.py
|
|
||||||
--- a/controllers.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
+++ b/controllers.py
|
--- a/controllers/my_controller.py
|
||||||
@@ -10,6 +10,8 @@ class Home(main.Home):
|
+++ b/controllers/my_controller.py
|
||||||
|
@@ -12,6 +12,8 @@ class my_controller(main.Home):
|
||||||
'tas': tas,
|
'tas': tas,
|
||||||
})
|
})
|
||||||
|
|
||||||
- @http.route('/tas/<int:id>/', auth='public', website=True)
|
- @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)
|
+ @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', {
|
+ return http.request.website.render('academy.ta', {
|
||||||
+ 'ta': ta
|
+ 'ta': ta,
|
||||||
+ })
|
+ })
|
||||||
diff --git a/views/templates.xml b/views/templates.xml
|
diff --git a/views/templates.xml b/views/templates.xml
|
||||||
--- a/views/templates.xml
|
--- a/views/templates.xml
|
||||||
|
|
|
@ -1,21 +1,25 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 0e882bf90a845788e155b437baf2b42c98901216
|
# Parent 170cc87a26983d34df5cd3bb27d3259722c586e5
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
+++ b/__openerp__.py
|
+++ b/__openerp__.py
|
||||||
@@ -1,4 +1,7 @@
|
@@ -16,7 +16,10 @@
|
||||||
{
|
|
||||||
'name': "Academy",
|
# any module necessary for this one to work correctly
|
||||||
'category': "Tools",
|
'depends': ['web'],
|
||||||
|
- 'data': ['security/ir.model.access.csv'],
|
||||||
+ 'data': [
|
+ 'data': [
|
||||||
|
+ 'security/ir.model.access.csv',
|
||||||
+ 'views/templates.xml',
|
+ 'views/templates.xml',
|
||||||
+ ]
|
+ ],
|
||||||
|
'tests': [
|
||||||
|
],
|
||||||
}
|
}
|
||||||
diff --git a/controllers.py b/controllers.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
--- a/controllers.py
|
--- a/controllers/my_controller.py
|
||||||
+++ b/controllers.py
|
+++ b/controllers/my_controller.py
|
||||||
@@ -17,41 +17,10 @@ class Home(main.Home):
|
@@ -19,36 +19,10 @@ class my_controller(main.Home):
|
||||||
for i, ta in enumerate(teaching_assistants)
|
for i, ta in enumerate(teaching_assistants)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -28,12 +32,7 @@ diff --git a/controllers.py b/controllers.py
|
||||||
- <body class="container">
|
- <body class="container">
|
||||||
- <h1>Introduction to a thing</h1>
|
- <h1>Introduction to a thing</h1>
|
||||||
- <h2>Course description</h2>
|
- <h2>Course description</h2>
|
||||||
- <p>
|
- <p>Course introduction</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>
|
|
||||||
- <h2>Teaching Assistants</h2>
|
- <h2>Teaching Assistants</h2>
|
||||||
- <ul>
|
- <ul>
|
||||||
- %(tas)s
|
- %(tas)s
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent a436864e066f91e51d30cc47f03fc42401c4296a
|
# Parent 1d6a01fae0bb650ea0de8437b3983a29f66463ed
|
||||||
diff --git a/controllers.py b/controllers.py
|
|
||||||
--- a/controllers.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
+++ b/controllers.py
|
--- a/controllers/my_controller.py
|
||||||
@@ -13,7 +13,7 @@ class Home(main.Home):
|
+++ b/controllers/my_controller.py
|
||||||
|
@@ -15,7 +15,7 @@ class my_controller(main.Home):
|
||||||
@http.route('/', auth='none')
|
@http.route('/', auth='none')
|
||||||
def index(self):
|
def index(self):
|
||||||
tas = [
|
tas = [
|
||||||
|
@ -12,7 +13,7 @@ diff --git a/controllers.py b/controllers.py
|
||||||
for i, ta in enumerate(teaching_assistants)
|
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)
|
'tas': '\n'.join(tas)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ diff --git a/controllers.py b/controllers.py
|
||||||
def ta(self, id):
|
def ta(self, id):
|
||||||
return """<!doctype html>
|
return """<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
@@ -54,4 +54,4 @@ class Home(main.Home):
|
@@ -51,4 +51,4 @@ class my_controller(main.Home):
|
||||||
<h1>%(name)s</h1>
|
<h1>%(name)s</h1>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 77db36690ddd8ad5065cab77837deec9da3df502
|
# Parent 5426218c6da91a13911e64eeb18a0cc2e19083c7
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
+++ b/__openerp__.py
|
+++ b/__openerp__.py
|
||||||
@@ -1,6 +1,7 @@
|
@@ -15,7 +15,7 @@
|
||||||
{
|
'version': '0.1',
|
||||||
'name': "Academy",
|
|
||||||
'category': "Tools",
|
# any module necessary for this one to work correctly
|
||||||
|
- 'depends': ['web'],
|
||||||
+ 'depends': ['website'],
|
+ 'depends': ['website'],
|
||||||
'data': [
|
'data': [
|
||||||
|
'security/ir.model.access.csv',
|
||||||
'views/templates.xml',
|
'views/templates.xml',
|
||||||
]
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
diff --git a/controllers.py b/controllers.py
|
--- a/controllers/my_controller.py
|
||||||
--- a/controllers.py
|
+++ b/controllers/my_controller.py
|
||||||
+++ b/controllers.py
|
@@ -12,17 +12,12 @@ teaching_assistants = [
|
||||||
@@ -10,17 +10,12 @@ teaching_assistants = [
|
|
||||||
]
|
]
|
||||||
|
|
||||||
class Home(main.Home):
|
class my_controller(main.Home):
|
||||||
- @http.route('/', auth='none')
|
- @http.route('/', auth='none')
|
||||||
+ @http.route('/', auth='public')
|
+ @http.route('/', auth='public')
|
||||||
def index(self):
|
def index(self):
|
||||||
|
|
|
@ -2,25 +2,46 @@
|
||||||
Generate an OpenERP module skeleton.
|
Generate an OpenERP module skeleton.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import functools
|
||||||
|
import keyword
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import jinja2
|
||||||
|
|
||||||
|
# FIXME: add logging
|
||||||
def run(args):
|
def run(args):
|
||||||
|
env = jinja2.Environment(loader=jinja2.PackageLoader(
|
||||||
|
'openerpcommand', 'templates'))
|
||||||
|
env.filters['snake'] = snake
|
||||||
assert args.module
|
assert args.module
|
||||||
module = args.module
|
args.dependency = 'web' if args.controller else 'base'
|
||||||
|
|
||||||
if os.path.exists(module):
|
module = functools.partial(os.path.join, snake(args.module))
|
||||||
print "The path `%s` already exists."
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
os.mkdir(module)
|
if os.path.exists(module()):
|
||||||
os.mkdir(os.path.join(module, 'models'))
|
message = "The path `%s` already exists." % module()
|
||||||
with open(os.path.join(module, '__openerp__.py'), 'w') as h:
|
die(message)
|
||||||
h.write(MANIFEST)
|
|
||||||
with open(os.path.join(module, '__init__.py'), 'w') as h:
|
dump(env, '__openerp__.jinja2', module('__openerp__.py'), config=args)
|
||||||
h.write(INIT_PY)
|
dump(env, '__init__.jinja2', module('__init__.py'), modules=[
|
||||||
with open(os.path.join(module, 'models', '__init__.py'), 'w') as h:
|
args.controller and 'controllers',
|
||||||
h.write(MODELS_PY % (module,))
|
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):
|
def add_parser(subparsers):
|
||||||
parser = subparsers.add_parser('scaffold',
|
parser = subparsers.add_parser('scaffold',
|
||||||
|
@ -28,50 +49,64 @@ def add_parser(subparsers):
|
||||||
parser.add_argument('module', metavar='MODULE',
|
parser.add_argument('module', metavar='MODULE',
|
||||||
help='the name of the generated 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 = """\
|
model = parser.add_mutually_exclusive_group()
|
||||||
# -*- coding: utf-8 -*-
|
model.add_argument('--model', type=identifier,
|
||||||
{
|
help="The name of the model to generate (default: %(default)s)")
|
||||||
'name': '<Module name>',
|
model.add_argument('--no-model', dest='model',
|
||||||
'version': '0.0',
|
action='store_const', const=None, help="Do not generate a model")
|
||||||
'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,
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
INIT_PY = """\
|
mod = parser.add_argument_group("Module information",
|
||||||
# -*- coding: utf-8 -*-
|
"these are added to the module metadata and displayed on e.g. "
|
||||||
import models
|
"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 = """\
|
parser.set_defaults(run=run, controller='my_controller', model='my_model')
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import openerp
|
|
||||||
|
|
||||||
# Define a new model.
|
def snake(s):
|
||||||
class my_model(openerp.osv.osv.Model):
|
""" 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)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
{% for module in modules if module -%}
|
||||||
|
import {{ module }}
|
||||||
|
{% endfor %}
|
|
@ -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': [
|
||||||
|
],
|
||||||
|
}
|
|
@ -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!"
|
|
@ -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 %}
|
|
@ -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(),
|
||||||
|
}
|
Loading…
Reference in New Issue