summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-02-07 11:11:57 +0100
committerXavier Morel <xmo@openerp.com>2014-05-19 08:32:11 +0200
commitcfc7015355848629cdc7f7d9fde795c929eec093 (patch)
treeaae452ae14fb63f2f1807677e664afc295205e92 /doc
parent66d8934802d6d15ef5b5d2be6dd5e4644bf2dda5 (diff)
[FIX] templating section, some wording
Diffstat (limited to 'doc')
-rw-r--r--doc/howto/howto_website.rst57
-rw-r--r--doc/howto/howto_website/templates-basic22
-rw-r--r--doc/howto/howto_website/website-dependency13
-rw-r--r--doc/howto/howto_website/website-layoutify8
4 files changed, 68 insertions, 32 deletions
diff --git a/doc/howto/howto_website.rst b/doc/howto/howto_website.rst
index 452d83d1aca..65a6ed18327 100644
--- a/doc/howto/howto_website.rst
+++ b/doc/howto/howto_website.rst
@@ -31,13 +31,29 @@ create a module:
.. patch::
:hidden:
-This builds a basic module for you, ignore anything in the ``models`` and
-``security`` directories for now.
+This builds a basic module for you:
+
+.. 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::
* instructions for start & install
* db handling
+
- if existing db, automatically selected
- if no existing db, nodb -> login -> login of first db
- 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
the words "Hello, world!" on it.
+.. todo:: screenshot?
+
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
nicer rendering than the default.
@@ -57,21 +75,28 @@ returned by the ``index`` method to get a more page-ish output:
.. note::
- this example requires internet access at all time, as we're accessing a
- :abbr:`CDN (Content Delivery Network, large distributed networks hosting
- static files and trying to provide high-performance and high-availability
- of these files)`-hosted file.
+ this example requires internet access as we're accessing a :abbr:`CDN
+ (Content Delivery Network, large distributed networks hosting static files
+ and trying to provide high-performance and high-availability of these
+ files)`-hosted file.
+
+.. todo:: screenshot
Data input: URL and query
=========================
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 dynamic pages which use data provided in the URL,
+for instance so a single controller generates multiple pages. Any
+query parameter (``?name=value``) is passed as a string parameter to the
+controller method.
-You can also create controllers which use data provided in the access URL,
-for instance so you have a single controller generating multiple pages. Any
-query parameter (``?name=value``) is passed as a parameter to the controller
-function, and is a string.
+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::
@@ -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
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
-``404 Not Found`` instead of generating a server error when the conversion
-fails).
+``404 Not Found`` instead of a 500 server error when the conversion fails).
Templating: better experience in editing
========================================
-So far we've created HTML output by munging together Python strings using
-string concatenation and formatting. It works, but is not exactly fun to edit
-(and somewhat unsafe to boot) as even advanced text editors have a hard time
-understanding they're dealing with HTML embedded in Python code.
+So far we've output HTML by munging strings. It works, but is not exactly fun
+to edit (and somewhat unsafe to boot) as even advanced text editors have a
+hard time understanding they're dealing with HTML embedded in Python code.
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
diff --git a/doc/howto/howto_website/templates-basic b/doc/howto/howto_website/templates-basic
index b0e5d85c487..e3475046b2d 100644
--- a/doc/howto/howto_website/templates-basic
+++ b/doc/howto/howto_website/templates-basic
@@ -1,5 +1,5 @@
# HG changeset patch
-# Parent 170cc87a26983d34df5cd3bb27d3259722c586e5
+# Parent 0792d59a4a456e1ce70d8aa4cb1784632883d714
diff --git a/__openerp__.py b/__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
--- a/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)
]
@@ -42,9 +48,9 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
-""" % {
- 'tas': '\n'.join(tas)
- }
-+ return "" % {
++ return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', {
+ 'tas': '\n'.join(tas)
-+ }
++ }, context=context)
@http.route('/tas/<int:id>/', auth='none')
def ta(self, id):
@@ -59,7 +65,9 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
- </body>
-</html>
-""" % 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
new file mode 100644
--- /dev/null
@@ -67,7 +75,7 @@ new file mode 100644
@@ -0,0 +1,39 @@
+<openerp>
+ <data>
-+<template id="academy.index" name="Index">
++<template id="index" name="Index">
+ <html>
+ <head>
+ <title>AcademyAcademy</title>
@@ -90,7 +98,7 @@ new file mode 100644
+ </html>
+</template>
+
-+<template id="academy.ta" name="Teaching Assistant">
++<template id="ta" name="Teaching Assistant">
+ <html>
+ <head>
+ <title>AcademyAcademy TA <t t-esc="name"/></title>
diff --git a/doc/howto/howto_website/website-dependency b/doc/howto/howto_website/website-dependency
index 6910aff199e..45c097dad72 100644
--- a/doc/howto/howto_website/website-dependency
+++ b/doc/howto/howto_website/website-dependency
@@ -1,5 +1,5 @@
# HG changeset patch
-# Parent 5426218c6da91a13911e64eeb18a0cc2e19083c7
+# Parent 1960586e8781d62d0cc8c2b7b9df7b04fb20f3ae
diff --git a/__openerp__.py b/__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
--- a/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):
- @http.route('/', auth='none')
+ @http.route('/', auth='public')
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)
@@ -31,14 +32,16 @@ diff --git a/controllers/my_controller.py b/controllers/my_controller.py
+ 'tas': teaching_assistants,
+ })
-- return "" % {
+- return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', {
- 'tas': '\n'.join(tas)
-- }
+- }, context=context)
-
- @http.route('/tas/<int:id>/', auth='none')
+ @http.route('/tas/<int:id>/', auth='public', website=True)
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])
diff --git a/views/templates.xml b/views/templates.xml
--- a/views/templates.xml
diff --git a/doc/howto/howto_website/website-layoutify b/doc/howto/howto_website/website-layoutify
index 27cfd6de74f..204e1305c1a 100644
--- a/doc/howto/howto_website/website-layoutify
+++ b/doc/howto/howto_website/website-layoutify
@@ -1,5 +1,5 @@
# HG changeset patch
-# Parent 375b20994a7069eadfbd64c793328a07f7d9baf6
+# Parent 307d452da9602b1bc1a8ed208e6949924ba0e5cf
diff --git a/views/templates.xml b/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 @@
<openerp>
<data>
- <template id="academy.index" name="Index">
+-<template id="index" name="Index">
- <html>
- <head>
- <title>AcademyAcademy</title>
@@ -32,6 +32,7 @@ diff --git a/views/templates.xml b/views/templates.xml
- </ul>
- </body>
- </html>
++<template id="academy.index" name="Index">
+ <t t-call="website.layout">
+ <div id="wrap">
+ <div class="oe_structure"/>
@@ -60,7 +61,7 @@ diff --git a/views/templates.xml b/views/templates.xml
+ </t>
</template>
- <template id="academy.ta" name="Teaching Assistant">
+-<template id="ta" name="Teaching Assistant">
- <html>
- <head>
- <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>
- </body>
- </html>
++<template id="academy.ta" name="Teaching Assistant">
+ <t t-call="website.layout">
+ <div id="wrap">
+ <div class="oe_structure"/>