3 from django
.utils
.safestring
import mark_safe
4 from django
import template
5 from django
.utils
.safestring
import mark_safe
7 from mygpo
.web
.utils
import get_page_list
, license_info
, hours_to_str
8 from mygpo
.utils
import edit_link
11 register
= template
.Library()
16 return dic
.get(key
, "")
20 def lookup_list(dict, keys
):
27 def smartwidthratio(val
, min_val
, max_val
, upper
, lower
):
30 return max(lower
, (float(val
- min_val
) / max_val
* upper
))
34 def page_list(cur
, start
, total
, show_max
):
35 return get_page_list(start
, total
, cur
, show_max
)
40 return [key
for key
, val
in dic
.items() if val
]
50 return [x
for x
in l
if x
!= item
]
54 def format_time(time
):
55 from mygpo
.utils
import format_time
as _format_time
57 return mark_safe(_format_time(time
))
62 return isinstance(obj
, tuple)
69 return mark_safe(markdown2
.markdown(txt
, extras
={"nofollow": True}))
74 """collapses multiple whitespaces and replaces them with """
77 return mark_safe(re
.sub(r
"\s+", " ", s
))
81 def license_name(license_url
):
82 """returns a "pretty" license name for a license URL"""
84 info
= license_info(license_url
)
87 return "%s %s" % (info
.name
, info
.version
or "")
94 """makes urllib.quote_plus available as a template filter"""
95 if isinstance(s
, str):
97 return mark_safe(urllib
.parse
.quote_plus(s
))
100 hours_to_str
= register
.filter(hours_to_str
)
104 def protocol(request
):
105 return "http{s}://".format(s
="s" if request
.is_secure() else "")
108 edit_link
= register
.simple_tag(edit_link
)