-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplatefilters.py
38 lines (29 loc) · 997 Bytes
/
templatefilters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python2.5
#
"""
Django template filters for CallTrends.
"""
__author__ = 'wferrell@ (Bill Ferrell)'
import time
import urllib
from google.appengine.api import datastore
from google.appengine.api import datastore_errors
from google.appengine.api import users
from google.appengine.ext.webapp import template
def hide_referer(url):
"""Modifies the given URL to redirect through Google to hide referers."""
return 'http://www.google.com/url?sa=D&q=' + urllib.quote(url)
def item(array, index):
"""Returns the item with the given index in the given array."""
return array[index]
def islist(value):
"""Returns true if the given value is a list.
Useful when you store lists in the Prometheus datastore since lists of
length 1 are incorrectly returned as strings.
"""
return isinstance(value, list)
# Register the filter functions with Django
register = template.create_template_register()
register.filter(hide_referer)
register.filter(item)
register.filter(islist)