Skip to content

Instantly share code, notes, and snippets.

@erickgnavar
Created December 14, 2012 04:57
Show Gist options
  • Save erickgnavar/4282781 to your computer and use it in GitHub Desktop.
Save erickgnavar/4282781 to your computer and use it in GitHub Desktop.
Common tags
from django import template
register = template.Library()
@register.filter
def to_range(value):
return range(1, value + 1)
class Path(object):
def __init__(self, name, url):
self.name = name
self.url = url
@register.filter
def path_to_list(path):
if '?' in path:
path = path.split('?')[0]
urls = []
path = path.split('/')
n = len(path)
for i in range(n):
if not path[i] == '':
url = Path(name=path[i], url='/'.join(path[:i + 1]))
urls.append(url)
return urls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment