Skip to content

Commit 026ed3f

Browse files
committed
Add statehelp template filter for outputting a little help icon for a
state with a tooltip and link to the description - Legacy-Id: 6133
1 parent 5a3cccc commit 026ed3f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

ietf/doc/templatetags/ietf_filters.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.template import resolve_variable
1010
from django.utils.safestring import mark_safe, SafeData
1111
from django.utils import simplejson
12+
from django.utils.html import strip_tags
1213
try:
1314
from email import utils as emailutils
1415
except ImportError:
@@ -475,6 +476,14 @@ def state(doc, slug):
475476
slug = "%s-stream-%s" % (doc.type_id, doc.stream_id)
476477
return doc.get_state(slug)
477478

479+
@register.filter
480+
def statehelp(state):
481+
"Output help icon with tooltip for state."
482+
from django.core.urlresolvers import reverse as urlreverse
483+
tooltip = escape(strip_tags(state.desc))
484+
url = urlreverse("state_help", kwargs=dict(type=state.type_id)) + "#" + state.slug
485+
return mark_safe('<a class="state-help-icon" href="%s" title="%s">?</a>' % (url, tooltip))
486+
478487
def _test():
479488
import doctest
480489
doctest.testmod()
@@ -483,11 +492,10 @@ def _test():
483492
_test()
484493

485494
@register.filter
486-
def plural(text, list, arg=u's'):
495+
def plural(text, seq, arg=u's'):
487496
"Similar to pluralize, but looks at the text, too"
488497
from django.template.defaultfilters import pluralize
489498
if text.endswith('s'):
490499
return text
491500
else:
492-
return text + pluralize(len(list), arg)
493-
501+
return text + pluralize(len(seq), arg)

0 commit comments

Comments
 (0)