X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fhtmltemplate.py;h=2f6557a1fdb0abba2b3e4d660048c9cfdc2e923b;hb=1941cfdb27feaa4e680a155d978b7cbe102a0dc5;hp=159041051d006b97e815c3a22349bbb18902bbf0;hpb=295d74d26099e5316a115d7d1ea9e529e331d4ca;p=roundup.git
diff --git a/roundup/htmltemplate.py b/roundup/htmltemplate.py
index 1590410..2f6557a 100644
--- a/roundup/htmltemplate.py
+++ b/roundup/htmltemplate.py
@@ -15,15 +15,15 @@
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: htmltemplate.py,v 1.69 2002-01-23 05:10:27 richard Exp $
+# $Id: htmltemplate.py,v 1.89 2002-05-15 06:34:47 richard Exp $
__doc__ = """
Template engine.
"""
-import os, re, StringIO, urllib, cgi, errno
+import os, re, StringIO, urllib, cgi, errno, types, urllib
-import hyperdb, date, password
+import hyperdb, date
from i18n import _
# This imports the StructureText functionality for the do_stext function
@@ -33,7 +33,15 @@ try:
except ImportError:
StructuredText = None
+class MissingTemplateError(ValueError):
+ '''Error raised when a template file is missing
+ '''
+ pass
+
class TemplateFunctions:
+ '''Defines the templating functions that are used in the HTML templates
+ of the roundup web interface.
+ '''
def __init__(self):
self.form = None
self.nodeid = None
@@ -43,6 +51,15 @@ class TemplateFunctions:
if key[:3] == 'do_':
self.globals[key[3:]] = getattr(self, key)
+ # These are added by the subclass where appropriate
+ self.client = None
+ self.instance = None
+ self.templates = None
+ self.classname = None
+ self.db = None
+ self.cl = None
+ self.properties = None
+
def do_plain(self, property, escape=0):
''' display a String property directly;
@@ -58,7 +75,7 @@ class TemplateFunctions:
if self.nodeid:
# make sure the property is a valid one
# TODO: this tests, but we should handle the exception
- prop_test = self.cl.getprops()[property]
+ dummy = self.cl.getprops()[property]
# get the value for this property
try:
@@ -93,9 +110,12 @@ class TemplateFunctions:
elif isinstance(propclass, hyperdb.Multilink):
linkcl = self.db.classes[propclass.classname]
k = linkcl.labelprop()
- value = ', '.join(value)
+ labels = []
+ for v in value:
+ labels.append(linkcl.get(v, k))
+ value = ', '.join(labels)
else:
- s = _('Plain: bad propclass "%(propclass)s"')%locals()
+ value = _('Plain: bad propclass "%(propclass)s"')%locals()
if escape:
value = cgi.escape(value)
return value
@@ -203,9 +223,8 @@ class TemplateFunctions:
elif isinstance(propclass, hyperdb.Multilink):
sortfunc = self.make_sort_function(propclass.classname)
linkcl = self.db.classes[propclass.classname]
- list = linkcl.list()
- list.sort(sortfunc)
- l = []
+ if value:
+ value.sort(sortfunc)
# map the id to the label property
if not showid:
k = linkcl.labelprop()
@@ -216,6 +235,27 @@ class TemplateFunctions:
s = _('Plain: bad propclass "%(propclass)s"')%locals()
return s
+ def do_multiline(self, property, rows=5, cols=40):
+ ''' display a string property in a multiline text edit field
+ '''
+ if not self.nodeid and self.form is None and self.filterspec is None:
+ return _('[Multiline: not called from item]')
+
+ propclass = self.properties[property]
+
+ # make sure this is a link property
+ if not isinstance(propclass, hyperdb.String):
+ return _('[Multiline: not a string]')
+
+ # get the value
+ value = self.determine_value(property)
+ if value is None:
+ value = ''
+
+ # display
+ return ''%(
+ property, rows, cols, value)
+
def do_menu(self, property, size=None, height=None, showid=0):
''' for a Link property, display a menu of the available choices
'''
@@ -236,20 +276,17 @@ class TemplateFunctions:
value = self.determine_value(property)
# display
- if isinstance(propclass, hyperdb.Link):
+ if isinstance(propclass, hyperdb.Multilink):
linkcl = self.db.classes[propclass.classname]
- l = ['