summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 34413d5)
raw | patch | inline | side by side (parent: 34413d5)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 22 Jan 2002 06:35:40 +0000 (06:35 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 22 Jan 2002 06:35:40 +0000 (06:35 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@580 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/htmltemplate.py | patch | blob | history | |
test/test_htmltemplate.py | patch | blob | history |
index 6c59c94b2f00eab55ceb447e5e5b9fc797259258..604b6645f4643a99f565359d3f553a2226fabfb7 100644 (file)
--- a/roundup/htmltemplate.py
+++ b/roundup/htmltemplate.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: htmltemplate.py,v 1.65 2002-01-22 00:12:06 richard Exp $
+# $Id: htmltemplate.py,v 1.66 2002-01-22 06:35:40 richard Exp $
__doc__ = """
Template engine.
'''
if not self.nodeid and self.form is None:
return _('[Link: not called from item]')
+
+ # get the value
+ value = self.determine_value(property)
+ if not value:
+ return _('[no %(propname)s]')%{'propname':property.capitalize()}
+
propclass = self.properties[property]
- if self.nodeid:
- value = self.cl.get(self.nodeid, property)
- else:
- if isinstance(propclass, hyperdb.Multilink): value = []
- elif isinstance(propclass, hyperdb.Link): value = None
- else: value = ''
if isinstance(propclass, hyperdb.Link):
linkname = propclass.classname
- if value is None: return '[no %s]'%property.capitalize()
linkcl = self.db.classes[linkname]
k = linkcl.labelprop()
- linkvalue = linkcl.get(value, k)
+ linkvalue = cgi.escape(linkcl.get(value, k))
if is_download:
return '<a href="%s%s/%s">%s</a>'%(linkname, value,
linkvalue, linkvalue)
linkname = propclass.classname
linkcl = self.db.classes[linkname]
k = linkcl.labelprop()
- if not value:
- return _('[no %(propname)s]')%{'propname': property.capitalize()}
l = []
for value in value:
- linkvalue = linkcl.get(value, k)
+ linkvalue = cgi.escape(linkcl.get(value, k))
if is_download:
l.append('<a href="%s%s/%s">%s</a>'%(linkname, value,
linkvalue, linkvalue))
l.append('<a href="%s%s">%s</a>'%(linkname, value,
linkvalue))
return ', '.join(l)
- if isinstance(propclass, hyperdb.String) and value == '':
- return _('[no %(propname)s]')%{'propname': property.capitalize()}
if is_download:
return '<a href="%s%s/%s">%s</a>'%(self.classname, self.nodeid,
value, value)
#
# $Log: not supported by cvs2svn $
+# Revision 1.65 2002/01/22 00:12:06 richard
+# Wrote more unit tests for htmltemplate, and while I was at it, I polished
+# off the implementation of some of the functions so they behave sanely.
+#
# Revision 1.64 2002/01/21 03:25:59 richard
# oops
#
index 3c7143b352c2c382220f6d6d6e50b311ccf3eee3..0285a71cc7b58bbf737bcbb73dae2759c3c4f36c 100644 (file)
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
-# $Id: test_htmltemplate.py,v 1.2 2002-01-22 00:12:07 richard Exp $
+# $Id: test_htmltemplate.py,v 1.3 2002-01-22 06:35:40 richard Exp $
import unittest, cgi
+from roundup import date, password
from roundup.htmltemplate import TemplateFunctions
-from roundup import date
-from roundup import password
+from roundup.i18n import _
from roundup.hyperdb import String, Password, Date, Interval, Link, Multilink
class Class:
def get(self, nodeid, attribute, default=None):
if attribute == 'string':
return 'Node %s: I am a string'%nodeid
+ elif attribute == 'filename':
+ return 'file.foo'
elif attribute == 'date':
return date.Date('2000-01-01')
elif attribute == 'interval':
def getprops(self):
return {'string': String(), 'date': Date(), 'interval': Interval(),
'link': Link('other'), 'multilink': Multilink('other'),
- 'password': Password(), 'html': String(), 'key': String()}
+ 'password': Password(), 'html': String(), 'key': String(),
+ 'novalue': String(), 'filename': String()}
def labelprop(self):
return 'key'
self.tf = tf = TemplateFunctions()
tf.nodeid = '1'
tf.cl = Class()
+ tf.classname = 'test_class'
tf.properties = tf.cl.getprops()
tf.db = Database()
'<input name="multilink" size="10" value="the key,the key">')
# def do_menu(self, property, size=None, height=None, showid=0):
+ def testMenu_nonlinks(self):
+ self.assertEqual(self.tf.do_menu('string'), _('[Menu: not a link]'))
+ self.assertEqual(self.tf.do_menu('date'), _('[Menu: not a link]'))
+ self.assertEqual(self.tf.do_menu('interval'), _('[Menu: not a link]'))
+ self.assertEqual(self.tf.do_menu('password'), _('[Menu: not a link]'))
+
def testMenu_link(self):
self.assertEqual(self.tf.do_menu('link'), '''<select name="link">
<option value="-1">- no selection -</option>
<option selected value="2">other2: the key</option>
</select>''')
+# def do_link(self, property=None, is_download=0):
+ def testLink_novalue(self):
+ self.assertEqual(self.tf.do_link('novalue'),
+ _('[no %(propname)s]')%{'propname':'novalue'.capitalize()})
+
+ def testLink_string(self):
+ self.assertEqual(self.tf.do_link('string'),
+ '<a href="test_class1">Node 1: I am a string</a>')
+
+ def testLink_file(self):
+ self.assertEqual(self.tf.do_link('filename', is_download=1),
+ '<a href="test_class1/file.foo">file.foo</a>')
+
+ def testLink_date(self):
+ self.assertEqual(self.tf.do_link('date'),
+ '<a href="test_class1">2000-01-01.00:00:00</a>')
+
+ def testLink_interval(self):
+ self.assertEqual(self.tf.do_link('interval'),
+ '<a href="test_class1">- 3d</a>')
+
+ def testLink_link(self):
+ self.assertEqual(self.tf.do_link('link'),
+ '<a href="other1">the key</a>')
+
+ def testLink_multilink(self):
+ self.assertEqual(self.tf.do_link('multilink'),
+ '<a href="other1">the key</a>, <a href="other2">the key</a>')
+
def suite():
return unittest.makeSuite(NodeCase, 'test')
#
# $Log: not supported by cvs2svn $
+# Revision 1.2 2002/01/22 00:12:07 richard
+# Wrote more unit tests for htmltemplate, and while I was at it, I polished
+# off the implementation of some of the functions so they behave sanely.
+#
# Revision 1.1 2002/01/21 11:05:48 richard
# New tests for htmltemplate (well, it's a beginning)
#