From: richard Date: Tue, 9 Jul 2002 05:20:09 +0000 (+0000) Subject: . added email display function - mangles email addrs so they're not so easily X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b9701e45bb893a63cc86418b0df694e89fa87753;p=roundup.git . added email display function - mangles email addrs so they're not so easily scraped from the web git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@843 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index efb4ba5..c8e4fdb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -28,6 +28,8 @@ Fixed: - new "reindex" command in roundup-admin used to force regeneration of the index . made the unit tests run again - they were quite b0rken + . added email display function - mangles email addrs so they're not so easily + scraped from the web 2002-06-24 0.4.2 diff --git a/roundup/htmltemplate.py b/roundup/htmltemplate.py index 65e9992..a2bc439 100644 --- a/roundup/htmltemplate.py +++ b/roundup/htmltemplate.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: htmltemplate.py,v 1.96 2002-07-09 04:19:09 richard Exp $ +# $Id: htmltemplate.py,v 1.97 2002-07-09 05:20:09 richard Exp $ __doc__ = """ Template engine. @@ -726,7 +726,7 @@ class TemplateFunctions: return _('') else: return _('[Submit: not called from item]') - + def do_classhelp(self, classname, properties, label='?', width='400', height='400'): '''pop up a javascript window with class help @@ -744,6 +744,35 @@ class TemplateFunctions: properties, width, height, label) #return '(%s)'%(classname, # properties, label) + + def do_email(self, property, escape=0): + '''display the property as one or more "fudged" email addrs + ''' + if not self.nodeid and self.form is None: + return _('[Email: not called from item]') + propclass = self.properties[property] + if self.nodeid: + # get the value for this property + try: + value = self.cl.get(self.nodeid, property) + except KeyError: + # a KeyError here means that the node doesn't have a value + # for the specified property + value = '' + else: + value = '' + if isinstance(propclass, hyperdb.String): + if value is None: value = '' + else: value = str(value) + value = value.replace('@', ' at ') + value = value.replace('.', ' ') + else: + value = _('[Email: not a string]')%locals() + if escape: + value = cgi.escape(value) + return value + + # # INDEX TEMPLATES # @@ -1237,6 +1266,11 @@ class NewItemTemplate(TemplateFunctions): # # $Log: not supported by cvs2svn $ +# Revision 1.96 2002/07/09 04:19:09 richard +# Added reindex command to roundup-admin. +# Fixed reindex on first access. +# Also fixed reindexing of entries that change. +# # Revision 1.95 2002/07/08 15:32:06 gmcm # Pagination of index pages. # New search form. diff --git a/test/test_htmltemplate.py b/test/test_htmltemplate.py index 4082be2..3342ab1 100644 --- a/test/test_htmltemplate.py +++ b/test/test_htmltemplate.py @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_htmltemplate.py,v 1.15 2002-07-08 06:39:00 richard Exp $ +# $Id: test_htmltemplate.py,v 1.16 2002-07-09 05:20:09 richard Exp $ import unittest, cgi, time @@ -41,6 +41,8 @@ class Class: return 'hello, I am HTML' elif attribute == 'multiline': return 'hello\nworld' + elif attribute == 'email': + return 'test@foo.domain.example' def list(self): return ['1', '2'] def filter(self, search_matches, filterspec, sort, group): @@ -50,7 +52,7 @@ class Class: 'link': Link('other'), 'multilink': Multilink('other'), 'password': Password(), 'html': String(), 'key': String(), 'novalue': String(), 'filename': String(), 'multiline': String(), - 'reldate': Date()} + 'reldate': Date(), 'email': String()} def labelprop(self, default_to_id=0): return 'key' @@ -349,12 +351,27 @@ the key2:''') '(?)') +# def do_multiline(self, property, rows=5, cols=40) + def testEmail_string(self): + self.assertEqual(self.tf.do_email('email'), 'test at foo domain example') + + def testEmail_nonstring(self): + s = _('[Email: not a string]') + self.assertEqual(self.tf.do_email('date'), s) + self.assertEqual(self.tf.do_email('interval'), s) + self.assertEqual(self.tf.do_email('password'), s) + self.assertEqual(self.tf.do_email('link'), s) + self.assertEqual(self.tf.do_email('multilink'), s) + def suite(): return unittest.makeSuite(NodeCase, 'test') # # $Log: not supported by cvs2svn $ +# Revision 1.15 2002/07/08 06:39:00 richard +# Fixed unit test support class so the tests ran again. +# # Revision 1.14 2002/05/15 06:37:31 richard # ehem and the unit test #