Added support for per-view side bar templates
This commit is contained in:
@@ -143,7 +143,7 @@
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% get_object_navigation_links as object_navigation_links %}
|
||||
{% if object_navigation_links %}
|
||||
<div class="block">
|
||||
@@ -176,6 +176,13 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% get_sidebar_templates as sidebar_templates %}
|
||||
{% for template in sidebar_templates %}
|
||||
{% with "true" as side_bar %}
|
||||
{% include template %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
|
||||
{% block sidebar %}{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ object_navigation = {}
|
||||
multi_object_navigation = {}
|
||||
menu_links = []
|
||||
model_list_columns = {}
|
||||
sidebar_templates = {}
|
||||
|
||||
|
||||
def register_multi_item_links(src, links, menu_name=None):
|
||||
@@ -62,3 +63,11 @@ def register_model_list_columns(model, columns):
|
||||
model_list_columns[model].extend(columns)
|
||||
else:
|
||||
model_list_columns[model] = copy.copy(columns)
|
||||
|
||||
|
||||
def register_sidebar_template(source_list, template_name):
|
||||
for source in source_list:
|
||||
if source in sidebar_templates:
|
||||
sidebar_templates[source].append(template_name)
|
||||
else:
|
||||
sidebar_templates[source] = [template_name]
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.utils.text import unescape_string_literal
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from navigation.api import object_navigation, multi_object_navigation, \
|
||||
menu_links as menu_navigation
|
||||
menu_links as menu_navigation, sidebar_templates
|
||||
from navigation.forms import MultiItemForm
|
||||
from navigation.utils import resolve_to_name
|
||||
|
||||
@@ -222,3 +222,26 @@ def get_multi_item_links_form(context):
|
||||
'submit_method': 'get',
|
||||
})
|
||||
return new_context
|
||||
|
||||
|
||||
class GetSidebarTemplatesNone(Node):
|
||||
def __init__(self, var_name='sidebar_templates'):
|
||||
self.var_name = var_name
|
||||
|
||||
def render(self, context):
|
||||
request = Variable('request').resolve(context)
|
||||
view_name = resolve_to_name(request.META['PATH_INFO'])
|
||||
context[self.var_name] = sidebar_templates.get(view_name, [])
|
||||
return ''
|
||||
|
||||
|
||||
@register.tag
|
||||
def get_sidebar_templates(parser, token):
|
||||
tag_name, arg = token.contents.split(None, 1)
|
||||
|
||||
m = re.search(r'("?\w+"?)?.?as (\w+)', arg)
|
||||
if not m:
|
||||
raise TemplateSyntaxError("%r tag had invalid arguments" % tag_name)
|
||||
|
||||
menu_name, var_name = m.groups()
|
||||
return GetSidebarTemplatesNone(var_name=var_name)
|
||||
|
||||
Reference in New Issue
Block a user