From 2db1738e4a958af48d8bf8fc71319a052a5c35d1 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 27 Feb 2019 14:47:11 +0100 Subject: [PATCH] make Admin UI more consistent, better show when provider has no application assigned --- .../templates/administration/application/list.html | 4 +++- .../templates/administration/factor/list.html | 2 +- .../templates/administration/policy/list.html | 4 ++-- .../templates/administration/provider/list.html | 14 +++++++++++--- passbook/admin/views/applications.py | 1 + passbook/core/models.py | 4 ++++ passbook/lib/templatetags/utils.py | 5 +++++ passbook/saml_idp/models.py | 6 +++--- 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/passbook/admin/templates/administration/application/list.html b/passbook/admin/templates/administration/application/list.html index 7a5df9bd2..20be356fb 100644 --- a/passbook/admin/templates/administration/application/list.html +++ b/passbook/admin/templates/administration/application/list.html @@ -21,6 +21,7 @@ {% trans 'Name' %} {% trans 'Provider' %} + {% trans 'Provider Type' %} @@ -28,7 +29,8 @@ {% for application in object_list %} {{ application.name }} - {{ application.provider }} + {{ application.get_provider }} + {{ application.get_provider|verbose_name }} {% trans 'Edit' %} diff --git a/passbook/admin/templates/administration/factor/list.html b/passbook/admin/templates/administration/factor/list.html index 68e78c148..9b73498da 100644 --- a/passbook/admin/templates/administration/factor/list.html +++ b/passbook/admin/templates/administration/factor/list.html @@ -40,7 +40,7 @@ {% for factor in object_list %} {{ factor.name }} ({{ factor.slug }}) - {{ factor.type }} + {{ factor|verbose_name }} {{ factor.order }} {{ factor.enabled }} diff --git a/passbook/admin/templates/administration/policy/list.html b/passbook/admin/templates/administration/policy/list.html index 342e92b57..ed41d1512 100644 --- a/passbook/admin/templates/administration/policy/list.html +++ b/passbook/admin/templates/administration/policy/list.html @@ -29,7 +29,7 @@ {% trans 'Name' %} - {% trans 'Class' %} + {% trans 'Type' %} @@ -37,7 +37,7 @@ {% for policy in object_list %} {{ policy.name }} - {{ policy|fieldtype }} + {{ policy|verbose_name }} {% trans 'Edit' %} diff --git a/passbook/admin/templates/administration/provider/list.html b/passbook/admin/templates/administration/provider/list.html index c47311612..43e84e7ba 100644 --- a/passbook/admin/templates/administration/provider/list.html +++ b/passbook/admin/templates/administration/provider/list.html @@ -29,16 +29,24 @@ + - + {% for provider in object_list %} - + + - +
{% trans 'Name' %}{% trans 'Class' %}{% trans 'Type' %}
+ {% if not provider.application %} + + {% else %} + + {% endif %} + {{ provider.name }}{{ provider|fieldtype }}{{ provider|verbose_name }} {% trans 'Edit' %} diff --git a/passbook/admin/views/applications.py b/passbook/admin/views/applications.py index b6ba4ed4c..bf9b5eb37 100644 --- a/passbook/admin/views/applications.py +++ b/passbook/admin/views/applications.py @@ -14,6 +14,7 @@ class ApplicationListView(AdminRequiredMixin, ListView): """Show list of all applications""" model = Application + ordering = 'name' template_name = 'administration/application/list.html' def get_queryset(self): diff --git a/passbook/core/models.py b/passbook/core/models.py index db6c6816e..a8bf4b5e9 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -161,6 +161,10 @@ class Application(PolicyModel): from passbook.core.policies import PolicyEngine return PolicyEngine(self.policies.all()).for_user(user).result + def get_provider(self): + """Get casted provider instance""" + return Provider.objects.get_subclass(pk=self.provider.pk) + def __str__(self): return self.name diff --git a/passbook/lib/templatetags/utils.py b/passbook/lib/templatetags/utils.py index df2c89311..1ed90740e 100644 --- a/passbook/lib/templatetags/utils.py +++ b/passbook/lib/templatetags/utils.py @@ -207,3 +207,8 @@ def gravatar(email, size=None, rating=None): gravatar_url += '?' + urlencode(parameters, doseq=True) return escape(gravatar_url) + +@register.filter +def verbose_name(obj): + """Return Object's Verbose Name""" + return obj._meta.verbose_name diff --git a/passbook/saml_idp/models.py b/passbook/saml_idp/models.py index 18ba9ccf3..55313e081 100644 --- a/passbook/saml_idp/models.py +++ b/passbook/saml_idp/models.py @@ -40,12 +40,12 @@ class SAMLProvider(Provider): def link_download_metadata(self): """Get link to download XML metadata for admin interface""" - # pylint: disable=no-member - if self.application: + try: # pylint: disable=no-member return reverse('passbook_saml_idp:metadata_xml', kwargs={'application': self.application.slug}) - return None + except Provider.application.RelatedObjectDoesNotExist: + return None class Meta: