from django.core.urlresolvers import reverse, resolve

import inspect

__all__ = [
    'Breadcrumb', 'BreadcrumbFactory', 'NullBreadcrumb',
    'lazy_reverse', 'lazy_parent'
]

class Breadcrumb(object):
    def __init__(self, application, parent, title, url):
        self.application, self.title, self.url = application, title, url
        self.parent = parent

def BreadcrumbFactory(breadcrumb_func):
    def data(self, request, context, *args, **kwargs):
        return breadcrumb_func(self, request, context, *args, **kwargs)
    
    def render(self, request, context, *args, **kwargs):
        breadcrumb = data(self, request, context, *args, **kwargs)
        
        if breadcrumb.parent:
            parent_data = breadcrumb.parent(self, breadcrumb.application, request, context)
            parent = parent_data.title, parent_data.url(parent_data.application)
        else:
            parent = None
        
        index_view = resolve(reverse('%s:index' % breadcrumb.application))[0]
        index = index_view.breadcrumb.data(index_view, request, context)
        index = index.title, index.url(breadcrumb.application)
        
        parent_is_index = index == parent
        
        return (
            breadcrumb.application,
            index,
            parent,
            parent_is_index,
            breadcrumb.title,
        )
        
    render.data = data
    render.breadcrumb_func = breadcrumb_func

    return render

@staticmethod
def NullBreadcrumb(request, context, *args, **kwargs):
    return None

def lazy_reverse(view_name, *args, **kwargs):
    def f(application_name):
        view = view_name
        if ':' not in view:
            view = '%s:%s' % (application_name, view)
        return reverse(view, *args, **kwargs)
    return f
    
def static_reverse(path):
    def f():
        return path
    return f
    
def lazy_parent(view_name, *args, **kwargs):
    def f(self, application_name, request, context):
        view = view_name
        if ':' not in view:
            view = '%s:%s' % (application_name, view)
        view, view_args, view_kwargs = resolve(reverse(view, args=args, kwargs=kwargs))
        return view.breadcrumb.data(view, request, context, *view_args, **view_kwargs)
    return f

def static_parent(path, title, application=None):
    def f(self, app, request, context):
        return Breadcrumb(
            application, None, title, lambda app: path
        )
    return f
    

@@ -1,8 +1,59 @@
+from collections import namedtuple%0Aimport inspect%0A%0A
 from dja
@@ -99,32 +99,16 @@
 esolve%0A%0A
-import inspect%0A%0A
 __all__ 
@@ -167,20 +167,65 @@
 dcrumb',
-%0A   
+ 'RenderedBreadcrumb',%0A    'RenderedBreadcrumbs',
  'lazy_r
@@ -436,16 +436,325 @@
 parent%0A%0A
+RenderedBreadcrumbs = namedtuple('RenderedBreadcrumbs',%0A                                %5B'application', 'index', 'parent',%0A                                 'parent_is_index', 'page_title'%5D)%0A%0ARenderedBreadcrumb = namedtuple('RenderedBreadcrumb',%0A                                %5B'title', 'url', 'view_name'%5D)%0A%0A
 def Brea
@@ -1186,24 +1186,28 @@
       parent
+_url
  = parent_da
@@ -1213,27 +1213,8 @@
 ata.
-title, parent_data.
 url(
@@ -1228,32 +1228,275 @@
 data.application
+)%0A            resolved_parent = resolve(parent_url)%0A            parent = RenderedBreadcrumb(%0A                parent_data.title, parent_url,%0A                '%25s:%25s' %25 (':'.join(resolved_parent.namespaces), resolved_parent.url_name)%0A            
 )%0A        else:%0A
@@ -1538,26 +1538,30 @@
         
+resolved_
 index
-_view
  = resol
@@ -1612,11 +1612,8 @@
 on))
-%5B0%5D
 %0A   
@@ -1629,45 +1629,63 @@
 x = 
-index_view.breadcrumb.data(index_view
+resolved_index.func.breadcrumb.data(resolved_index.func
 , re
@@ -1711,24 +1711,56 @@
      index =
+ RenderedBreadcrumb(%0A           
  index.title
@@ -1786,32 +1786,128 @@
 umb.application)
+,%0A            '%25s:%25s' %25 (':'.join(resolved_index.namespaces), resolved_index.url_name)%0A        )
 %0A        %0A      
@@ -1966,16 +1966,35 @@
  return 
+RenderedBreadcrumbs
 (%0A      

Change breadcrumbs API to include view_names in individual breadcrumbs, also use namedtuples to retain backwards compatibility, but give more flexibility in future