Added a new more comprehensive method of passing multiple variables per item in multi item selection views
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
{% load non_breakable %}
|
||||
{% load variable_tags %}
|
||||
{% load main_settings_tags %}
|
||||
{% load multiselect_tags %}
|
||||
|
||||
{% get_main_setting "DISABLE_ICONS" as disable_icons %}
|
||||
|
||||
@@ -91,7 +92,13 @@
|
||||
{% for object in object_list %}
|
||||
<tr class="{% cycle 'odd' 'even2' %}">
|
||||
{% if multi_select or multi_select_as_buttons %}
|
||||
<td><input type="checkbox" class="checkbox" name="pk_{{ object.pk }}" value="" /></td>
|
||||
<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 %}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% if not hide_object %}
|
||||
{% if main_object %}
|
||||
|
||||
14
apps/common/templatetags/multiselect_tags.py
Normal file
14
apps/common/templatetags/multiselect_tags.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.template import Library
|
||||
from django.utils.simplejson import dumps
|
||||
|
||||
from common.utils import return_attrib
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_encoded_parameter(item, parameters_dict):
|
||||
result = {}
|
||||
for attrib_name, attrib in parameters_dict.items():
|
||||
result[attrib_name] = return_attrib(item, attrib)
|
||||
return dumps(result)
|
||||
@@ -8,6 +8,7 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.http import urlencode
|
||||
from django.contrib.auth.views import login
|
||||
from django.utils.simplejson import dumps, loads
|
||||
|
||||
from common.forms import ChoiceForm, UserForm, UserForm_view, \
|
||||
ChangelogForm, LicenseForm
|
||||
@@ -34,19 +35,28 @@ def multi_object_action_view(request):
|
||||
|
||||
action = request.GET.get('action', None)
|
||||
id_list = u','.join([key[3:] for key in request.GET.keys() if key.startswith('pk_')])
|
||||
items_property_list = [loads(key[11:]) for key in request.GET.keys() if key.startswith('properties_')]
|
||||
|
||||
if not action:
|
||||
messages.error(request, _(u'No action selected.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
if not id_list:
|
||||
if not id_list and not items_property_list:
|
||||
messages.error(request, _(u'Must select at least one item.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
return HttpResponseRedirect('%s?%s' % (
|
||||
action,
|
||||
urlencode({'id_list': id_list, 'next': next}))
|
||||
)
|
||||
# Separate redirects to keep backwards compatibility with older
|
||||
# functions that don't expect a properties_list parameter
|
||||
if items_property_list:
|
||||
return HttpResponseRedirect('%s?%s' % (
|
||||
action,
|
||||
urlencode({'items_property_list': dumps(items_property_list), 'next': next}))
|
||||
)
|
||||
else:
|
||||
return HttpResponseRedirect('%s?%s' % (
|
||||
action,
|
||||
urlencode({'id_list': id_list, 'next': next}))
|
||||
)
|
||||
|
||||
|
||||
def get_obj_from_content_type_string(string):
|
||||
|
||||
Reference in New Issue
Block a user