[FIX] templating section, some wording
This commit is contained in:
parent
66d8934802
commit
cfc7015355
|
@ -31,13 +31,29 @@ create a module:
|
||||||
.. patch::
|
.. patch::
|
||||||
:hidden:
|
:hidden:
|
||||||
|
|
||||||
This builds a basic module for you, ignore anything in the ``models`` and
|
This builds a basic module for you:
|
||||||
``security`` directories for now.
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
academy
|
||||||
|
├── __init__.py
|
||||||
|
├── __openerp__.py
|
||||||
|
├── controllers
|
||||||
|
│ ├── __init__.py
|
||||||
|
│ └── my_controller.py
|
||||||
|
├── models
|
||||||
|
│ ├── __init__.py
|
||||||
|
│ └── my_model.py
|
||||||
|
└── security
|
||||||
|
└── ir.model.access.csv
|
||||||
|
|
||||||
|
Ignore anything in the ``models`` and ``security`` directories for now.
|
||||||
|
|
||||||
.. todo::
|
.. todo::
|
||||||
|
|
||||||
* instructions for start & install
|
* instructions for start & install
|
||||||
* db handling
|
* db handling
|
||||||
|
|
||||||
- if existing db, automatically selected
|
- if existing db, automatically selected
|
||||||
- if no existing db, nodb -> login -> login of first db
|
- if no existing db, nodb -> login -> login of first db
|
||||||
- dbfilter
|
- dbfilter
|
||||||
|
@ -46,6 +62,8 @@ Now start your OpenERP server and install your module in it, open a web
|
||||||
browser and navigate to http://localhost:8069. A page should appear with just
|
browser and navigate to http://localhost:8069. A page should appear with just
|
||||||
the words "Hello, world!" on it.
|
the words "Hello, world!" on it.
|
||||||
|
|
||||||
|
.. todo:: screenshot?
|
||||||
|
|
||||||
Let's prettify things a bit: instead of returning just a bit of text,
|
Let's prettify things a bit: instead of returning just a bit of text,
|
||||||
we can return a page, and use a tool like bootstrap_ to get a
|
we can return a page, and use a tool like bootstrap_ to get a
|
||||||
nicer rendering than the default.
|
nicer rendering than the default.
|
||||||
|
@ -57,21 +75,28 @@ returned by the ``index`` method to get a more page-ish output:
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
this example requires internet access at all time, as we're accessing a
|
this example requires internet access as we're accessing a :abbr:`CDN
|
||||||
:abbr:`CDN (Content Delivery Network, large distributed networks hosting
|
(Content Delivery Network, large distributed networks hosting static files
|
||||||
static files and trying to provide high-performance and high-availability
|
and trying to provide high-performance and high-availability of these
|
||||||
of these files)`-hosted file.
|
files)`-hosted file.
|
||||||
|
|
||||||
|
.. todo:: screenshot
|
||||||
|
|
||||||
Data input: URL and query
|
Data input: URL and query
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
Being able to build a static page in code is nice, but makes for limited
|
Being able to build a static page in code is nice, but makes for limited
|
||||||
usefulness (you could do that with static files in the first place).
|
usefulness (you could do that with static files).
|
||||||
|
|
||||||
You can also create controllers which use data provided in the access URL,
|
You can also create dynamic pages which use data provided in the URL,
|
||||||
for instance so you have a single controller generating multiple pages. Any
|
for instance so a single controller generates multiple pages. Any
|
||||||
query parameter (``?name=value``) is passed as a parameter to the controller
|
query parameter (``?name=value``) is passed as a string parameter to the
|
||||||
function, and is a string.
|
controller method.
|
||||||
|
|
||||||
|
For instance, the index page can display a list of teaching assistants linking
|
||||||
|
to a page for each assistant through their index in a global array. Each
|
||||||
|
assistant's page will simply print their name by applying the index to the
|
||||||
|
array:
|
||||||
|
|
||||||
.. patch::
|
.. patch::
|
||||||
|
|
||||||
|
@ -89,16 +114,14 @@ This can be done by adding `converter patterns`_ to the URL in
|
||||||
These patterns can perform conversions directly (in this case the conversion
|
These patterns can perform conversions directly (in this case the conversion
|
||||||
from a string URL section to a python integer) and will perform a some
|
from a string URL section to a python integer) and will perform a some
|
||||||
validation (if the ``id`` is not a valid integer, the converter will return a
|
validation (if the ``id`` is not a valid integer, the converter will return a
|
||||||
``404 Not Found`` instead of generating a server error when the conversion
|
``404 Not Found`` instead of a 500 server error when the conversion fails).
|
||||||
fails).
|
|
||||||
|
|
||||||
Templating: better experience in editing
|
Templating: better experience in editing
|
||||||
========================================
|
========================================
|
||||||
|
|
||||||
So far we've created HTML output by munging together Python strings using
|
So far we've output HTML by munging strings. It works, but is not exactly fun
|
||||||
string concatenation and formatting. It works, but is not exactly fun to edit
|
to edit (and somewhat unsafe to boot) as even advanced text editors have a
|
||||||
(and somewhat unsafe to boot) as even advanced text editors have a hard time
|
hard time understanding they're dealing with HTML embedded in Python code.
|
||||||
understanding they're dealing with HTML embedded in Python code.
|
|
||||||
|
|
||||||
The usual solution is to use templates_, documents with placeholders which can
|
The usual solution is to use templates_, documents with placeholders which can
|
||||||
be "rendered" to produce final pages (or others). OpenERP lets you use any
|
be "rendered" to produce final pages (or others). OpenERP lets you use any
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 170cc87a26983d34df5cd3bb27d3259722c586e5
|
# Parent 0792d59a4a456e1ce70d8aa4cb1784632883d714
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
|
@ -19,7 +19,13 @@ diff --git a/__openerp__.py b/__openerp__.py
|
||||||
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
--- a/controllers/my_controller.py
|
--- a/controllers/my_controller.py
|
||||||
+++ b/controllers/my_controller.py
|
+++ b/controllers/my_controller.py
|
||||||
@@ -19,36 +19,10 @@ class my_controller(main.Home):
|
@@ -14,41 +14,18 @@ teaching_assistants = [
|
||||||
|
class my_controller(main.Home):
|
||||||
|
@http.route('/', auth='none')
|
||||||
|
def index(self):
|
||||||
|
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
|
||||||
|
tas = [
|
||||||
|
'<li><a href="/tas/%d/">%s</a></li>' % (i, ta['name'])
|
||||||
for i, ta in enumerate(teaching_assistants)
|
for i, ta in enumerate(teaching_assistants)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -42,9 +48,9 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
-""" % {
|
-""" % {
|
||||||
- 'tas': '\n'.join(tas)
|
- 'tas': '\n'.join(tas)
|
||||||
- }
|
- }
|
||||||
+ return "" % {
|
+ return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', {
|
||||||
+ 'tas': '\n'.join(tas)
|
+ 'tas': '\n'.join(tas)
|
||||||
+ }
|
+ }, context=context)
|
||||||
|
|
||||||
@http.route('/tas/<int:id>/', auth='none')
|
@http.route('/tas/<int:id>/', auth='none')
|
||||||
def ta(self, id):
|
def ta(self, id):
|
||||||
|
@ -59,7 +65,9 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
- </body>
|
- </body>
|
||||||
-</html>
|
-</html>
|
||||||
-""" % teaching_assistants[id]
|
-""" % teaching_assistants[id]
|
||||||
+ return "" % teaching_assistants[id]
|
+ cr, uid, context = http.request.cr, http.request.uid, http.request.context
|
||||||
|
+ return http.request.registry['ir.ui.view'].render(
|
||||||
|
+ cr, uid, "academy.tas", teaching_assistants[id], context=context)
|
||||||
diff --git a/views/templates.xml b/views/templates.xml
|
diff --git a/views/templates.xml b/views/templates.xml
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
|
@ -67,7 +75,7 @@ new file mode 100644
|
||||||
@@ -0,0 +1,39 @@
|
@@ -0,0 +1,39 @@
|
||||||
+<openerp>
|
+<openerp>
|
||||||
+ <data>
|
+ <data>
|
||||||
+<template id="academy.index" name="Index">
|
+<template id="index" name="Index">
|
||||||
+ <html>
|
+ <html>
|
||||||
+ <head>
|
+ <head>
|
||||||
+ <title>AcademyAcademy</title>
|
+ <title>AcademyAcademy</title>
|
||||||
|
@ -90,7 +98,7 @@ new file mode 100644
|
||||||
+ </html>
|
+ </html>
|
||||||
+</template>
|
+</template>
|
||||||
+
|
+
|
||||||
+<template id="academy.ta" name="Teaching Assistant">
|
+<template id="ta" name="Teaching Assistant">
|
||||||
+ <html>
|
+ <html>
|
||||||
+ <head>
|
+ <head>
|
||||||
+ <title>AcademyAcademy TA <t t-esc="name"/></title>
|
+ <title>AcademyAcademy TA <t t-esc="name"/></title>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 5426218c6da91a13911e64eeb18a0cc2e19083c7
|
# Parent 1960586e8781d62d0cc8c2b7b9df7b04fb20f3ae
|
||||||
|
|
||||||
diff --git a/__openerp__.py b/__openerp__.py
|
diff --git a/__openerp__.py b/__openerp__.py
|
||||||
--- a/__openerp__.py
|
--- a/__openerp__.py
|
||||||
|
@ -16,13 +16,14 @@ diff --git a/__openerp__.py b/__openerp__.py
|
||||||
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
--- a/controllers/my_controller.py
|
--- a/controllers/my_controller.py
|
||||||
+++ b/controllers/my_controller.py
|
+++ b/controllers/my_controller.py
|
||||||
@@ -12,17 +12,12 @@ teaching_assistants = [
|
@@ -12,20 +12,12 @@ teaching_assistants = [
|
||||||
]
|
]
|
||||||
|
|
||||||
class my_controller(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):
|
||||||
|
- cr, uid, context = http.request.cr, http.request.uid, http.request.context
|
||||||
- tas = [
|
- tas = [
|
||||||
- '<li><a href="/tas/%d/">%s</a></li>' % (i, ta['name'])
|
- '<li><a href="/tas/%d/">%s</a></li>' % (i, ta['name'])
|
||||||
- for i, ta in enumerate(teaching_assistants)
|
- for i, ta in enumerate(teaching_assistants)
|
||||||
|
@ -31,14 +32,16 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
|
||||||
+ 'tas': teaching_assistants,
|
+ 'tas': teaching_assistants,
|
||||||
+ })
|
+ })
|
||||||
|
|
||||||
- return "" % {
|
- return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', {
|
||||||
- 'tas': '\n'.join(tas)
|
- 'tas': '\n'.join(tas)
|
||||||
- }
|
- }, context=context)
|
||||||
-
|
-
|
||||||
- @http.route('/tas/<int:id>/', auth='none')
|
- @http.route('/tas/<int:id>/', auth='none')
|
||||||
+ @http.route('/tas/<int:id>/', auth='public', website=True)
|
+ @http.route('/tas/<int:id>/', auth='public', website=True)
|
||||||
def ta(self, id):
|
def ta(self, id):
|
||||||
- return "" % teaching_assistants[id]
|
- cr, uid, context = http.request.cr, http.request.uid, http.request.context
|
||||||
|
- return http.request.registry['ir.ui.view'].render(
|
||||||
|
- cr, uid, "academy.tas", teaching_assistants[id], context=context)
|
||||||
+ return http.request.website.render('academy.ta', teaching_assistants[id])
|
+ return http.request.website.render('academy.ta', teaching_assistants[id])
|
||||||
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,5 +1,5 @@
|
||||||
# HG changeset patch
|
# HG changeset patch
|
||||||
# Parent 375b20994a7069eadfbd64c793328a07f7d9baf6
|
# Parent 307d452da9602b1bc1a8ed208e6949924ba0e5cf
|
||||||
|
|
||||||
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
|
||||||
|
@ -7,7 +7,7 @@ diff --git a/views/templates.xml b/views/templates.xml
|
||||||
@@ -1,42 +1,46 @@
|
@@ -1,42 +1,46 @@
|
||||||
<openerp>
|
<openerp>
|
||||||
<data>
|
<data>
|
||||||
<template id="academy.index" name="Index">
|
-<template id="index" name="Index">
|
||||||
- <html>
|
- <html>
|
||||||
- <head>
|
- <head>
|
||||||
- <title>AcademyAcademy</title>
|
- <title>AcademyAcademy</title>
|
||||||
|
@ -32,6 +32,7 @@ diff --git a/views/templates.xml b/views/templates.xml
|
||||||
- </ul>
|
- </ul>
|
||||||
- </body>
|
- </body>
|
||||||
- </html>
|
- </html>
|
||||||
|
+<template id="academy.index" name="Index">
|
||||||
+ <t t-call="website.layout">
|
+ <t t-call="website.layout">
|
||||||
+ <div id="wrap">
|
+ <div id="wrap">
|
||||||
+ <div class="oe_structure"/>
|
+ <div class="oe_structure"/>
|
||||||
|
@ -60,7 +61,7 @@ diff --git a/views/templates.xml b/views/templates.xml
|
||||||
+ </t>
|
+ </t>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="academy.ta" name="Teaching Assistant">
|
-<template id="ta" name="Teaching Assistant">
|
||||||
- <html>
|
- <html>
|
||||||
- <head>
|
- <head>
|
||||||
- <title>AcademyAcademy TA <t t-esc="name"/></title>
|
- <title>AcademyAcademy TA <t t-esc="name"/></title>
|
||||||
|
@ -70,6 +71,7 @@ diff --git a/views/templates.xml b/views/templates.xml
|
||||||
- <h1><t t-esc="name"/></h1>
|
- <h1><t t-esc="name"/></h1>
|
||||||
- </body>
|
- </body>
|
||||||
- </html>
|
- </html>
|
||||||
|
+<template id="academy.ta" name="Teaching Assistant">
|
||||||
+ <t t-call="website.layout">
|
+ <t t-call="website.layout">
|
||||||
+ <div id="wrap">
|
+ <div id="wrap">
|
||||||
+ <div class="oe_structure"/>
|
+ <div class="oe_structure"/>
|
||||||
|
|
Loading…
Reference in New Issue