@@ -197,11 +197,10 @@ def __getitem__(self, name):
197197 except NoTemplate , message :
198198 raise KeyError , message
199199
200- class RoundupPageTemplate ( PageTemplate . PageTemplate ):
201- '''A Roundup-specific PageTemplate.
200+ def context ( client , template = None , classname = None , request = None ):
201+ """Return the rendering context dictionary
202202
203- Interrogate the client to set up the various template variables to
204- be available:
203+ The dictionary includes following symbols:
205204
206205 *context*
207206 this is one of three things:
@@ -211,6 +210,7 @@ class RoundupPageTemplate(PageTemplate.PageTemplate):
211210 instance.
212211 3. The current item from the database, if we're viewing a specific
213212 item, as an HTMLItem instance.
213+
214214 *request*
215215 Includes information about the current request, including:
216216
@@ -220,48 +220,88 @@ class RoundupPageTemplate(PageTemplate.PageTemplate):
220220 - methods for easy filterspec link generation
221221 - *user*, the current user node as an HTMLItem instance
222222 - *form*, the current CGI form information as a FieldStorage
223+
223224 *config*
224225 The current tracker config.
226+
225227 *db*
226228 The current database, used to access arbitrary database items.
229+
227230 *utils*
228231 This is a special class that has its base in the TemplatingUtils
229232 class in this file. If the tracker interfaces module defines a
230233 TemplatingUtils class then it is mixed in, overriding the methods
231234 in the base class.
235+
236+ *templates*
237+ Access to all the tracker templates by name.
238+ Used mainly in *use-macro* commands.
239+
240+ *template*
241+ Current rendering template.
242+
243+ *true*
244+ Logical True value.
245+
246+ *false*
247+ Logical False value.
248+
249+ """
250+ # construct the TemplatingUtils class
251+ utils = TemplatingUtils
252+ if hasattr (client .instance .interfaces , 'TemplatingUtils' ):
253+ class utils (client .instance .interfaces .TemplatingUtils , utils ):
254+ pass
255+
256+ # if template, classname and/or request are not passed explicitely,
257+ # compute form client
258+ if template is None :
259+ template = client .template
260+ if classname is None :
261+ classname = client .classname
262+ if request is None :
263+ request = HTMLRequest (client )
264+
265+ c = {
266+ 'context' : None ,
267+ 'options' : {},
268+ 'nothing' : None ,
269+ 'request' : request ,
270+ 'db' : HTMLDatabase (client ),
271+ 'config' : client .instance .config ,
272+ 'tracker' : client .instance ,
273+ 'utils' : utils (client ),
274+ 'templates' : Templates (client .instance .config .TEMPLATES ),
275+ 'template' : template ,
276+ 'true' : 1 ,
277+ 'false' : 0 ,
278+ }
279+ # add in the item if there is one
280+ if client .nodeid :
281+ if classname == 'user' :
282+ c ['context' ] = HTMLUser (client , classname , client .nodeid ,
283+ anonymous = 1 )
284+ else :
285+ c ['context' ] = HTMLItem (client , classname , client .nodeid ,
286+ anonymous = 1 )
287+ elif client .db .classes .has_key (classname ):
288+ if classname == 'user' :
289+ c ['context' ] = HTMLUserClass (client , classname , anonymous = 1 )
290+ else :
291+ c ['context' ] = HTMLClass (client , classname , anonymous = 1 )
292+ return c
293+
294+ class RoundupPageTemplate (PageTemplate .PageTemplate ):
295+ '''A Roundup-specific PageTemplate.
296+
297+ Interrogate the client to set up Roundup-specific template variables
298+ to be available. See 'context' function for the list of variables.
299+
232300 '''
301+
302+ # 06-jun-2004 [als] i am not sure if this method is used yet
233303 def getContext (self , client , classname , request ):
234- # construct the TemplatingUtils class
235- utils = TemplatingUtils
236- if hasattr (client .instance .interfaces , 'TemplatingUtils' ):
237- class utils (client .instance .interfaces .TemplatingUtils , utils ):
238- pass
239-
240- c = {
241- 'options' : {},
242- 'nothing' : None ,
243- 'request' : request ,
244- 'db' : HTMLDatabase (client ),
245- 'config' : client .instance .config ,
246- 'tracker' : client .instance ,
247- 'utils' : utils (client ),
248- 'templates' : Templates (client .instance .config .TEMPLATES ),
249- 'template' : self ,
250- }
251- # add in the item if there is one
252- if client .nodeid :
253- if classname == 'user' :
254- c ['context' ] = HTMLUser (client , classname , client .nodeid ,
255- anonymous = 1 )
256- else :
257- c ['context' ] = HTMLItem (client , classname , client .nodeid ,
258- anonymous = 1 )
259- elif client .db .classes .has_key (classname ):
260- if classname == 'user' :
261- c ['context' ] = HTMLUserClass (client , classname , anonymous = 1 )
262- else :
263- c ['context' ] = HTMLClass (client , classname , anonymous = 1 )
264- return c
304+ return context (client , self , classname , request )
265305
266306 def render (self , client , classname , request , ** options ):
267307 """Render this Page Template"""
@@ -276,9 +316,7 @@ def render(self, client, classname, request, **options):
276316 'Page Template %s has errors.' % self .id
277317
278318 # figure the context
279- classname = classname or client .classname
280- request = request or HTMLRequest (client )
281- c = self .getContext (client , classname , request )
319+ c = context (client , self , classname , request )
282320 c .update ({'options' : options })
283321
284322 # and go
0 commit comments