comparison roundup/cgi/templating.py @ 1073:cf30c6cdca02

More documentation. Simplified the "klass", "item" and "*classname*" variables into "context.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 09 Sep 2002 00:45:06 +0000
parents 665730c27d29
children 954ad22eb7d9
comparison
equal deleted inserted replaced
1072:88ded00fa0e0 1073:cf30c6cdca02
121 ''' A Roundup-specific PageTemplate. 121 ''' A Roundup-specific PageTemplate.
122 122
123 Interrogate the client to set up the various template variables to 123 Interrogate the client to set up the various template variables to
124 be available: 124 be available:
125 125
126 *class* 126 *context*
127 The current class of node being displayed as an HTMLClass 127 this is one of three things:
128 instance. 128 1. None - we're viewing a "home" page
129 *item* 129 2. The current class of item being displayed. This is an HTMLClass
130 The current node from the database, if we're viewing a specific 130 instance.
131 node, as an HTMLItem instance. If it doesn't exist, then we're 131 3. The current item from the database, if we're viewing a specific
132 on a new item page. 132 item, as an HTMLItem instance.
133 (*classname*)
134 this is one of two things:
135
136 1. the *item* is also available under its classname, so a *user*
137 node would also be available under the name *user*. This is
138 also an HTMLItem instance.
139 2. if there's no *item* then the current class is available
140 through this name, thus "user/name" and "user/name/menu" will
141 still work - the latter will pull information from the form
142 if it can.
143 *form*
144 The current CGI form information as a mapping of form argument
145 name to value
146 *request* 133 *request*
147 Includes information about the current request, including: 134 Includes information about the current request, including:
148 - the url 135 - the url
149 - the current index information (``filterspec``, ``filter`` args, 136 - the current index information (``filterspec``, ``filter`` args,
150 ``properties``, etc) parsed out of the form. 137 ``properties``, etc) parsed out of the form.
151 - methods for easy filterspec link generation 138 - methods for easy filterspec link generation
152 - *user*, the current user node as an HTMLItem instance 139 - *user*, the current user node as an HTMLItem instance
140 - *form*, the current CGI form information as a FieldStorage
153 *instance* 141 *instance*
154 The current instance 142 The current instance
155 *db* 143 *db*
156 The current database, through which db.config may be reached. 144 The current database, through which db.config may be reached.
157
158 Maybe also:
159
160 *modules*
161 python modules made available (XXX: not sure what's actually in
162 there tho)
163 ''' 145 '''
164 def getContext(self, client, classname, request): 146 def getContext(self, client, classname, request):
165 c = { 147 c = {
166 'klass': HTMLClass(client, classname),
167 'options': {}, 148 'options': {},
168 'nothing': None, 149 'nothing': None,
169 'request': request, 150 'request': request,
170 'content': client.content, 151 'content': client.content,
171 'db': HTMLDatabase(client), 152 'db': HTMLDatabase(client),
172 'instance': client.instance 153 'instance': client.instance
173 } 154 }
174 # add in the item if there is one 155 # add in the item if there is one
175 if client.nodeid: 156 if client.nodeid:
176 c['item'] = HTMLItem(client, classname, client.nodeid) 157 c['context'] = HTMLItem(client, classname, client.nodeid)
177 c[classname] = c['item'] 158 else:
178 else: 159 c['context'] = HTMLClass(client, classname)
179 c[classname] = c['klass']
180 return c 160 return c
181 161
182 def render(self, client, classname, request, **options): 162 def render(self, client, classname, request, **options):
183 """Render this Page Template""" 163 """Render this Page Template"""
184 164
235 215
236 def __getitem__(self, item): 216 def __getitem__(self, item):
237 ''' return an HTMLProperty instance 217 ''' return an HTMLProperty instance
238 ''' 218 '''
239 #print 'getitem', (self, item) 219 #print 'getitem', (self, item)
220
221 # we don't exist
222 if item == 'id':
223 return None
240 if item == 'creator': 224 if item == 'creator':
241 return HTMLUser(self.client, 'user', client.userid) 225 # but we will be created by this user...
242 226 return HTMLUser(self.client, 'user', self.client.userid)
243 if not self.props.has_key(item): 227
244 raise KeyError, item 228 # get the property
245 prop = self.props[item] 229 prop = self.props[item]
246 230
247 # look up the correct HTMLProperty class 231 # look up the correct HTMLProperty class
248 for klass, htmlklass in propclasses: 232 for klass, htmlklass in propclasses:
249 if isinstance(prop, hyperdb.Multilink): 233 if isinstance(prop, hyperdb.Multilink):
396 ''' return an HTMLProperty instance 380 ''' return an HTMLProperty instance
397 ''' 381 '''
398 #print 'getitem', (self, item) 382 #print 'getitem', (self, item)
399 if item == 'id': 383 if item == 'id':
400 return self.nodeid 384 return self.nodeid
401 if not self.props.has_key(item): 385
402 raise KeyError, item 386 # get the property
403 prop = self.props[item] 387 prop = self.props[item]
404 388
405 # get the value, handling missing values 389 # get the value, handling missing values
406 value = self.klass.get(self.nodeid, item, None) 390 value = self.klass.get(self.nodeid, item, None)
407 if value is None: 391 if value is None:

Roundup Issue Tracker: http://roundup-tracker.org/