space-accessstablestage
|
Last change
on this file was
4bf8692,
checked in by Alex Dehnert <adehnert@…>, 13 years ago
|
|
Add and use constitution linkifying filter (ASA-#146)
|
-
Property mode set to
100644
|
|
File size:
646 bytes
|
| Line | |
|---|
| 1 | from django import template |
|---|
| 2 | from django.utils.html import conditional_escape |
|---|
| 3 | from django.utils.safestring import mark_safe |
|---|
| 4 | |
|---|
| 5 | register = template.Library() |
|---|
| 6 | |
|---|
| 7 | @register.filter(needs_autoescape=True) |
|---|
| 8 | def format_constitution_link(url, autoescape=None): |
|---|
| 9 | if autoescape: |
|---|
| 10 | esc = conditional_escape |
|---|
| 11 | else: |
|---|
| 12 | esc = lambda x: x |
|---|
| 13 | |
|---|
| 14 | if url: |
|---|
| 15 | text = esc(url) |
|---|
| 16 | else: |
|---|
| 17 | text = mark_safe("<em>not provided</em>") |
|---|
| 18 | |
|---|
| 19 | link = None |
|---|
| 20 | if url.startswith("http://") or url.startswith("https://"): |
|---|
| 21 | link = esc(url) |
|---|
| 22 | |
|---|
| 23 | if link: |
|---|
| 24 | return mark_safe("<a href='%s'>%s</a>" % (link, text, )) |
|---|
| 25 | else: |
|---|
| 26 | return text |
|---|
Note: See
TracBrowser
for help on using the repository browser.