Skip to content

Commit 66b8be9

Browse files
author
Richard Jones
committed
allow trackers to override the classes used to render properties...
...in templating per issue2550659 (thanks Ezio Melotti)
1 parent dc19265 commit 66b8be9

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ are given with the most recent entry first.
33

44
2010-??-?? 1.4.16
55

6+
Features:
7+
8+
- allow trackers to override the classes used to render properties in
9+
templating per issue2550659 (thanks Ezio Melotti)
10+
611
Fixed:
712

813
- fixed reporting of source missing warnings

roundup/cgi/templating.py

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,42 @@ class StringHTMLProperty(HTMLProperty):
13431343
)''', re.X | re.I)
13441344
protocol_re = re.compile('^(ht|f)tp(s?)://', re.I)
13451345

1346-
def _hyper_repl_item(self,match,replacement):
1346+
1347+
1348+
def _hyper_repl(self, match):
1349+
if match.group('url'):
1350+
return self._hyper_repl_url(match, '<a href="%s">%s</a>%s')
1351+
elif match.group('email'):
1352+
return self._hyper_repl_email(match, '<a href="mailto:%s">%s</a>')
1353+
elif len(match.group('id')) < 10:
1354+
return self._hyper_repl_item(match,
1355+
'<a href="%(cls)s%(id)s">%(item)s</a>')
1356+
else:
1357+
# just return the matched text
1358+
return match.group(0)
1359+
1360+
def _hyper_repl_url(self, match, replacement):
1361+
u = s = match.group('url')
1362+
if not self.protocol_re.search(s):
1363+
u = 'http://' + s
1364+
if s.endswith('&gt;'):
1365+
# catch an escaped ">" at the end of the URL
1366+
u = s = s[:-4]
1367+
e = '&gt;'
1368+
elif s.count('(') != s.count(')'):
1369+
# don't include extraneous ')' in the link
1370+
pos = s.rfind(')')
1371+
e = s[pos:]
1372+
u = s = s[:pos]
1373+
else:
1374+
e = ''
1375+
return replacement % (u, s, e)
1376+
1377+
def _hyper_repl_email(self, match, replacement):
1378+
s = match.group('email')
1379+
return replacement % (s, s)
1380+
1381+
def _hyper_repl_item(self, match, replacement):
13471382
item = match.group('item')
13481383
cls = match.group('class').lower()
13491384
id = match.group('id')
@@ -1356,32 +1391,6 @@ def _hyper_repl_item(self,match,replacement):
13561391
except KeyError:
13571392
return item
13581393

1359-
def _hyper_repl(self, match):
1360-
if match.group('url'):
1361-
u = s = match.group('url')
1362-
if not self.protocol_re.search(s):
1363-
u = 'http://' + s
1364-
if s.endswith('&gt;'):
1365-
# catch an escaped ">" at the end of the URL
1366-
u = s = s[:-4]
1367-
e = '&gt;'
1368-
elif s.count('(') != s.count(')'):
1369-
# don't include extraneous ')' in the link
1370-
pos = s.rfind(')')
1371-
e = s[pos:]
1372-
u = s = s[:pos]
1373-
else:
1374-
e = ''
1375-
return '<a href="%s">%s</a>%s' % (u, s, e)
1376-
elif match.group('email'):
1377-
s = match.group('email')
1378-
return '<a href="mailto:%s">%s</a>' % (s, s)
1379-
elif len(match.group('id')) < 10:
1380-
return self._hyper_repl_item(match,
1381-
'<a href="%(cls)s%(id)s">%(item)s</a>')
1382-
else:
1383-
# just return the matched text
1384-
return match.group(0)
13851394

13861395
def _hyper_repl_rst(self, match):
13871396
if match.group('url'):
@@ -2281,8 +2290,9 @@ def menu(self, size=None, height=None, showid=0, additional=[],
22812290
l.append('</select>')
22822291
return '\n'.join(l)
22832292

2293+
22842294
# set the propclasses for HTMLItem
2285-
propclasses = (
2295+
propclasses = [
22862296
(hyperdb.String, StringHTMLProperty),
22872297
(hyperdb.Number, NumberHTMLProperty),
22882298
(hyperdb.Boolean, BooleanHTMLProperty),
@@ -2291,7 +2301,17 @@ def menu(self, size=None, height=None, showid=0, additional=[],
22912301
(hyperdb.Password, PasswordHTMLProperty),
22922302
(hyperdb.Link, LinkHTMLProperty),
22932303
(hyperdb.Multilink, MultilinkHTMLProperty),
2294-
)
2304+
]
2305+
2306+
def register_propclass(prop, cls):
2307+
for index,propclass in enumerate(propclasses):
2308+
p, c = propclass
2309+
if prop == p:
2310+
propclasses[index] = (prop, cls)
2311+
break
2312+
else:
2313+
propclasses.append((prop, cls))
2314+
22952315

22962316
def make_sort_function(db, classname, sort_on=None):
22972317
"""Make a sort function for a given class

0 commit comments

Comments
 (0)