Add get_object_list_object_name tag to override the object to process from an object_list

This commit is contained in:
Roberto Rosario
2012-04-11 03:11:08 -04:00
parent a7b7195370
commit c8129b1f5f
2 changed files with 27 additions and 8 deletions

View File

@@ -6,6 +6,7 @@
{% load variable_tags %}
{% load main_settings_tags %}
{% load multiselect_tags %}
{% load subtemplates_tags %}
{% get_main_setting "DISABLE_ICONS" as disable_icons %}
@@ -76,7 +77,9 @@
<th>{{ column.name|capfirst }}</th>
{% endfor %}
{% for column in object_list.0|get_model_list_columns %}
{% get_object_list_object_name object_list.0 %}
{% for column in object|get_model_list_columns %}
<th>{{ column.name|capfirst }}</th>
{% endfor %}
@@ -89,15 +92,17 @@
{% endif %}
</tr>
{% endif %}
{% for object in object_list %}
{% get_object_list_object_name object %}
<tr class="{% cycle 'odd' 'even2' %}">
{% if multi_select or multi_select_as_buttons %}
<td>
{% if multi_select_item_properties %}
<input type="checkbox" class="checkbox" name="properties_{{ object|get_encoded_parameter:multi_select_item_properties }}" value="" />
{% else %}
<input type="checkbox" class="checkbox" name="pk_{{ object.pk }}" value="" />
{% endif %}
{% if multi_select_item_properties %}
<input type="checkbox" class="checkbox" name="properties_{{ object|get_encoded_parameter:multi_select_item_properties }}" value="" />
{% else %}
<input type="checkbox" class="checkbox" name="pk_{{ object.pk }}" value="" />
{% endif %}
</td>
{% endif %}
{% if not hide_object %}

View File

@@ -1,9 +1,11 @@
import re
from django.template import Node, TemplateSyntaxError, Library, \
Variable, Context
from django.template import (Node, TemplateSyntaxError, Library,
Variable, Context)
from django.template.loader import get_template
from common.utils import return_attrib
register = Library()
@@ -49,3 +51,15 @@ def render_subtemplate(parser, token):
return RenderSubtemplateNode(template_name, template_context, var_name)
#format_string[1:-1]
@register.simple_tag(takes_context=True)
def get_object_list_object_name(context, source_object):
object_list_object_name = context.get('object_list_object_name')
if object_list_object_name:
context['object'] = return_attrib(source_object, object_list_object_name)
else:
context['object'] = source_object
return ''