comparison roundup/cgi/templating.py @ 2005:fc52d57c6c3e

documentation cleanup
author Richard Jones <richard@users.sourceforge.net>
date Wed, 11 Feb 2004 23:55:10 +0000
parents b046b65e51db
children 1b11ffd8015e
comparison
equal deleted inserted replaced
2004:1782fe36e7b8 2005:fc52d57c6c3e
1 """Implements the API used in the HTML templating for the web interface.
2 """
3 __docformat__ = 'restructuredtext'
4
1 from __future__ import nested_scopes 5 from __future__ import nested_scopes
2 6
3 import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes 7 import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes
4 8
5 from roundup import hyperdb, date, rcsv 9 from roundup import hyperdb, date, rcsv
141 return self.get(name, extension) 145 return self.get(name, extension)
142 except NoTemplate, message: 146 except NoTemplate, message:
143 raise KeyError, message 147 raise KeyError, message
144 148
145 class RoundupPageTemplate(PageTemplate.PageTemplate): 149 class RoundupPageTemplate(PageTemplate.PageTemplate):
146 ''' A Roundup-specific PageTemplate. 150 '''A Roundup-specific PageTemplate.
147 151
148 Interrogate the client to set up the various template variables to 152 Interrogate the client to set up the various template variables to
149 be available: 153 be available:
150 154
151 *context* 155 *context*
152 this is one of three things: 156 this is one of three things:
153 1. None - we're viewing a "home" page 157
154 2. The current class of item being displayed. This is an HTMLClass 158 1. None - we're viewing a "home" page
155 instance. 159 2. The current class of item being displayed. This is an HTMLClass
156 3. The current item from the database, if we're viewing a specific 160 instance.
157 item, as an HTMLItem instance. 161 3. The current item from the database, if we're viewing a specific
158 *request* 162 item, as an HTMLItem instance.
159 Includes information about the current request, including: 163 *request*
160 - the url 164 Includes information about the current request, including:
161 - the current index information (``filterspec``, ``filter`` args, 165
162 ``properties``, etc) parsed out of the form. 166 - the url
163 - methods for easy filterspec link generation 167 - the current index information (``filterspec``, ``filter`` args,
164 - *user*, the current user node as an HTMLItem instance 168 ``properties``, etc) parsed out of the form.
165 - *form*, the current CGI form information as a FieldStorage 169 - methods for easy filterspec link generation
166 *config* 170 - *user*, the current user node as an HTMLItem instance
167 The current tracker config. 171 - *form*, the current CGI form information as a FieldStorage
168 *db* 172 *config*
169 The current database, used to access arbitrary database items. 173 The current tracker config.
170 *utils* 174 *db*
171 This is a special class that has its base in the TemplatingUtils 175 The current database, used to access arbitrary database items.
172 class in this file. If the tracker interfaces module defines a 176 *utils*
173 TemplatingUtils class then it is mixed in, overriding the methods 177 This is a special class that has its base in the TemplatingUtils
174 in the base class. 178 class in this file. If the tracker interfaces module defines a
179 TemplatingUtils class then it is mixed in, overriding the methods
180 in the base class.
175 ''' 181 '''
176 def getContext(self, client, classname, request): 182 def getContext(self, client, classname, request):
177 # construct the TemplatingUtils class 183 # construct the TemplatingUtils class
178 utils = TemplatingUtils 184 utils = TemplatingUtils
179 if hasattr(client.instance.interfaces, 'TemplatingUtils'): 185 if hasattr(client.instance.interfaces, 'TemplatingUtils'):
960 def hyperlinked(self): 966 def hyperlinked(self):
961 ''' Render a "hyperlinked" version of the text ''' 967 ''' Render a "hyperlinked" version of the text '''
962 return self.plain(hyperlink=1) 968 return self.plain(hyperlink=1)
963 969
964 def plain(self, escape=0, hyperlink=0): 970 def plain(self, escape=0, hyperlink=0):
965 ''' Render a "plain" representation of the property 971 '''Render a "plain" representation of the property
966 972
967 "escape" turns on/off HTML quoting 973 - "escape" turns on/off HTML quoting
968 "hyperlink" turns on/off in-text hyperlinking of URLs, email 974 - "hyperlink" turns on/off in-text hyperlinking of URLs, email
969 addresses and designators 975 addresses and designators
970 ''' 976 '''
971 self.view_check() 977 self.view_check()
972 978
973 if self._value is None: 979 if self._value is None:
974 return '' 980 return ''
1439 klass = HTMLItem 1445 klass = HTMLItem
1440 return klass(self._client, self._prop.classname, value) 1446 return klass(self._client, self._prop.classname, value)
1441 1447
1442 def __contains__(self, value): 1448 def __contains__(self, value):
1443 ''' Support the "in" operator. We have to make sure the passed-in 1449 ''' Support the "in" operator. We have to make sure the passed-in
1444 value is a string first, not a *HTMLProperty. 1450 value is a string first, not a HTMLProperty.
1445 ''' 1451 '''
1446 return str(value) in self._value 1452 return str(value) in self._value
1447 1453
1448 def reverse(self): 1454 def reverse(self):
1449 ''' return the list in reverse order 1455 ''' return the list in reverse order
1599 self.columns[col] = 1 1605 self.columns[col] = 1
1600 def __getitem__(self, name): 1606 def __getitem__(self, name):
1601 return self.columns.has_key(name) 1607 return self.columns.has_key(name)
1602 1608
1603 class HTMLRequest(HTMLInputMixin): 1609 class HTMLRequest(HTMLInputMixin):
1604 ''' The *request*, holding the CGI form and environment. 1610 '''The *request*, holding the CGI form and environment.
1605 1611
1606 "form" the CGI form as a cgi.FieldStorage 1612 - "form" the CGI form as a cgi.FieldStorage
1607 "env" the CGI environment variables 1613 - "env" the CGI environment variables
1608 "base" the base URL for this instance 1614 - "base" the base URL for this instance
1609 "user" a HTMLUser instance for this user 1615 - "user" a HTMLUser instance for this user
1610 "classname" the current classname (possibly None) 1616 - "classname" the current classname (possibly None)
1611 "template" the current template (suffix, also possibly None) 1617 - "template" the current template (suffix, also possibly None)
1612 1618
1613 Index args: 1619 Index args:
1614 "columns" dictionary of the columns to display in an index page 1620
1615 "show" a convenience access to columns - request/show/colname will 1621 - "columns" dictionary of the columns to display in an index page
1616 be true if the columns should be displayed, false otherwise 1622 - "show" a convenience access to columns - request/show/colname will
1617 "sort" index sort column (direction, column name) 1623 be true if the columns should be displayed, false otherwise
1618 "group" index grouping property (direction, column name) 1624 - "sort" index sort column (direction, column name)
1619 "filter" properties to filter the index on 1625 - "group" index grouping property (direction, column name)
1620 "filterspec" values to filter the index on 1626 - "filter" properties to filter the index on
1621 "search_text" text to perform a full-text search on for an index 1627 - "filterspec" values to filter the index on
1622 1628 - "search_text" text to perform a full-text search on for an index
1623 ''' 1629 '''
1624 def __init__(self, client): 1630 def __init__(self, client):
1625 # _client is needed by HTMLInputMixin 1631 # _client is needed by HTMLInputMixin
1626 self._client = self.client = client 1632 self._client = self.client = client
1627 1633

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