Commits

Sławek Ehlert committed aaf765a

some work on templatetag and some README clarifications

  • Participants
  • Parent commits c5dae22

Comments (0)

Files changed (5)

 
 An app for generic breadcrumbs in Django. More info soon (I hope).
 
+The idea is to make breadcrumbs out of parts of an url path. This application assumes that your url patterns are in a REST style.
+
+i.e. ::
+
+    /                                               # root path
+    /application/                                   # root of an app/module
+    /application/object_type/                       # list of specific objects
+    /application/object_type/some_object/           # details of specific object
+    /application/object_type/some_object/edit/      # edit (or any other operations) of a specific object
+
 See ``testproject`` for sample usage.
 
 For now this is developed only against Django 1.4 (I don't know whether is it working or not with the older versions)

File testproject/testproject/settings.py

 
 TEMPLATE_CONTEXT_PROCESSORS = \
     global_settings.TEMPLATE_CONTEXT_PROCESSORS + \
-    ('urlbreadcrumbs.context_processors.build_breadcrumbs',)
+    (
+     'django.core.context_processors.request', # for ``render_breadcrumbs`` templatetag
+     'urlbreadcrumbs.context_processors.build_breadcrumbs',
+    )
 
 INSTALLED_APPS = (
     'urlbreadcrumbs',

File testproject/testproject/templates/base.html

     <h1>This is a urlbreadcrumbs test page</h1>
 
     <h2>
-        MENU
+        MENU (click on element and see how breadrumbs change)
     </h2>
     <ul>
 
     <h2>
     BREADCRUMBS
     </h2>
+    <h3> by template inclusion </h3>
+        {% include "urlbreadcrumbs/default.html" %}
+    <hr/>
         
-        {% include "urlbreadcrumbs/default.html" %}
-    <hr>
+    <h3> by templatetag </h3>
+    <h4> default </h4>
+        {% load urlbreadcrumbs_tags %}
+        {% render_breadcrumbs %}
+        
+    <h4> twitter bootstrap (no CSS) </h4>
+        {% render_breadcrumbs "urlbreadcrumbs/twitter-bootstrap.html" %}
+    <hr/>
 
     <h2>
     CONTENT

File urlbreadcrumbs/templatetags/__init__.py

Empty file added.

File urlbreadcrumbs/templatetags/urlbreadcrumbs_tags.py

+from django import template
+from django.core.exceptions import ImproperlyConfigured
+from urlbreadcrumbs.context_processors import build_breadcrumbs
+
+register = template.Library()
+
+
+@register.simple_tag(name="render_breadcrumbs", takes_context=True)
+def render_breadcrumbs(context, template_name = "urlbreadcrumbs/default.html"):
+    request = context.get('request', None)
+    if request is None:
+        raise ImproperlyConfigured("You have to provide a request object in context")
+
+    c_vars = build_breadcrumbs(request)
+    t = template.loader.get_template(template_name)
+    context.update(c_vars)
+    return t.render(context)
+
+