from django import template
from django.contrib.flatpages.models import FlatPage
register = template.Library()
def crumbs(url, title):
"Return breadcrumb trail leading to URL for this page"
t = title
s = ' > '
c = 'Home'
l = url.split('/')
for index, item in enumerate(l):
if item == '':
del l[index]
n = len(l)
if n > 1:
l[0] = '/' + l[0] + '/'
for i in range(1, n-1):
l[i] = l[i-1] + l[i] + '/'
for index2, item2 in enumerate(l):
q = FlatPage.objects.filter(url=l[index2])
if q:
qa = '%s' % (q[0].url, q[0].title)
c = c + s + qa
c = c + s + t
return c
register.filter('crumbs', crumbs)