Created
December 14, 2012 04:57
-
-
Save erickgnavar/4282781 to your computer and use it in GitHub Desktop.
Common tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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