Skip to content

Commit 68eb098

Browse files
committed
[ADD] improved scaffolding, controllers scaffolding
alter tutorial module to use scaffolded structure
1 parent f41fde4 commit 68eb098

23 files changed

+363
-253
lines changed

doc/howto/howto_website.rst

+8-24
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,15 @@ In OpenERP, doing things takes the form of creating modules, and these modules
2222
customize the behavior of the OpenERP installation. The first step is thus to
2323
create a module:
2424

25-
.. todo:: code generator in oe?
25+
.. code:: shell-session
2626
27-
* Create empty module (mandatory name, category)
28-
* Create controller (parent class?)
29-
* Create model (concrete/abstract? Inherit?)
30-
* Add field?
27+
> oe scaffold Academy
3128
32-
* Create a new folder called :file:`academy` in a module directory, inside it
33-
create an empty file called :file:`__openerp__.py` with the following
34-
content:
35-
36-
.. patch::
37-
38-
* Create a second file :file:`controllers.py`. This is where the code
39-
interacting directly with your web browser will live. For starters, just
40-
include the following in it:
41-
42-
.. patch::
43-
44-
* Finally, create a third file :file:`__init__.py` containing just:
45-
46-
.. patch::
29+
.. patch::
30+
:hidden:
4731

48-
This makes :file:`controllers.py` "visible" to openerp (by running the code
49-
it holds).
32+
This builds a basic module for you, ignore anything in the ``models`` and
33+
``security`` directories for now.
5034

5135
.. todo::
5236

@@ -66,8 +50,8 @@ display). Let's prettify things a bit: instead of returning just a bit of
6650
text, we can return a page, and use a tool/library like bootstrap_ to get a
6751
nicer rendering than the default.
6852

69-
Change the string returned by the ``index`` method to get a more page-ish
70-
output:
53+
Go to :file:`academy/controllers/my_controller.py` and change the string
54+
returned by the ``index`` method to get a more page-ish output:
7155

7256
.. patch::
7357

doc/howto/howto_website/basic-controller

-15
This file was deleted.

doc/howto/howto_website/basic-page

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# HG changeset patch
2-
# Parent b377930cec8f9445882bb3268f9f5fac71dd8c15
2+
# Parent a76a9a0e0668f4191bdc383a0d4b3173f44b39b1
33

4-
diff --git a/controllers.py b/controllers.py
5-
--- a/controllers.py
6-
+++ b/controllers.py
7-
@@ -4,4 +4,21 @@ from openerp.addons.web.controllers impo
8-
class Home(main.Home):
4+
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
5+
--- a/controllers/my_controller.py
6+
+++ b/controllers/my_controller.py
7+
@@ -6,4 +6,16 @@ from openerp.addons.web.controllers impo
8+
class my_controller(main.Home):
99
@http.route('/', auth='none')
1010
def index(self):
1111
- return "Hello, world!"
@@ -18,12 +18,7 @@ diff --git a/controllers.py b/controllers.py
1818
+ <body class="container">
1919
+ <h1>Introduction to a thing</h1>
2020
+ <h2>Course description</h2>
21-
+ <p>
22-
+ This course will provide a basic introduction to a thing, for
23-
+ motivated students with no prior experience in things. The course
24-
+ will focus on the discovery of things and the planning and
25-
+ organization necessary to handle things.
26-
+ </p>
21+
+ <p>Course introduction</p>
2722
+ </body>
2823
+</html>
2924
+"""

doc/howto/howto_website/data-to-demo

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# HG changeset patch
2-
# Parent 2af29a429acda61e5e567997dad78a673e011796
2+
# Parent 8799d7578ebf7aa0d81f0dbafa959f8abd106dff
3+
34
diff --git a/__openerp__.py b/__openerp__.py
45
--- a/__openerp__.py
56
+++ b/__openerp__.py
6-
@@ -5,7 +5,9 @@
7+
@@ -19,8 +19,10 @@
78
'data': [
8-
'ir.model.access.csv',
9+
'security/ir.model.access.csv',
910
'views/templates.xml',
1011
- 'data/teaching_assistants.xml',
1112
- 'data/lectures.xml',
1213
+ ],
1314
+ 'demo': [
1415
+ 'demo/teaching_assistants.xml',
1516
+ 'demo/lectures.xml',
16-
]
17-
}
17+
],
18+
'tests': [
19+
],
1820
diff --git a/data/lectures.xml b/demo/lectures.xml
1921
rename from data/lectures.xml
2022
rename to demo/lectures.xml

doc/howto/howto_website/lectures-action-and-menus

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# HG changeset patch
2-
# Parent 419f2476f7485ffc81eced5233f323c3bea76100
2+
# Parent f8963c3ab009d422767aaaaa29f8ce08f84ac299
3+
34
diff --git a/__openerp__.py b/__openerp__.py
45
--- a/__openerp__.py
56
+++ b/__openerp__.py
6-
@@ -5,6 +5,7 @@
7+
@@ -19,6 +19,7 @@
78
'data': [
8-
'ir.model.access.csv',
9+
'security/ir.model.access.csv',
910
'views/templates.xml',
1011
+ 'data/views.xml',
1112
],

doc/howto/howto_website/lectures-model-add

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# HG changeset patch
2-
# Parent 65912bc56408d6bf61b2023a79a48e06a22fe9e2
2+
# Parent 9042ace1e3e8175155d9dbed75657222a371cdb6
33

44
diff --git a/__openerp__.py b/__openerp__.py
55
--- a/__openerp__.py
66
+++ b/__openerp__.py
7-
@@ -6,5 +6,6 @@
8-
'ir.model.access.csv',
7+
@@ -20,6 +20,7 @@
8+
'security/ir.model.access.csv',
99
'views/templates.xml',
1010
'data/teaching_assistants.xml',
1111
+ 'data/lectures.xml',
12-
]
13-
}
14-
diff --git a/controllers.py b/controllers.py
15-
--- a/controllers.py
16-
+++ b/controllers.py
17-
@@ -4,10 +4,15 @@ from openerp.addons.web.controllers impo
18-
class Home(main.Home):
12+
],
13+
'tests': [
14+
],
15+
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
16+
--- a/controllers/my_controller.py
17+
+++ b/controllers/my_controller.py
18+
@@ -6,10 +6,15 @@ from openerp.addons.web.controllers impo
19+
class my_controller(main.Home):
1920
@http.route('/', auth='public')
2021
def index(self):
2122
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
@@ -59,17 +60,10 @@ new file mode 100644
5960
+ </record>
6061
+ </data>
6162
+</openerp>
62-
diff --git a/ir.model.access.csv b/ir.model.access.csv
63-
--- a/ir.model.access.csv
64-
+++ b/ir.model.access.csv
65-
@@ -1,2 +1,3 @@
66-
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
67-
access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0
68-
+access_academy_lectures,access_academy_lectures,model_academy_lectures,,1,0,0,0
69-
diff --git a/models.py b/models.py
70-
--- a/models.py
71-
+++ b/models.py
72-
@@ -9,3 +9,12 @@ class TeachingAssistants(orm.Model):
63+
diff --git a/models/my_model.py b/models/my_model.py
64+
--- a/models/my_model.py
65+
+++ b/models/my_model.py
66+
@@ -8,3 +8,12 @@ class TeachingAssistants(orm.Model):
7367
'name': fields.char(),
7468
'biography': fields.html(),
7569
}
@@ -82,6 +76,14 @@ diff --git a/models.py b/models.py
8276
+ 'name': fields.char(required=True),
8377
+ 'date': fields.date(required=True),
8478
+ }
79+
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
80+
--- a/security/ir.model.access.csv
81+
+++ b/security/ir.model.access.csv
82+
@@ -1,2 +1,3 @@
83+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
84+
access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0
85+
+access_academy_lectures,access_academy_lectures,model_academy_lectures,,1,0,0,0
86+
\ No newline at end of file
8587
diff --git a/views/templates.xml b/views/templates.xml
8688
--- a/views/templates.xml
8789
+++ b/views/templates.xml

doc/howto/howto_website/manifest

+81-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,90 @@
11
# HG changeset patch
22
# Parent 0000000000000000000000000000000000000000
3+
4+
diff --git a/__init__.py b/__init__.py
5+
new file mode 100644
6+
--- /dev/null
7+
+++ b/__init__.py
8+
@@ -0,0 +1,4 @@
9+
+# -*- coding: utf-8 -*-
10+
+import controllers
11+
+import models
12+
+
313
diff --git a/__openerp__.py b/__openerp__.py
414
new file mode 100644
515
--- /dev/null
616
+++ b/__openerp__.py
7-
@@ -0,0 +1,4 @@
17+
@@ -0,0 +1,22 @@
18+
+# -*- coding: utf-8 -*-
819
+{
920
+ 'name': "Academy",
10-
+ 'category': "Tools",
21+
+ # short description, used as subtitles on modules listings
22+
+ 'summary': "",
23+
+ # long description of module purpose
24+
+ 'description': """
25+
+""",
26+
+ # Who you are
27+
+ 'author': "",
28+
+ 'website': "",
29+
+
30+
+ # categories can be used to filter modules in modules listing
31+
+ 'category': 'Uncategorized',
32+
+ 'version': '0.1',
33+
+
34+
+ # any module necessary for this one to work correctly
35+
+ 'depends': ['web'],
36+
+ 'data': ['security/ir.model.access.csv'],
37+
+ 'tests': [
38+
+ ],
1139
+}
40+
diff --git a/controllers/__init__.py b/controllers/__init__.py
41+
new file mode 100644
42+
--- /dev/null
43+
+++ b/controllers/__init__.py
44+
@@ -0,0 +1,3 @@
45+
+# -*- coding: utf-8 -*-
46+
+import my_controller
47+
+
48+
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
49+
new file mode 100644
50+
--- /dev/null
51+
+++ b/controllers/my_controller.py
52+
@@ -0,0 +1,9 @@
53+
+# -*- coding: utf-8 -*-
54+
+
55+
+from openerp import http
56+
+from openerp.addons.web.controllers import main
57+
+
58+
+class my_controller(main.Home):
59+
+ @http.route('/', auth='none')
60+
+ def index(self):
61+
+ return "Hello, world!"
62+
diff --git a/models/__init__.py b/models/__init__.py
63+
new file mode 100644
64+
--- /dev/null
65+
+++ b/models/__init__.py
66+
@@ -0,0 +1,3 @@
67+
+# -*- coding: utf-8 -*-
68+
+import my_model
69+
+
70+
diff --git a/models/my_model.py b/models/my_model.py
71+
new file mode 100644
72+
--- /dev/null
73+
+++ b/models/my_model.py
74+
@@ -0,0 +1,9 @@
75+
+# -*- coding: utf-8 -*-
76+
+from openerp.osv import orm, fields
77+
+
78+
+class my_model(orm.Model):
79+
+ _name = "academy.my_model"
80+
+
81+
+ _columns = {
82+
+ 'name': fields.char(),
83+
+ }
84+
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
85+
new file mode 100644
86+
--- /dev/null
87+
+++ b/security/ir.model.access.csv
88+
@@ -0,0 +1,2 @@
89+
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
90+
+access_academy_my_model,access_academy_my_model,model_academy_my_model,,1,0,0,0

doc/howto/howto_website/module-init

-8
This file was deleted.

doc/howto/howto_website/series

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
manifest
2-
basic-controller
3-
module-init
42
basic-page
53
ta-controller
64
url-pattern

doc/howto/howto_website/ta-controller

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# HG changeset patch
2-
# Parent 30a859b5dc378c0da751537b1342e8d22775ad44
2+
# Parent a615de71be483d88acca032ad5d35072c87999c0
33

4-
diff --git a/controllers.py b/controllers.py
5-
--- a/controllers.py
6-
+++ b/controllers.py
7-
@@ -1,9 +1,22 @@
4+
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
5+
--- a/controllers/my_controller.py
6+
+++ b/controllers/my_controller.py
7+
@@ -3,9 +3,22 @@
88
from openerp import http
99
from openerp.addons.web.controllers import main
1010

@@ -16,7 +16,7 @@ diff --git a/controllers.py b/controllers.py
1616
+ {'name': "Tanya Harris"},
1717
+]
1818
+
19-
class Home(main.Home):
19+
class my_controller(main.Home):
2020
@http.route('/', auth='none')
2121
def index(self):
2222
+ tas = [
@@ -27,10 +27,10 @@ diff --git a/controllers.py b/controllers.py
2727
return """<!doctype html>
2828
<html>
2929
<head>
30-
@@ -19,6 +32,26 @@ class Home(main.Home):
31-
will focus on the discovery of things and the planning and
32-
organization necessary to handle things.
33-
</p>
30+
@@ -16,6 +29,26 @@ class my_controller(main.Home):
31+
<h1>Introduction to a thing</h1>
32+
<h2>Course description</h2>
33+
<p>Course introduction</p>
3434
+ <h2>Teaching Assistants</h2>
3535
+ <ul>
3636
+ %(tas)s

doc/howto/howto_website/ta-data

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# HG changeset patch
2-
# Parent 94316d8049d7453cf70aff198b2d7ad1c04bf089
2+
# Parent a35b5f4903087b1b31a4ecf33bfe655dc3ad5663
33

44
diff --git a/__openerp__.py b/__openerp__.py
55
--- a/__openerp__.py
66
+++ b/__openerp__.py
7-
@@ -5,5 +5,6 @@
7+
@@ -19,6 +19,7 @@
88
'data': [
9-
'ir.model.access.csv',
9+
'security/ir.model.access.csv',
1010
'views/templates.xml',
1111
+ 'data/teaching_assistants.xml',
12-
]
13-
}
12+
],
13+
'tests': [
14+
],
1415
diff --git a/data/teaching_assistants.xml b/data/teaching_assistants.xml
1516
new file mode 100644
1617
--- /dev/null

doc/howto/howto_website/ta-html-biography

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# HG changeset patch
2-
# Parent e603b52f5a0484822964f6cefd7e5b389d44399b
3-
diff --git a/models.py b/models.py
4-
--- a/models.py
5-
+++ b/models.py
6-
@@ -7,4 +7,5 @@ class TeachingAssistants(orm.Model):
2+
# Parent 8cbdbbeaf1d89c9a4e4d03e2392ddcc79a648206
3+
4+
diff --git a/models/my_model.py b/models/my_model.py
5+
--- a/models/my_model.py
6+
+++ b/models/my_model.py
7+
@@ -6,4 +6,5 @@ class TeachingAssistants(orm.Model):
78

89
_columns = {
910
'name': fields.char(),

0 commit comments

Comments
 (0)