|
|
|
@ -7,6 +7,7 @@ from mptt.templatetags.mptt_tags import recursetree |
|
|
|
|
|
|
|
|
|
|
|
register = template.Library() |
|
|
|
register = template.Library() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@register.tag |
|
|
|
@register.tag |
|
|
|
def breadcrumb(parser, token): |
|
|
|
def breadcrumb(parser, token): |
|
|
|
""" |
|
|
|
""" |
|
|
|
@ -40,7 +41,7 @@ def breadcrumb_url(parser, token): |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
bits = token.split_contents() |
|
|
|
bits = token.split_contents() |
|
|
|
if len(bits)==2: |
|
|
|
if len(bits) == 2: |
|
|
|
return breadcrumb(parser, token) |
|
|
|
return breadcrumb(parser, token) |
|
|
|
|
|
|
|
|
|
|
|
# Extract our extra title parameter |
|
|
|
# Extract our extra title parameter |
|
|
|
@ -51,20 +52,22 @@ def breadcrumb_url(parser, token): |
|
|
|
|
|
|
|
|
|
|
|
return UrlBreadcrumbNode(title, url_node) |
|
|
|
return UrlBreadcrumbNode(title, url_node) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def breadcrumb_mptt_url(parser, token): |
|
|
|
def breadcrumb_mptt_url(parser, token): |
|
|
|
return recursetree(parser, token) |
|
|
|
return recursetree(parser, token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BreadcrumbNode(Node): |
|
|
|
class BreadcrumbNode(Node): |
|
|
|
def __init__(self, vars): |
|
|
|
def __init__(self, vars): |
|
|
|
""" |
|
|
|
""" |
|
|
|
First var is title, second var is url context variable |
|
|
|
First var is title, second var is url context variable |
|
|
|
""" |
|
|
|
""" |
|
|
|
self.vars = map(Variable,vars) |
|
|
|
self.vars = map(Variable, vars) |
|
|
|
|
|
|
|
|
|
|
|
def render(self, context): |
|
|
|
def render(self, context): |
|
|
|
title = self.vars[0].var |
|
|
|
title = self.vars[0].var |
|
|
|
|
|
|
|
|
|
|
|
if title.find("'")==-1 and title.find('"')==-1: |
|
|
|
if title.find("'") == -1 and title.find('"') == -1: |
|
|
|
try: |
|
|
|
try: |
|
|
|
val = self.vars[0] |
|
|
|
val = self.vars[0] |
|
|
|
title = val.resolve(context) |
|
|
|
title = val.resolve(context) |
|
|
|
@ -72,12 +75,12 @@ class BreadcrumbNode(Node): |
|
|
|
title = '' |
|
|
|
title = '' |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
title=title.strip("'").strip('"') |
|
|
|
title = title.strip("'").strip('"') |
|
|
|
title=smart_bytes(title) |
|
|
|
title = smart_bytes(title) |
|
|
|
|
|
|
|
|
|
|
|
url = None |
|
|
|
url = None |
|
|
|
|
|
|
|
|
|
|
|
if len(self.vars)>1: |
|
|
|
if len(self.vars) > 1: |
|
|
|
val = self.vars[1] |
|
|
|
val = self.vars[1] |
|
|
|
try: |
|
|
|
try: |
|
|
|
url = val.resolve(context) |
|
|
|
url = val.resolve(context) |
|
|
|
@ -96,15 +99,14 @@ class UrlBreadcrumbNode(Node): |
|
|
|
def render(self, context): |
|
|
|
def render(self, context): |
|
|
|
title = self.title.var |
|
|
|
title = self.title.var |
|
|
|
|
|
|
|
|
|
|
|
if title.find("'")==-1 and title.find('"')==-1: |
|
|
|
if title.find("'") == -1 and title.find('"') == -1: |
|
|
|
try: |
|
|
|
try: |
|
|
|
val = self.title |
|
|
|
val = self.title |
|
|
|
title = val.resolve(context) |
|
|
|
title = val.resolve(context) |
|
|
|
except: |
|
|
|
except: |
|
|
|
title = '' |
|
|
|
title = '' |
|
|
|
else: |
|
|
|
else: |
|
|
|
title=title.strip("'").strip('"') |
|
|
|
title = title.strip("'").strip('"') |
|
|
|
title=smart_bytes(title) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
url = self.url_node.render(context) |
|
|
|
url = self.url_node.render(context) |
|
|
|
return create_crumb(title, url) |
|
|
|
return create_crumb(title, url) |
|
|
|
@ -114,7 +116,7 @@ def create_crumb(title, url=None): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Helper function |
|
|
|
Helper function |
|
|
|
""" |
|
|
|
""" |
|
|
|
crumb = """<li><a href='%s'>%s</a></span>""" |
|
|
|
crumb = """<li><a href='{}'>{}</a></span>""" |
|
|
|
if url: |
|
|
|
if url: |
|
|
|
crumb = crumb.format(url, title) |
|
|
|
crumb = crumb.format(url, title) |
|
|
|
else: |
|
|
|
else: |
|
|
|
|