diff roundup/cgi/templating.py @ 4396:172489ea9e07

allow trackers to override the classes used to render properties... ...in templating per issue2550659 (thanks Ezio Melotti)
author Richard Jones <richard@users.sourceforge.net>
date Sat, 24 Jul 2010 09:44:58 +0000
parents d5239335fae3
children 66603a9051f9
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Tue Jul 13 05:03:49 2010 +0000
+++ b/roundup/cgi/templating.py	Sat Jul 24 09:44:58 2010 +0000
@@ -1343,7 +1343,42 @@
     )''', 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, '<a href="%s">%s</a>%s')
+        elif match.group('email'):
+            return self._hyper_repl_email(match, '<a href="mailto:%s">%s</a>')
+        elif len(match.group('id')) < 10:
+            return self._hyper_repl_item(match,
+                '<a href="%(cls)s%(id)s">%(item)s</a>')
+        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('&gt;'):
+            # catch an escaped ">" at the end of the URL
+            u = s = s[:-4]
+            e = '&gt;'
+        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 @@
         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('&gt;'):
-                # catch an escaped ">" at the end of the URL
-                u = s = s[:-4]
-                e = '&gt;'
-            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 '<a href="%s">%s</a>%s' % (u, s, e)
-        elif match.group('email'):
-            s = match.group('email')
-            return '<a href="mailto:%s">%s</a>' % (s, s)
-        elif len(match.group('id')) < 10:
-            return self._hyper_repl_item(match,
-                '<a href="%(cls)s%(id)s">%(item)s</a>')
-        else:
-            # just return the matched text
-            return match.group(0)
 
     def _hyper_repl_rst(self, match):
         if match.group('url'):
@@ -2281,8 +2290,9 @@
         l.append('</select>')
         return '\n'.join(l)
 
+
 # set the propclasses for HTMLItem
-propclasses = (
+propclasses = [
     (hyperdb.String, StringHTMLProperty),
     (hyperdb.Number, NumberHTMLProperty),
     (hyperdb.Boolean, BooleanHTMLProperty),
@@ -2291,7 +2301,17 @@
     (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

Roundup Issue Tracker: http://roundup-tracker.org/