Skip to content

Commit 69ebf3c

Browse files
author
Richard Jones
committed
added email display function
mangles email addrs so they're not so easily scraped from the web
1 parent 0cf2a53 commit 69ebf3c

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Fixed:
2828
- new "reindex" command in roundup-admin used to force regeneration of the
2929
index
3030
. made the unit tests run again - they were quite b0rken
31+
. added email display function - mangles email addrs so they're not so easily
32+
scraped from the web
3133

3234

3335
2002-06-24 0.4.2

roundup/htmltemplate.py

Lines changed: 36 additions & 2 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.96 2002-07-09 04:19:09 richard Exp $
18+
# $Id: htmltemplate.py,v 1.97 2002-07-09 05:20:09 richard Exp $
1919

2020
__doc__ = """
2121
Template engine.
@@ -726,7 +726,7 @@ def do_submit(self):
726726
return _('<input type="submit" name="submit" value="Submit New Entry">')
727727
else:
728728
return _('[Submit: not called from item]')
729-
729+
730730
def do_classhelp(self, classname, properties, label='?', width='400',
731731
height='400'):
732732
'''pop up a javascript window with class help
@@ -744,6 +744,35 @@ def do_classhelp(self, classname, properties, label='?', width='400',
744744
properties, width, height, label)
745745
#return '<a href="classhelp?classname=%s&properties=%s" target="classhelp"><b>(%s)</b></a>'%(classname,
746746
# properties, label)
747+
748+
def do_email(self, property, escape=0):
749+
'''display the property as one or more "fudged" email addrs
750+
'''
751+
if not self.nodeid and self.form is None:
752+
return _('[Email: not called from item]')
753+
propclass = self.properties[property]
754+
if self.nodeid:
755+
# get the value for this property
756+
try:
757+
value = self.cl.get(self.nodeid, property)
758+
except KeyError:
759+
# a KeyError here means that the node doesn't have a value
760+
# for the specified property
761+
value = ''
762+
else:
763+
value = ''
764+
if isinstance(propclass, hyperdb.String):
765+
if value is None: value = ''
766+
else: value = str(value)
767+
value = value.replace('@', ' at ')
768+
value = value.replace('.', ' ')
769+
else:
770+
value = _('[Email: not a string]')%locals()
771+
if escape:
772+
value = cgi.escape(value)
773+
return value
774+
775+
747776
#
748777
# INDEX TEMPLATES
749778
#
@@ -1237,6 +1266,11 @@ def render(self, form):
12371266

12381267
#
12391268
# $Log: not supported by cvs2svn $
1269+
# Revision 1.96 2002/07/09 04:19:09 richard
1270+
# Added reindex command to roundup-admin.
1271+
# Fixed reindex on first access.
1272+
# Also fixed reindexing of entries that change.
1273+
#
12401274
# Revision 1.95 2002/07/08 15:32:06 gmcm
12411275
# Pagination of index pages.
12421276
# New search form.

test/test_htmltemplate.py

Lines changed: 19 additions & 2 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.15 2002-07-08 06:39:00 richard Exp $
11+
# $Id: test_htmltemplate.py,v 1.16 2002-07-09 05:20:09 richard Exp $
1212

1313
import unittest, cgi, time
1414

@@ -41,6 +41,8 @@ def get(self, nodeid, attribute, default=None):
4141
return '<html>hello, I am HTML</html>'
4242
elif attribute == 'multiline':
4343
return 'hello\nworld'
44+
elif attribute == 'email':
45+
4446
def list(self):
4547
return ['1', '2']
4648
def filter(self, search_matches, filterspec, sort, group):
@@ -50,7 +52,7 @@ def getprops(self):
5052
'link': Link('other'), 'multilink': Multilink('other'),
5153
'password': Password(), 'html': String(), 'key': String(),
5254
'novalue': String(), 'filename': String(), 'multiline': String(),
53-
'reldate': Date()}
55+
'reldate': Date(), 'email': String()}
5456
def labelprop(self, default_to_id=0):
5557
return 'key'
5658

@@ -349,12 +351,27 @@ def testClasshelp(self):
349351
'<a href="javascript:help_window(\'classhelp?classname=theclass'
350352
'&properties=prop1,prop2\', \'400\', \'400\')"><b>(?)</b></a>')
351353

354+
# def do_multiline(self, property, rows=5, cols=40)
355+
def testEmail_string(self):
356+
self.assertEqual(self.tf.do_email('email'), 'test at foo domain example')
357+
358+
def testEmail_nonstring(self):
359+
s = _('[Email: not a string]')
360+
self.assertEqual(self.tf.do_email('date'), s)
361+
self.assertEqual(self.tf.do_email('interval'), s)
362+
self.assertEqual(self.tf.do_email('password'), s)
363+
self.assertEqual(self.tf.do_email('link'), s)
364+
self.assertEqual(self.tf.do_email('multilink'), s)
365+
352366
def suite():
353367
return unittest.makeSuite(NodeCase, 'test')
354368

355369

356370
#
357371
# $Log: not supported by cvs2svn $
372+
# Revision 1.15 2002/07/08 06:39:00 richard
373+
# Fixed unit test support class so the tests ran again.
374+
#
358375
# Revision 1.14 2002/05/15 06:37:31 richard
359376
# ehem and the unit test
360377
#

0 commit comments

Comments
 (0)