Skip to content

Commit cfc7015

Browse files
committed
[FIX] templating section, some wording
1 parent 66d8934 commit cfc7015

File tree

4 files changed

+68
-32
lines changed

4 files changed

+68
-32
lines changed

doc/howto/howto_website.rst

+40-17
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,29 @@ create a module:
3131
.. patch::
3232
:hidden:
3333

34-
This builds a basic module for you, ignore anything in the ``models`` and
35-
``security`` directories for now.
34+
This builds a basic module for you:
35+
36+
.. code-block:: text
37+
38+
academy
39+
├── __init__.py
40+
├── __openerp__.py
41+
├── controllers
42+
│   ├── __init__.py
43+
│   └── my_controller.py
44+
├── models
45+
│   ├── __init__.py
46+
│   └── my_model.py
47+
└── security
48+
└── ir.model.access.csv
49+
50+
Ignore anything in the ``models`` and ``security`` directories for now.
3651

3752
.. todo::
3853

3954
* instructions for start & install
4055
* db handling
56+
4157
- if existing db, automatically selected
4258
- if no existing db, nodb -> login -> login of first db
4359
- dbfilter
@@ -46,6 +62,8 @@ Now start your OpenERP server and install your module in it, open a web
4662
browser and navigate to http://localhost:8069. A page should appear with just
4763
the words "Hello, world!" on it.
4864

65+
.. todo:: screenshot?
66+
4967
Let's prettify things a bit: instead of returning just a bit of text,
5068
we can return a page, and use a tool like bootstrap_ to get a
5169
nicer rendering than the default.
@@ -57,21 +75,28 @@ returned by the ``index`` method to get a more page-ish output:
5775

5876
.. note::
5977

60-
this example requires internet access at all time, as we're accessing a
61-
:abbr:`CDN (Content Delivery Network, large distributed networks hosting
62-
static files and trying to provide high-performance and high-availability
63-
of these files)`-hosted file.
78+
this example requires internet access as we're accessing a :abbr:`CDN
79+
(Content Delivery Network, large distributed networks hosting static files
80+
and trying to provide high-performance and high-availability of these
81+
files)`-hosted file.
82+
83+
.. todo:: screenshot
6484

6585
Data input: URL and query
6686
=========================
6787

6888
Being able to build a static page in code is nice, but makes for limited
69-
usefulness (you could do that with static files in the first place).
89+
usefulness (you could do that with static files).
90+
91+
You can also create dynamic pages which use data provided in the URL,
92+
for instance so a single controller generates multiple pages. Any
93+
query parameter (``?name=value``) is passed as a string parameter to the
94+
controller method.
7095

71-
You can also create controllers which use data provided in the access URL,
72-
for instance so you have a single controller generating multiple pages. Any
73-
query parameter (``?name=value``) is passed as a parameter to the controller
74-
function, and is a string.
96+
For instance, the index page can display a list of teaching assistants linking
97+
to a page for each assistant through their index in a global array. Each
98+
assistant's page will simply print their name by applying the index to the
99+
array:
75100

76101
.. patch::
77102

@@ -89,16 +114,14 @@ This can be done by adding `converter patterns`_ to the URL in
89114
These patterns can perform conversions directly (in this case the conversion
90115
from a string URL section to a python integer) and will perform a some
91116
validation (if the ``id`` is not a valid integer, the converter will return a
92-
``404 Not Found`` instead of generating a server error when the conversion
93-
fails).
117+
``404 Not Found`` instead of a 500 server error when the conversion fails).
94118

95119
Templating: better experience in editing
96120
========================================
97121

98-
So far we've created HTML output by munging together Python strings using
99-
string concatenation and formatting. It works, but is not exactly fun to edit
100-
(and somewhat unsafe to boot) as even advanced text editors have a hard time
101-
understanding they're dealing with HTML embedded in Python code.
122+
So far we've output HTML by munging strings. It works, but is not exactly fun
123+
to edit (and somewhat unsafe to boot) as even advanced text editors have a
124+
hard time understanding they're dealing with HTML embedded in Python code.
102125

103126
The usual solution is to use templates_, documents with placeholders which can
104127
be "rendered" to produce final pages (or others). OpenERP lets you use any

doc/howto/howto_website/templates-basic

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# HG changeset patch
2-
# Parent 170cc87a26983d34df5cd3bb27d3259722c586e5
2+
# Parent 0792d59a4a456e1ce70d8aa4cb1784632883d714
33

44
diff --git a/__openerp__.py b/__openerp__.py
55
--- a/__openerp__.py
@@ -19,7 +19,13 @@ diff --git a/__openerp__.py b/__openerp__.py
1919
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
2020
--- a/controllers/my_controller.py
2121
+++ b/controllers/my_controller.py
22-
@@ -19,36 +19,10 @@ class my_controller(main.Home):
22+
@@ -14,41 +14,18 @@ teaching_assistants = [
23+
class my_controller(main.Home):
24+
@http.route('/', auth='none')
25+
def index(self):
26+
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
27+
tas = [
28+
'<li><a href="/tas/%d/">%s</a></li>' % (i, ta['name'])
2329
for i, ta in enumerate(teaching_assistants)
2430
]
2531

@@ -42,9 +48,9 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
4248
-""" % {
4349
- 'tas': '\n'.join(tas)
4450
- }
45-
+ return "" % {
51+
+ return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', {
4652
+ 'tas': '\n'.join(tas)
47-
+ }
53+
+ }, context=context)
4854

4955
@http.route('/tas/<int:id>/', auth='none')
5056
def ta(self, id):
@@ -59,15 +65,17 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
5965
- </body>
6066
-</html>
6167
-""" % teaching_assistants[id]
62-
+ return "" % teaching_assistants[id]
68+
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
69+
+ return http.request.registry['ir.ui.view'].render(
70+
+ cr, uid, "academy.tas", teaching_assistants[id], context=context)
6371
diff --git a/views/templates.xml b/views/templates.xml
6472
new file mode 100644
6573
--- /dev/null
6674
+++ b/views/templates.xml
6775
@@ -0,0 +1,39 @@
6876
+<openerp>
6977
+ <data>
70-
+<template id="academy.index" name="Index">
78+
+<template id="index" name="Index">
7179
+ <html>
7280
+ <head>
7381
+ <title>AcademyAcademy</title>
@@ -90,7 +98,7 @@ new file mode 100644
9098
+ </html>
9199
+</template>
92100
+
93-
+<template id="academy.ta" name="Teaching Assistant">
101+
+<template id="ta" name="Teaching Assistant">
94102
+ <html>
95103
+ <head>
96104
+ <title>AcademyAcademy TA <t t-esc="name"/></title>

doc/howto/howto_website/website-dependency

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# HG changeset patch
2-
# Parent 5426218c6da91a13911e64eeb18a0cc2e19083c7
2+
# Parent 1960586e8781d62d0cc8c2b7b9df7b04fb20f3ae
33

44
diff --git a/__openerp__.py b/__openerp__.py
55
--- a/__openerp__.py
@@ -16,13 +16,14 @@ diff --git a/__openerp__.py b/__openerp__.py
1616
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
1717
--- a/controllers/my_controller.py
1818
+++ b/controllers/my_controller.py
19-
@@ -12,17 +12,12 @@ teaching_assistants = [
19+
@@ -12,20 +12,12 @@ teaching_assistants = [
2020
]
2121

2222
class my_controller(main.Home):
2323
- @http.route('/', auth='none')
2424
+ @http.route('/', auth='public')
2525
def index(self):
26+
- cr, uid, context = http.request.cr, http.request.uid, http.request.context
2627
- tas = [
2728
- '<li><a href="/tas/%d/">%s</a></li>' % (i, ta['name'])
2829
- for i, ta in enumerate(teaching_assistants)
@@ -31,14 +32,16 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
3132
+ 'tas': teaching_assistants,
3233
+ })
3334

34-
- return "" % {
35+
- return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', {
3536
- 'tas': '\n'.join(tas)
36-
- }
37+
- }, context=context)
3738
-
3839
- @http.route('/tas/<int:id>/', auth='none')
3940
+ @http.route('/tas/<int:id>/', auth='public', website=True)
4041
def ta(self, id):
41-
- return "" % teaching_assistants[id]
42+
- cr, uid, context = http.request.cr, http.request.uid, http.request.context
43+
- return http.request.registry['ir.ui.view'].render(
44+
- cr, uid, "academy.tas", teaching_assistants[id], context=context)
4245
+ return http.request.website.render('academy.ta', teaching_assistants[id])
4346
diff --git a/views/templates.xml b/views/templates.xml
4447
--- a/views/templates.xml

doc/howto/howto_website/website-layoutify

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# HG changeset patch
2-
# Parent 375b20994a7069eadfbd64c793328a07f7d9baf6
2+
# Parent 307d452da9602b1bc1a8ed208e6949924ba0e5cf
33

44
diff --git a/views/templates.xml b/views/templates.xml
55
--- a/views/templates.xml
66
+++ b/views/templates.xml
77
@@ -1,42 +1,46 @@
88
<openerp>
99
<data>
10-
<template id="academy.index" name="Index">
10+
-<template id="index" name="Index">
1111
- <html>
1212
- <head>
1313
- <title>AcademyAcademy</title>
@@ -32,6 +32,7 @@ diff --git a/views/templates.xml b/views/templates.xml
3232
- </ul>
3333
- </body>
3434
- </html>
35+
+<template id="academy.index" name="Index">
3536
+ <t t-call="website.layout">
3637
+ <div id="wrap">
3738
+ <div class="oe_structure"/>
@@ -60,7 +61,7 @@ diff --git a/views/templates.xml b/views/templates.xml
6061
+ </t>
6162
</template>
6263

63-
<template id="academy.ta" name="Teaching Assistant">
64+
-<template id="ta" name="Teaching Assistant">
6465
- <html>
6566
- <head>
6667
- <title>AcademyAcademy TA <t t-esc="name"/></title>
@@ -70,6 +71,7 @@ diff --git a/views/templates.xml b/views/templates.xml
7071
- <h1><t t-esc="name"/></h1>
7172
- </body>
7273
- </html>
74+
+<template id="academy.ta" name="Teaching Assistant">
7375
+ <t t-call="website.layout">
7476
+ <div id="wrap">
7577
+ <div class="oe_structure"/>

0 commit comments

Comments
 (0)