Skip to content

Commit c27b023

Browse files
author
Richard Jones
committed
More HTML template cleanup and unit tests.
- download() now implemented correctly, replacing link(is_download=1) [fixed in the templates, but link(is_download=1) will still work for existing templates]
1 parent aee770b commit c27b023

File tree

5 files changed

+60
-33
lines changed

5 files changed

+60
-33
lines changed

doc/index.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,7 @@ <h3>Displaying Properties</h3>
10091009
For other properties, link to this node with the property as the text.
10101010
<p>
10111011
<em>Options:</em><br>
1012-
property (property name) - the property to use in the second case.<br>
1013-
is_download (boolean) - to be used for links te <em>file</em> class nodes -
1014-
this indicates that the URL should have the specified property (usually
1015-
<em>name</em>) appended so that the download has the correct name (instead
1016-
of the node designator.)
1012+
property (property name) - the property to use in the second case.
10171013
</td></tr>
10181014

10191015
<tr><td valign="top"><strong>count</strong></td>
@@ -1037,8 +1033,13 @@ <h3>Displaying Properties</h3>
10371033
</td></tr>
10381034

10391035
<tr><td valign="top"><strong>download</strong></td>
1040-
<td>Show a Link("file") or Multilink("file")
1041-
property using links that allow you to download files.
1036+
<td>For a Link or Multilink property, display the names of the linked
1037+
nodes, hyperlinked to the item views on those nodes.
1038+
<p>
1039+
For other properties, link to this node with the property as the text.
1040+
<p>
1041+
In all cases, append the name (key property) of the item to the path so it
1042+
is the name of the file being downloaded.
10421043
<p>
10431044
<em>Arguments:</em><br>
10441045
property (property name) - the property to use.
@@ -1303,7 +1304,7 @@ <h1><a name="ack">Acknowledgements</a></h1>
13031304

13041305
<p>&nbsp;</p>
13051306
<hr>
1306-
$Id: index.html,v 1.26 2002-01-16 04:54:27 richard Exp $
1307+
$Id: index.html,v 1.27 2002-01-23 05:10:27 richard Exp $
13071308
<p>&nbsp;</p>
13081309

13091310
</body></html>

roundup/htmltemplate.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: htmltemplate.py,v 1.68 2002-01-22 22:55:28 richard Exp $
18+
# $Id: htmltemplate.py,v 1.69 2002-01-23 05:10:27 richard Exp $
1919

2020
__doc__ = """
2121
Template engine.
@@ -389,20 +389,7 @@ def do_download(self, property, **args):
389389
'''
390390
if not self.nodeid:
391391
return _('[Download: not called from item]')
392-
propclass = self.properties[property]
393-
value = self.cl.get(self.nodeid, property)
394-
if isinstance(propclass, hyperdb.Link):
395-
linkcl = self.db.classes[propclass.classname]
396-
linkvalue = linkcl.get(value, k)
397-
return '<a href="%s%s">%s</a>'%(linkcl, value, linkvalue)
398-
if isinstance(propclass, hyperdb.Multilink):
399-
linkcl = self.db.classes[propclass.classname]
400-
l = []
401-
for value in value:
402-
linkvalue = linkcl.get(value, k)
403-
l.append('<a href="%s%s">%s</a>'%(linkcl, value, linkvalue))
404-
return ', '.join(l)
405-
return _('[Download: not a link]')
392+
return self.do_link(property, is_download=1)
406393

407394

408395
def do_checklist(self, property, **args):
@@ -468,7 +455,7 @@ def do_list(self, property, reverse=0):
468455
if not isinstance(propcl, hyperdb.Multilink):
469456
return _('[List: not a Multilink]')
470457
value = self.cl.get(self.nodeid, property)
471-
value.sort()
458+
value.sort()
472459
if reverse:
473460
value.reverse()
474461

@@ -505,6 +492,7 @@ def do_history(self, direction='descending'):
505492

506493
comments = {}
507494
history = self.cl.history(self.nodeid)
495+
history.sort()
508496
if direction == 'descending':
509497
history.reverse()
510498
for id, evt_date, user, action, args in history:
@@ -1048,6 +1036,9 @@ def render(self, form):
10481036

10491037
#
10501038
# $Log: not supported by cvs2svn $
1039+
# Revision 1.68 2002/01/22 22:55:28 richard
1040+
# . htmltemplate list() wasn't sorting...
1041+
#
10511042
# Revision 1.67 2002/01/22 22:46:22 richard
10521043
# more htmltemplate cleanups and unit tests
10531044
#

roundup/templates/classic/html/file.index

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<!-- $Id: file.index,v 1.3 2001-10-21 11:42:15 richard Exp $-->
1+
<!-- $Id: file.index,v 1.4 2002-01-23 05:10:27 richard Exp $-->
22
<tr>
33
<property name="name">
4-
<td><display call="link('name', is_download=1)"></td>
4+
<td><display call="download('name')"></td>
55
</property>
66
<property name="type">
77
<td><display call="plain('type')"></td>

roundup/templates/extended/html/file.index

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<!-- $Id: file.index,v 1.2 2001-10-21 11:42:15 richard Exp $-->
1+
<!-- $Id: file.index,v 1.3 2002-01-23 05:10:28 richard Exp $-->
22
<tr>
33
<property name="name">
4-
<td><display call="link('name', is_download=1)"></td>
4+
<td><display call="download('name')"></td>
55
</property>
66
<property name="type">
77
<td><display call="plain('type')"></td>

test/test_htmltemplate.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_htmltemplate.py,v 1.4 2002-01-22 22:46:22 richard Exp $
11+
# $Id: test_htmltemplate.py,v 1.5 2002-01-23 05:10:28 richard Exp $
1212

1313
import unittest, cgi
1414

@@ -139,10 +139,11 @@ def testField_multilink(self):
139139

140140
# def do_menu(self, property, size=None, height=None, showid=0):
141141
def testMenu_nonlinks(self):
142-
self.assertEqual(self.tf.do_menu('string'), _('[Menu: not a link]'))
143-
self.assertEqual(self.tf.do_menu('date'), _('[Menu: not a link]'))
144-
self.assertEqual(self.tf.do_menu('interval'), _('[Menu: not a link]'))
145-
self.assertEqual(self.tf.do_menu('password'), _('[Menu: not a link]'))
142+
s = _('[Menu: not a link]')
143+
self.assertEqual(self.tf.do_menu('string'), s)
144+
self.assertEqual(self.tf.do_menu('date'), s)
145+
self.assertEqual(self.tf.do_menu('interval'), s)
146+
self.assertEqual(self.tf.do_menu('password'), s)
146147

147148
def testMenu_link(self):
148149
self.assertEqual(self.tf.do_menu('link'), '''<select name="link">
@@ -235,12 +236,46 @@ def testReldate_date(self):
235236
self.assertEqual(self.tf.do_reldate('date', pretty=1),
236237
' 1 January 2000')
237238

239+
# def do_download(self, property):
240+
def testDownload_novalue(self):
241+
self.assertEqual(self.tf.do_download('novalue'),
242+
_('[no %(propname)s]')%{'propname':'novalue'.capitalize()})
243+
244+
def testDownload_string(self):
245+
self.assertEqual(self.tf.do_download('string'),
246+
'<a href="test_class1/Node 1: I am a string">Node 1: '
247+
'I am a string</a>')
248+
249+
def testDownload_file(self):
250+
self.assertEqual(self.tf.do_download('filename', is_download=1),
251+
'<a href="test_class1/file.foo">file.foo</a>')
252+
253+
def testDownload_date(self):
254+
self.assertEqual(self.tf.do_download('date'),
255+
'<a href="test_class1/2000-01-01.00:00:00">2000-01-01.00:00:00</a>')
256+
257+
def testDownload_interval(self):
258+
self.assertEqual(self.tf.do_download('interval'),
259+
'<a href="test_class1/- 3d">- 3d</a>')
260+
261+
def testDownload_link(self):
262+
self.assertEqual(self.tf.do_download('link'),
263+
'<a href="other1/the key">the key</a>')
264+
265+
def testDownload_multilink(self):
266+
self.assertEqual(self.tf.do_download('multilink'),
267+
'<a href="other1/the key">the key</a>, '
268+
'<a href="other2/the key">the key</a>')
269+
238270
def suite():
239271
return unittest.makeSuite(NodeCase, 'test')
240272

241273

242274
#
243275
# $Log: not supported by cvs2svn $
276+
# Revision 1.4 2002/01/22 22:46:22 richard
277+
# more htmltemplate cleanups and unit tests
278+
#
244279
# Revision 1.3 2002/01/22 06:35:40 richard
245280
# more htmltemplate tests and cleanup
246281
#

0 commit comments

Comments
 (0)