summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/admin.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index 48847b804..fd0efd455 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -41,6 +41,7 @@ from django.forms import BaseInlineFormSet
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render
from django.utils.decorators import method_decorator
+from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_protect
@@ -75,6 +76,25 @@ class ImportGenericForm(forms.Form):
)
+def change_value(attribute, value, description):
+ """
+ Action to change a specific value in a list
+ """
+ def _change_value(modeladmin, request, queryset):
+ for obj in queryset.order_by('pk'):
+ setattr(obj, attribute, value)
+ obj.save()
+ url = reverse(
+ 'admin:%s_%s_changelist' % (
+ modeladmin.model._meta.app_label,
+ modeladmin.model._meta.model_name)
+ )
+ return HttpResponseRedirect(url)
+ _change_value.short_description = description
+ _change_value.__name__ = str(slugify(description))
+ return _change_value
+
+
def export_as_csv_action(description=_(u"Export selected as CSV file"),
fields=None, exclude=None, header=True):
"""
@@ -815,6 +835,10 @@ class JsonDataFieldForm(JsonContentTypeFormMixin, forms.ModelForm):
class JsonDataFieldAdmin(admin.ModelAdmin):
list_display = ['name', 'content_type', 'key', 'display',
'order', 'section']
+ actions = [
+ change_value('display', True, _(u"Display selected")),
+ change_value('display', False, _(u"Hide selected"))
+ ]
form = JsonDataFieldForm