2011-04-18 13:36:11 +00:00
|
|
|
from django import template
|
|
|
|
from bestpractices.models import BestPractice
|
|
|
|
import re
|
|
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
|
|
|
def link_bps(value):
|
|
|
|
r = r'BP\:[0-9][0-9]?'
|
|
|
|
matches = re.findall(r, value)
|
|
|
|
for match in matches:
|
|
|
|
id = int(match.replace("BP:", "").strip())
|
2011-04-25 19:13:19 +00:00
|
|
|
try:
|
|
|
|
bp = BestPractice.objects.get(pk=id)
|
|
|
|
title = bp.title
|
|
|
|
html = "<a class='bpRelated' href='/itf/bestpractices/stories#%d' title='View related Best Practice story'>%s</a>" % (id, title,)
|
|
|
|
value = value.replace(match, html, 1)
|
|
|
|
except:
|
|
|
|
value = value.replace(match, '', 1)
|
2011-04-18 13:36:11 +00:00
|
|
|
return value
|
|
|
|
|
2011-10-11 12:55:21 +00:00
|
|
|
def abs_link_bps(value):
|
|
|
|
r = r'BP\:[0-9][0-9]?'
|
|
|
|
matches = re.findall(r, value)
|
|
|
|
for match in matches:
|
|
|
|
id = int(match.replace("BP:", "").strip())
|
|
|
|
try:
|
|
|
|
bp = BestPractice.objects.get(pk=id)
|
|
|
|
title = bp.title
|
|
|
|
html = "<a class='bpRelated' href='%s' title='View related Best Practice story'>%s</a>" % (bp.get_absolute_url(), title,)
|
|
|
|
value = value.replace(match, html, 1)
|
|
|
|
except:
|
|
|
|
value = value.replace(match, '', 1)
|
|
|
|
return value
|
|
|
|
|
|
|
|
register.filter("abs_link_bps", abs_link_bps)
|
2011-04-18 13:36:11 +00:00
|
|
|
register.filter("link_bps", link_bps)
|