comparison roundup/cgi/client.py @ 1204:b862bbf2067a

Replaced the content() callback ickiness with Page Template macro usage changed the default CSS style to be less offensive to some ;) better handling of Page Template compilation errors removed dependency on ComputedAttribute
author Richard Jones <richard@users.sourceforge.net>
date Wed, 25 Sep 2002 02:10:25 +0000
parents ee204fb67798
children 619ab5de5af0
comparison
equal deleted inserted replaced
1203:735adcbfc665 1204:b862bbf2067a
1 # $Id: client.py,v 1.41 2002-09-24 02:00:09 richard Exp $ 1 # $Id: client.py,v 1.42 2002-09-25 02:10:25 richard Exp $
2 2
3 __doc__ = """ 3 __doc__ = """
4 WWW request handler (also used in the stand-alone server). 4 WWW request handler (also used in the stand-alone server).
5 """ 5 """
6 6
8 import binascii, Cookie, time, random 8 import binascii, Cookie, time, random
9 9
10 from roundup import roundupdb, date, hyperdb, password 10 from roundup import roundupdb, date, hyperdb, password
11 from roundup.i18n import _ 11 from roundup.i18n import _
12 12
13 from roundup.cgi.templating import getTemplate, HTMLRequest, NoTemplate 13 from roundup.cgi.templating import Templates, HTMLRequest, NoTemplate
14 from roundup.cgi import cgitb 14 from roundup.cgi import cgitb
15 15
16 from roundup.cgi.PageTemplates import PageTemplate 16 from roundup.cgi.PageTemplates import PageTemplate
17 17
18 class Unauthorised(ValueError): 18 class Unauthorised(ValueError):
150 # we don't want clients caching our dynamic pages 150 # we don't want clients caching our dynamic pages
151 self.additional_headers['Cache-Control'] = 'no-cache' 151 self.additional_headers['Cache-Control'] = 'no-cache'
152 self.additional_headers['Pragma'] = 'no-cache' 152 self.additional_headers['Pragma'] = 'no-cache'
153 self.additional_headers['Expires'] = 'Thu, 1 Jan 1970 00:00:00 GMT' 153 self.additional_headers['Expires'] = 'Thu, 1 Jan 1970 00:00:00 GMT'
154 154
155 if self.form.has_key(':contentonly'): 155 # render the content
156 # just the content 156 self.write(self.renderContext())
157 self.write(self.content())
158 else:
159 # render the content inside the page template
160 self.write(self.renderTemplate('page', '',
161 ok_message=self.ok_message,
162 error_message=self.error_message))
163 except Redirect, url: 157 except Redirect, url:
164 # let's redirect - if the url isn't None, then we need to do 158 # let's redirect - if the url isn't None, then we need to do
165 # the headers, otherwise the headers have been set before the 159 # the headers, otherwise the headers have been set before the
166 # exception was raised 160 # exception was raised
167 if url: 161 if url:
331 mt = mimetypes.guess_type(str(file))[0] 325 mt = mimetypes.guess_type(str(file))[0]
332 self.additional_headers['Content-Type'] = mt 326 self.additional_headers['Content-Type'] = mt
333 self.write(open(os.path.join(self.instance.config.TEMPLATES, 327 self.write(open(os.path.join(self.instance.config.TEMPLATES,
334 file)).read()) 328 file)).read())
335 329
336 def renderTemplate(self, name, extension, **kwargs): 330 def renderContext(self):
337 ''' Return a PageTemplate for the named page 331 ''' Return a PageTemplate for the named page
338 ''' 332 '''
339 pt = getTemplate(self.instance.config.TEMPLATES, name, extension) 333 name = self.classname
334 extension = self.template
335 pt = Templates(self.instance.config.TEMPLATES).get(name, extension)
336
340 # catch errors so we can handle PT rendering errors more nicely 337 # catch errors so we can handle PT rendering errors more nicely
338 args = {
339 'ok_message': self.ok_message,
340 'error_message': self.error_message
341 }
341 try: 342 try:
342 # let the template render figure stuff out 343 # let the template render figure stuff out
343 return pt.render(self, None, None, **kwargs) 344 return pt.render(self, None, None, **args)
344 except PageTemplate.PTRuntimeError, message:
345 return '<strong>%s</strong><ol><li>%s</ol>'%(message,
346 '<li>'.join([cgi.escape(x) for x in pt._v_errors]))
347 except NoTemplate, message: 345 except NoTemplate, message:
348 return '<strong>%s</strong>'%message 346 return '<strong>%s</strong>'%message
349 except: 347 except:
350 # everything else 348 # everything else
351 return cgitb.pt_html() 349 return cgitb.pt_html()
352
353 def content(self):
354 ''' Callback used by the page template to render the content of
355 the page.
356
357 If we don't have a specific class to display, that is none was
358 determined in determine_context(), then we display a "home"
359 template.
360 '''
361 # now render the page content using the template we determined in
362 # determine_context
363 if self.classname is None:
364 name = 'home'
365 else:
366 name = self.classname
367 return self.renderTemplate(self.classname, self.template)
368 350
369 # these are the actions that are available 351 # these are the actions that are available
370 actions = ( 352 actions = (
371 ('edit', 'editItemAction'), 353 ('edit', 'editItemAction'),
372 ('editCSV', 'editCSVAction'), 354 ('editCSV', 'editCSVAction'),

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