Mercurial > p > roundup > code
annotate doc/templating.txt @ 978:4f57a8f51da4
tweaks
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 27 Aug 2002 08:34:32 +0000 |
| parents | 22e6707a993a |
| children | 79129f013153 |
| rev | line source |
|---|---|
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 ========================== |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2 HTML Templating Mechanisms |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 ========================== |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 |
| 978 | 5 :Version: $Revision: 1.12 $ |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
6 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
7 Current Situation and Issues |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 ============================ |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
10 Syntax |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 ------ |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
12 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 Roundup currently uses an element-based HTML-tag-alike templating syntax:: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 <display call="checklist('status')"> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
16 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
17 The templates were initially parsed using recursive regular expression |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
18 parsing, and since no template tag could encapsulate itself, the parser |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 worked just fine. Then we got the ``<require>`` tag, which could have other |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
20 ``<require>`` tags inside. This forced us to move towards a more complete |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
21 parser, using the standard python sgmllib/htmllib parser. The downside of this |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 switch is that constructs of the form:: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
24 <tr class="row-<display call="plain('status')">"> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
26 don't parse as we'd hope. We can modify the parser to work, but that doesn't |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
27 another couple of issues that have arisen: |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 |
| 956 | 29 1. the template syntax is not well-formed, and therefore is a pain to parse |
| 30 and doesn't play well with other tools, and | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 2. user requirements generally have to be anticipated and accounted for in |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 templating functions (like ``plain()`` and ``checklist()`` above), and |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 we are therefore artificially restrictive. |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 Arguments for switching templating systems: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
37 *Pros* |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
38 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
39 - more flexibility in templating control and content |
| 956 | 40 - we can be well-formed |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 *Cons* |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
43 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
44 - installed user base (though they'd have to edit their templates with the |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 next release anyway) |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
46 - current templating system is pretty trivial, and a more flexible system |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
47 is likely to be more complex |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
48 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 Templates |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 --------- |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
52 |
| 957 | 53 We should also take this opportunity to open up the flexibility of the |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
54 templates through: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
55 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
56 1. allowing the instance to define a "page" template, which holds the overall |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
57 page structure, including header and footer |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
58 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
59 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
60 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
61 Possible approaches |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
62 =================== |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
63 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
64 Zope's PageTemplates |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
65 -------------------- |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
66 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
67 Using Zope's PageTemplates seems to be the best approach of the lot. |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
68 In my opinion, it's the peak of HTML templating technology at present. With |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
69 appropriate infrastructure, the above two examples would read: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
70 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
71 <span tal:replace="item/status/checklist">status checklist</span> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
72 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
73 <tr tal:attributes="class string:row-${item/status/name}"> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 ... which doesn't look that much more complicated... honest... |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
76 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
77 Other fun can be had when you start playing with stuff like: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
78 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
79 <table> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
80 <tr tal:repeat="message item/msg/list"> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
81 <td tal:define="from message/from"> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
82 <a href="" tal:attributes="href string:mailto:${from/address}" |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
83 tal:content="from/name">mailto link</a> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
84 </td> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
85 <td tal:content="message/title">subject</td> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
86 <td tal:content="message/created">received date</td> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
87 </tr> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
88 </table> |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
89 |
| 963 | 90 Note: even if we don't switch templating as a whole, this document may be |
| 91 applied to the ZRoundup frontend. | |
| 92 | |
| 960 | 93 PageTemplates in a Nutshell |
| 94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 95 | |
| 96 PageTemplates consist of three technologies: | |
| 97 | |
| 98 TAL - Template Attribute Language | |
| 99 This is the syntax which is woven into the HTML using the ``tal:`` tag | |
| 100 attributes. A TAL parser pulls out the TAL commands from the attributes | |
| 101 runs them using some expression engine. | |
| 102 | |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
103 TALES - TAL Expression Syntax |
| 960 | 104 The expression engine used in this case is TALES, which runs the expressions |
| 105 that form the tag attribute values. TALES expressions come in three | |
| 106 flavours: | |
| 107 | |
|
961
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
108 Path Expressions - eg. ``item/status/checklist`` |
| 960 | 109 These are object attribute / item accesses. Roughly speaking, the path |
|
961
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
110 ``item/status/checklist`` is broken into parts ``item``, ``status`` |
|
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
111 and ``checklist``. The ``item`` part is the root of the expression. |
|
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
112 We then look for a ``status`` attribute on ``item``, or failing that, a |
|
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
113 ``status`` item (as in ``item['status']``). If that |
| 960 | 114 fails, the path expression fails. When we get to the end, the object we're |
| 115 left with is evaluated to get a string - methods are called, objects are | |
| 116 stringified. Path expressions may have an optional ``path:`` prefix, though | |
| 117 they are the default expression type, so it's not necessary. | |
| 118 | |
| 119 String Expressions - eg. ``string:hello ${user/name}`` | |
| 120 These expressions are simple string interpolations (though they can be just | |
| 121 plain strings with no interpolation if you want. The expression in the | |
| 122 ``${ ... }`` is just a path expression as above. | |
| 123 | |
| 124 Python Expressions - eg. ``python: 1+1`` | |
| 125 These expressions give the full power of Python. All the "root level" | |
|
961
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
126 variables are available, so ``python:item.status.checklist()`` would be |
|
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
127 equivalent to ``item/status/checklist``, assuming that ``checklist`` is |
|
7d68f88f0642
more useful example
Richard Jones <richard@users.sourceforge.net>
parents:
960
diff
changeset
|
128 a method. |
| 960 | 129 |
| 130 PageTemplates | |
| 131 The PageTemplates module glues together TAL and TALES. | |
| 132 | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
133 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
134 Implementation |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
135 ~~~~~~~~~~~~~~ |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
136 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
137 I'm envisaging an infrastructure layer where each template has the following |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
138 "root level" (that is, directly accessible in the TALES namespace) variables |
| 960 | 139 defined: |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
140 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
141 *class* |
| 963 | 142 The current class of node being displayed as an HTMLClass instance |
| 143 | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
144 *item* |
| 963 | 145 The current node from the database, if we're viewing a specific node, as an |
| 146 HTMLItem instance. If it doesn't exist, then we're on a new item page. | |
| 147 | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
148 (*classname*) |
| 963 | 149 this is one of two things: |
| 150 | |
| 151 1. the *item* is also available under its classname, so a *user* node | |
| 152 would also be available under the name *user*. This is also an HTMLItem | |
| 153 instance. | |
| 154 2. if there's no *item* then the current class is available through this | |
| 155 name, thus "user/name" and "user/name/menu" will still work - the latter | |
| 156 will pull information from the form if it can. | |
| 157 | |
| 978 | 158 this is a dangerous attribute, and may cause us pain the long run (its name |
| 159 may clash with other top-level variables ... it already clashed with the | |
| 160 proposed *user* variable). It might be safer to go with just *class* and | |
| 161 *item*, actually... | |
| 162 | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
163 *form* |
| 963 | 164 The current CGI form information as a mapping of form argument name to value |
| 165 | |
| 166 *request* | |
| 167 Includes information about the current request, including: | |
| 168 - the url | |
| 169 - the current index information (``filterspec``, ``filter`` args, | |
| 170 ``properties``, etc) parsed out of the form. | |
| 171 - methods for easy filterspec link generation | |
| 978 | 172 - *user*, the current user node as an HTMLItem instance |
| 963 | 173 |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
174 *instance* |
| 963 | 175 The current instance |
| 176 | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
177 *db* |
| 963 | 178 The current open database |
| 179 | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
180 *config* |
| 963 | 181 The current instance config |
| 182 | |
| 960 | 183 *modules* |
| 963 | 184 python modules made available (XXX: not sure what's actually in there tho) |
| 185 | |
| 978 | 186 Accesses through a class (either through *class* or *db.<classname>*):: |
| 958 | 187 |
| 959 | 188 class HTMLClass: |
| 958 | 189 def __getattr__(self, attr): |
| 190 ''' return an HTMLItem instance ''' | |
| 191 def classhelp(self, ...) | |
| 192 def list(self, ...) | |
| 966 | 193 def filter(self): |
| 194 ''' Return a list of items from this class, filtered and sorted | |
| 195 by the current requested filterspec/filter/sort/group args | |
| 196 ''' | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
197 |
| 958 | 198 Accesses through an *item*:: |
| 199 | |
| 200 class HTMLItem: | |
| 201 def __getattr__(self, attr): | |
| 202 ''' return an HTMLItem instance ''' | |
| 203 def history(self, ...) | |
| 204 def remove(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
205 |
| 963 | 206 Note: the above could cause problems if someone wants to have properties |
| 207 called "history" or "remove"... | |
| 208 | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
209 String, Number, Date, Interval HTMLProperty |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
210 a wrapper object which may be stringified for the current plain() behaviour |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
211 and has methods emulating all the current display functions, so |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
212 ``item/name/plain`` would emulate the current ``call="plain()``". Also, |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
213 ``python:item.name.plain(name=value)`` would work just fine:: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
214 |
| 958 | 215 class HTMLProperty: |
| 216 def __init__(self, instance, db, ...) | |
| 217 def __str__(self): | |
| 218 return self.plain() | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
219 |
| 958 | 220 class StringHTMLProperty(HTLProperty): |
| 221 def plain(self, ...) | |
| 222 def field(self, ...) | |
| 223 def stext(self, ...) | |
| 224 def multiline(self, ...) | |
| 225 def email(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
226 |
| 958 | 227 class NumberHTMLProperty(HTMLProperty): |
| 228 def plain(self, ...) | |
| 229 def field(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
230 |
| 958 | 231 class BooleanHTMLProperty(HTMLProperty): |
| 232 def plain(self, ...) | |
| 233 def field(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
234 |
| 958 | 235 class DateHTMLProperty(HTMLProperty): |
| 236 def plain(self, ...) | |
| 237 def field(self, ...) | |
| 238 def reldate(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
239 |
| 958 | 240 class IntervalHTMLProperty(HTMLProperty): |
| 241 def plain(self, ...) | |
| 242 def field(self, ...) | |
| 963 | 243 def pretty(self, ...) |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
244 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
245 Link HTMLProperty |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
246 the wrapper object would include the above as well as being able to access |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
247 the class information. Stringifying the object itself would result in the |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
248 value from the item being displayed. Accessing attributes of this object |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
249 would result in the appropriate entry from the class being queried for the |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
250 property accessed (so item/assignedto/name would look up the user entry |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
251 identified by the assignedto property on item, and then the name property of |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
252 that user):: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
253 |
| 958 | 254 class LinkHTMLProperty(HTMLProperty): |
| 255 ''' Be a HTMLItem too ''' | |
| 256 def __getattr__(self, attr): | |
| 257 ''' return a new HTMLProperty ''' | |
| 258 def download(self, ...) | |
| 259 def checklist(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
260 |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
261 Multilink HTMLProperty |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
262 the wrapper would also be iterable, returning a wrapper object like the Link |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
263 case for each entry in the multilink:: |
|
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
264 |
| 958 | 265 class MultilinkHTMLProperty(HTMLProperty): |
| 266 def __len__(self): | |
| 267 ''' length of the multilink ''' | |
| 268 def __getitem(self, num): | |
| 269 ''' return a new HTMLItem ''' | |
| 270 def checklist(self, ...) | |
| 271 def list(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
272 |
| 963 | 273 *request* |
| 274 the request object will handle:: | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
275 |
| 963 | 276 class Request: |
| 958 | 277 def __init__(self, ...) |
| 278 def filterspec(self, ...) | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
279 |
| 978 | 280 Accesses through the *user* attribute of *request*:: |
| 281 | |
| 282 class HTMLUser(HTMLItem): | |
| 283 def hasPermission(self, ...) | |
| 284 | |
| 285 (note that the other permission check implemented by the security module may | |
| 286 be implemented easily in a tal:condition, so isn't needed here) | |
| 287 | |
| 966 | 288 Template files |
| 289 ~~~~~~~~~~~~~~ | |
| 290 | |
| 291 Each instance will have the opportunity to supply the following templates: | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
292 |
| 966 | 293 page |
| 294 This is the overall page look template, and includes at some point a TAL | |
| 295 command that includes the variable "content". This variable causes the actual | |
| 296 page content to be generated. | |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
297 |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
298 [classname].[template type] |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
299 Templates that have this form are applied to item data. There are three forms |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
300 of special template types: |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
301 |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
302 [classname].index |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
303 This template is used when the URL specifies only the class, and not a node |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
304 designator. It displays a list of [classname] items from the database, and |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
305 a "filter refinement" form. |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
306 Would perform a TAL ``repeat`` command using the list supplied by |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
307 ``class/filter``. This deviates from the current situation in that currently |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
308 the index template specifies a single row, and the filter part is |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
309 automatically generated. |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
310 |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
311 [classname].item |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
312 This template is used when the URL specifies an item designator. It's the |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
313 default template used (when no template is explicitly given). It displays |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
314 a single item from the database using the *classname* variable (that |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
315 is, the variable of the same name as the class being displayed. If |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
316 |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
317 These two special template types may be overridden by the :template CGI |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
318 variable. |
| 966 | 319 |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
320 Note that the "newitem" template doesn't exist any more because the item |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
321 templates may determine whether the page has an existing item to render. The |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
322 new item page would be accessed by "/tracker/url/issue?:template=item". |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
323 The old "filter" template has been subsumed by the index template. |
|
955
84281f7f2900
templating redesign
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
324 |
| 958 | 325 |
| 966 | 326 Integrating Code |
| 327 ~~~~~~~~~~~~~~~~ | |
| 328 | |
| 329 We will install PageTemplates, TAL and ZTUtils in site-packages. If there is a | |
| 330 local Zope installation, it will use its own PageTemplates code (Zope modifies | |
| 331 the module search path to give precedence to its own module library). | |
| 332 | |
| 333 We will then install the trivial MultiMapping and ComputedAttribute modules in | |
| 334 the Roundup package, and have some import trickery that determines whether | |
| 335 they are required, and if so they will be imported as if they were at the | |
| 336 "top level" of the module namespace. | |
| 337 | |
|
977
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
338 New CGI client structure |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
339 ~~~~~~~~~~~~~~~~~~~~~~~~ |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
340 |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
341 Handling of a request in the CGI client will take three phases: |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
342 |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
343 1. Determine user, pre-set "content" to authorisation page if necessary |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
344 2. Render main page, with callback to "content" |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
345 3. Render content - if not pre-set, then determine which content to render |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
346 |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
347 |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
348 Use Cases |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
349 ~~~~~~~~~ |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
350 |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
351 Meta/parent bug |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
352 Can be done with addition to the schema and then the actual parent heirarchy |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
353 may be displayed with a new template page ":dependencies" or something. |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
354 |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
355 Submission wizard |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
356 Can be done using new templates ":page1", ":page2", etc and some additional |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
357 actions on the CGI Client class in the instance. |
|
22e6707a993a
More tweaks to the design.
Richard Jones <richard@users.sourceforge.net>
parents:
966
diff
changeset
|
358 |
