diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-31 16:03:12 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-31 16:03:38 +0200 |
commit | 88546436f8eeea52461456f5f46736900f652a93 (patch) | |
tree | 9a058ead8859b9229c6e44f1d17385477903c571 | |
parent | 9f4fb05ea2650936a3c913205ad073a385cd9260 (diff) | |
download | Ishtar-88546436f8eeea52461456f5f46736900f652a93.tar.bz2 Ishtar-88546436f8eeea52461456f5f46736900f652a93.zip |
Admin: profile type summary page
-rw-r--r-- | ishtar_common/admin.py | 48 | ||||
-rw-r--r-- | ishtar_common/models.py | 7 | ||||
-rw-r--r-- | ishtar_common/templates/admin/profiletype_summary_change_list.html | 42 |
3 files changed, 96 insertions, 1 deletions
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'<img src="{}admin/img/icon-yes.svg" alt="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 %} + <h1>{% trans "Profile type Summary" %}</h1> +{% endblock %} + +{% block result_list %} + +<div class="results"> + <table> + {% for group in groups %} + {% if forloop.counter0|divisibleby:10 %} + <tr> + <td> + </td> + {% for profile_type in profile_types %} + <th> + <div class="text"> + <a href="/admin/ishtar_common/profiletype/{{profile_type.pk}}/change/"> + {{ profile_type.name }} + </a> + </div> + </th> + {% endfor %} + </tr> + {% endif %} + + <tr class="{% cycle 'row1' 'row2' %}"> + {% for col in group %} + {% if forloop.first %}<th><div class="text">{% else %}<td>{% endif%} + {{col}} + {% if forloop.first %}</div></th>{% else %}</td>{% endif%} + {% endfor %} + </tr> + {% endfor %} + </table> +</div> + + +{% endblock %} + +{% block pagination %}{% endblock %}
\ No newline at end of file |