From 483aec19a29c69f544e27b6fb60966ca48b4f016 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 31 Aug 2018 16:03:12 +0200 Subject: Admin: profile type summary page --- ishtar_common/admin.py | 48 +++++++++++++++++++++- ishtar_common/models.py | 7 ++++ .../admin/profiletype_summary_change_list.html | 42 +++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 ishtar_common/templates/admin/profiletype_summary_change_list.html (limited to 'ishtar_common') diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index ab96dee8a..d1504069a 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -41,7 +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.text import slugify, mark_safe from django.utils.translation import ugettext_lazy as _ from django.views.decorators.csrf import csrf_protect @@ -499,6 +499,52 @@ class ProfileTypeAdmin(GeneralTypeAdmin): admin_site.register(models.ProfileType, ProfileTypeAdmin) +class ProfileTypeSummaryAdmin(admin.ModelAdmin): + change_list_template = 'admin/profiletype_summary_change_list.html' + search_fields = ('label',) + list_filter = ('available', 'label') + + def has_add_permission(self, request, obj=None): + return False + + def changelist_view(self, request, extra_context=None): + response = super(ProfileTypeSummaryAdmin, self).changelist_view( + request, + extra_context=extra_context, + ) + + try: + qs = response.context_data["cl"].queryset + except (AttributeError, KeyError): + return response + + profile_types = list( + qs.order_by("label") + ) + rights = {} + for profile_type in profile_types: + rights[profile_type.pk] = [g.pk for g in profile_type.groups.all()] + groups = [] + ok = mark_safe( + u'True'.format( + settings.STATIC_URL + )) + for group in models.Group.objects.order_by("name"): + gp = [group.name] + for profile_type in profile_types: + gp.append( + ok if group.pk in rights[profile_type.pk] + else "-") + groups.append(gp) + + response.context_data.update({"profile_types": profile_types, + "groups": groups}) + return response + + +admin_site.register(models.ProfileTypeSummary, ProfileTypeSummaryAdmin) + + class ImporterDefaultValuesInline(admin.TabularInline): model = models.ImporterDefaultValues diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 8096bf6ba..4f1168d39 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2998,6 +2998,13 @@ post_save.connect(post_save_cache, sender=ProfileType) post_delete.connect(post_save_cache, sender=ProfileType) +class ProfileTypeSummary(ProfileType): + class Meta: + proxy = True + verbose_name = _(u"Profile type summary") + verbose_name_plural = _(u"Profile types summary") + + class UserProfile(models.Model): name = models.CharField(_(u"Name"), blank=True, default=u"", max_length=100) profile_type = models.ForeignKey( diff --git a/ishtar_common/templates/admin/profiletype_summary_change_list.html b/ishtar_common/templates/admin/profiletype_summary_change_list.html new file mode 100644 index 000000000..f071545cc --- /dev/null +++ b/ishtar_common/templates/admin/profiletype_summary_change_list.html @@ -0,0 +1,42 @@ +{% extends "admin/change_list.html" %}{% load i18n %} + +{% block content_title %} +

{% trans "Profile type Summary" %}

+{% endblock %} + +{% block result_list %} + +
+ + {% for group in groups %} + {% if forloop.counter0|divisibleby:10 %} + + + {% for profile_type in profile_types %} + + {% endfor %} + + {% endif %} + + + {% for col in group %} + {% if forloop.first %}{% endif%} + {% endfor %} + + {% endfor %} +
+ + +
{% else %}
{% endif%} + {{col}} + {% if forloop.first %}{% else %}
+
+ + +{% endblock %} + +{% block pagination %}{% endblock %} \ No newline at end of file -- cgit v1.2.3