Added support for handling navigation for view with more than one main object class
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
{% load pagination_tags %}
|
||||
{% load navigation_tags %}
|
||||
{% load non_breakable %}
|
||||
{% load variable_tags %}
|
||||
|
||||
{% if side_bar %}
|
||||
<div class="block">
|
||||
@@ -122,13 +123,17 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if not hide_links %}
|
||||
{% if list_object_variable_name %}
|
||||
{% copy_variable object as list_object_variable_name %}
|
||||
{% copy_variable list_object_variable_name as "navigation_object_name" %}
|
||||
{% endif %}
|
||||
<td class="last">
|
||||
{% if navigation_object_links %}
|
||||
{% with navigation_object_links as overrided_object_links %}
|
||||
{% object_navigation_template %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
{% object_navigation_template %}
|
||||
{% object_navigation_template %}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import re
|
||||
|
||||
from django.template import Node, TemplateSyntaxError, Library, Variable
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
class CopyNode(Node):
|
||||
def __init__(self, source_variable, var_name, delete_old=False):
|
||||
self.source_variable = source_variable
|
||||
self.var_name = var_name
|
||||
self.delete_old = delete_old
|
||||
|
||||
def render(self, context):
|
||||
context[Variable(self.var_name).resolve(context)] = Variable(self.source_variable).resolve(context)
|
||||
if self.delete_old:
|
||||
context[Variable(self.source_variable).resolve(context)] = u''
|
||||
return ''
|
||||
|
||||
|
||||
@register.tag
|
||||
def copy_variable(parser, token):
|
||||
return parse_tag(parser, token)
|
||||
|
||||
|
||||
@register.tag
|
||||
def rename_variable(parser, token):
|
||||
return parse_tag(parser, token, {'delete_old': True})
|
||||
|
||||
|
||||
def parse_tag(parser, token, *args, **kwargs):
|
||||
# This version uses a regular expression to parse tag contents.
|
||||
try:
|
||||
# Splitting by None == splitting by spaces.
|
||||
tag_name, arg = token.contents.split(None, 1)
|
||||
except ValueError:
|
||||
raise TemplateSyntaxError('%r tag requires arguments' % token.contents.split()[0])
|
||||
m = re.search(r'(.*?) as ([\'"]*\w+[\'"]*)', arg)
|
||||
if not m:
|
||||
raise TemplateSyntaxError('%r tag had invalid arguments' % tag_name)
|
||||
source_variable, var_name = m.groups()
|
||||
return CopyNode(source_variable, var_name, *args, **kwargs)
|
||||
Reference in New Issue
Block a user