From eed33db9145686ab18c76cdb19580b23a8557b44 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 24 Jul 2010 09:44:58 +0000 Subject: [PATCH] allow trackers to override the classes used to render properties in templating per issue2550659 (thanks Ezio Melotti) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4502 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 5 +++ roundup/cgi/templating.py | 78 ++++++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9a681fd..06cb7c7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,11 @@ are given with the most recent entry first. 2010-??-?? 1.4.16 +Features: + +- allow trackers to override the classes used to render properties in + templating per issue2550659 (thanks Ezio Melotti) + Fixed: - fixed reporting of source missing warnings diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index 6296a13..9176420 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -1343,7 +1343,42 @@ class StringHTMLProperty(HTMLProperty): )''', re.X | re.I) protocol_re = re.compile('^(ht|f)tp(s?)://', re.I) - def _hyper_repl_item(self,match,replacement): + + + def _hyper_repl(self, match): + if match.group('url'): + return self._hyper_repl_url(match, '%s%s') + elif match.group('email'): + return self._hyper_repl_email(match, '%s') + elif len(match.group('id')) < 10: + return self._hyper_repl_item(match, + '%(item)s') + else: + # just return the matched text + return match.group(0) + + def _hyper_repl_url(self, match, replacement): + u = s = match.group('url') + if not self.protocol_re.search(s): + u = 'http://' + s + if s.endswith('>'): + # catch an escaped ">" at the end of the URL + u = s = s[:-4] + e = '>' + elif s.count('(') != s.count(')'): + # don't include extraneous ')' in the link + pos = s.rfind(')') + e = s[pos:] + u = s = s[:pos] + else: + e = '' + return replacement % (u, s, e) + + def _hyper_repl_email(self, match, replacement): + s = match.group('email') + return replacement % (s, s) + + def _hyper_repl_item(self, match, replacement): item = match.group('item') cls = match.group('class').lower() id = match.group('id') @@ -1356,32 +1391,6 @@ class StringHTMLProperty(HTMLProperty): except KeyError: return item - def _hyper_repl(self, match): - if match.group('url'): - u = s = match.group('url') - if not self.protocol_re.search(s): - u = 'http://' + s - if s.endswith('>'): - # catch an escaped ">" at the end of the URL - u = s = s[:-4] - e = '>' - elif s.count('(') != s.count(')'): - # don't include extraneous ')' in the link - pos = s.rfind(')') - e = s[pos:] - u = s = s[:pos] - else: - e = '' - return '%s%s' % (u, s, e) - elif match.group('email'): - s = match.group('email') - return '%s' % (s, s) - elif len(match.group('id')) < 10: - return self._hyper_repl_item(match, - '%(item)s') - else: - # just return the matched text - return match.group(0) def _hyper_repl_rst(self, match): if match.group('url'): @@ -2281,8 +2290,9 @@ class MultilinkHTMLProperty(HTMLProperty): l.append('') return '\n'.join(l) + # set the propclasses for HTMLItem -propclasses = ( +propclasses = [ (hyperdb.String, StringHTMLProperty), (hyperdb.Number, NumberHTMLProperty), (hyperdb.Boolean, BooleanHTMLProperty), @@ -2291,7 +2301,17 @@ propclasses = ( (hyperdb.Password, PasswordHTMLProperty), (hyperdb.Link, LinkHTMLProperty), (hyperdb.Multilink, MultilinkHTMLProperty), -) +] + +def register_propclass(prop, cls): + for index,propclass in enumerate(propclasses): + p, c = propclass + if prop == p: + propclasses[index] = (prop, cls) + break + else: + propclasses.append((prop, cls)) + def make_sort_function(db, classname, sort_on=None): """Make a sort function for a given class -- 2.30.2