From 969da0543787fa7a7885fc274ba39edcdfd5e0cd Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 20 May 2020 13:47:58 +0200 Subject: [PATCH] admin: show object's docstring on inheritance based lists --- .../templates/administration/policy/list.html | 14 ++++++-- .../administration/property_mapping/list.html | 14 ++++++-- .../administration/provider/list.html | 14 ++++++-- .../templates/administration/source/list.html | 14 ++++++-- .../templates/administration/stage/list.html | 14 ++++++-- passbook/admin/templates/generic/create.html | 10 ++++-- passbook/admin/templates/generic/update.html | 10 ++++-- passbook/admin/views/policies.py | 2 +- passbook/admin/views/property_mapping.py | 2 +- passbook/admin/views/providers.py | 2 +- passbook/admin/views/sources.py | 2 +- passbook/admin/views/stages.py | 2 +- passbook/lib/templatetags/passbook_utils.py | 5 +++ passbook/policies/expiry/models.py | 2 +- .../migrations/0002_auto_20200520_1108.py | 33 +++++++++++++++++++ passbook/sources/oauth/models.py | 24 +++++++++++--- 16 files changed, 140 insertions(+), 24 deletions(-) create mode 100644 passbook/sources/oauth/migrations/0002_auto_20200520_1108.py diff --git a/passbook/admin/templates/administration/policy/list.html b/passbook/admin/templates/administration/policy/list.html index 3c782f597..44dde645a 100644 --- a/passbook/admin/templates/administration/policy/list.html +++ b/passbook/admin/templates/administration/policy/list.html @@ -26,7 +26,12 @@ @@ -92,7 +97,12 @@ {% for type, name in types.items %}
  • {{ name }} + href="{% url 'passbook_admin:policy-create' %}?type={{ type }}&back={{ request.get_full_path }}"> + {{ name|verbose_name }}
    + + {{ trans|doc }} + +
  • {% endfor %} diff --git a/passbook/admin/templates/administration/property_mapping/list.html b/passbook/admin/templates/administration/property_mapping/list.html index 5d117af39..a1d56dc36 100644 --- a/passbook/admin/templates/administration/property_mapping/list.html +++ b/passbook/admin/templates/administration/property_mapping/list.html @@ -28,7 +28,12 @@ {% for type, name in types.items %}
  • {{ name }} + href="{% url 'passbook_admin:property-mapping-create' %}?type={{ type }}&back={{ request.get_full_path }}"> + {{ name|verbose_name }}
    + + {{ trans|doc }} + +
  • {% endfor %} @@ -86,7 +91,12 @@ {% for type, name in types.items %}
  • {{ name }} + href="{% url 'passbook_admin:property-mapping-create' %}?type={{ type }}&back={{ request.get_full_path }}"> + {{ name|verbose_name }}
    + + {{ trans|doc }} + +
  • {% endfor %} diff --git a/passbook/admin/templates/administration/provider/list.html b/passbook/admin/templates/administration/provider/list.html index 0a7fe65fc..cd58442f6 100644 --- a/passbook/admin/templates/administration/provider/list.html +++ b/passbook/admin/templates/administration/provider/list.html @@ -28,7 +28,12 @@ @@ -104,7 +109,12 @@ diff --git a/passbook/admin/templates/administration/source/list.html b/passbook/admin/templates/administration/source/list.html index b50ddab40..571b65a6e 100644 --- a/passbook/admin/templates/administration/source/list.html +++ b/passbook/admin/templates/administration/source/list.html @@ -28,7 +28,12 @@ @@ -98,7 +103,12 @@ diff --git a/passbook/admin/templates/administration/stage/list.html b/passbook/admin/templates/administration/stage/list.html index 2622c8b66..0bf9aa537 100644 --- a/passbook/admin/templates/administration/stage/list.html +++ b/passbook/admin/templates/administration/stage/list.html @@ -28,7 +28,12 @@ @@ -93,7 +98,12 @@ {% for type, name in types.items %}
  • {{ name }} + href="{% url 'passbook_admin:stage-create' %}?type={{ type }}&back={{ request.get_full_path }}"> + {{ name|verbose_name }}
    + + {{ trans|doc }} + +
  • {% endfor %} diff --git a/passbook/admin/templates/generic/create.html b/passbook/admin/templates/generic/create.html index 1358e6ba2..3094c2da7 100644 --- a/passbook/admin/templates/generic/create.html +++ b/passbook/admin/templates/generic/create.html @@ -4,9 +4,15 @@ {% load i18n %} {% block above_form %} -

    {% blocktrans with type=form|form_verbose_name %}Create {{ type }}{% endblocktrans %}

    +

    + {% blocktrans with type=form|form_verbose_name|title %} + Create {{ type }} + {% endblocktrans %} +

    {% endblock %} {% block action %} -{% blocktrans with type=form|form_verbose_name %}Create {{ type }}{% endblocktrans %} +{% blocktrans with type=form|form_verbose_name|title %} +Create {{ type }} +{% endblocktrans %} {% endblock %} diff --git a/passbook/admin/templates/generic/update.html b/passbook/admin/templates/generic/update.html index d52bb8fb4..7c7f57290 100644 --- a/passbook/admin/templates/generic/update.html +++ b/passbook/admin/templates/generic/update.html @@ -4,9 +4,15 @@ {% load i18n %} {% block above_form %} -

    {% blocktrans with type=form|form_verbose_name %}Update {{ type }}{% endblocktrans %}

    +

    + {% blocktrans with type=form|form_verbose_name|title inst=form.instance %} + Update {{ type }}: {{ inst }} + {% endblocktrans %} +

    {% endblock %} {% block action %} -{% blocktrans with type=form|form_verbose_name %}Update {{ type }}{% endblocktrans %} +{% blocktrans with type=form|form_verbose_name|title %} +Update {{ type }} +{% endblocktrans %} {% endblock %} diff --git a/passbook/admin/views/policies.py b/passbook/admin/views/policies.py index 4c1a441c2..9f4678561 100644 --- a/passbook/admin/views/policies.py +++ b/passbook/admin/views/policies.py @@ -30,7 +30,7 @@ class PolicyListView(LoginRequiredMixin, PermissionListMixin, ListView): def get_context_data(self, **kwargs): kwargs["types"] = { - x.__name__: x._meta.verbose_name for x in all_subclasses(Policy) + x.__name__: x for x in all_subclasses(Policy) } return super().get_context_data(**kwargs) diff --git a/passbook/admin/views/property_mapping.py b/passbook/admin/views/property_mapping.py index 1de9bfe04..c1edb5815 100644 --- a/passbook/admin/views/property_mapping.py +++ b/passbook/admin/views/property_mapping.py @@ -27,7 +27,7 @@ class PropertyMappingListView(LoginRequiredMixin, PermissionListMixin, ListView) def get_context_data(self, **kwargs): kwargs["types"] = { - x.__name__: x._meta.verbose_name for x in all_subclasses(PropertyMapping) + x.__name__: x for x in all_subclasses(PropertyMapping) } return super().get_context_data(**kwargs) diff --git a/passbook/admin/views/providers.py b/passbook/admin/views/providers.py index ff1c96ebe..11a287a36 100644 --- a/passbook/admin/views/providers.py +++ b/passbook/admin/views/providers.py @@ -27,7 +27,7 @@ class ProviderListView(LoginRequiredMixin, PermissionListMixin, ListView): def get_context_data(self, **kwargs): kwargs["types"] = { - x.__name__: x._meta.verbose_name for x in all_subclasses(Provider) + x.__name__: x for x in all_subclasses(Provider) } return super().get_context_data(**kwargs) diff --git a/passbook/admin/views/sources.py b/passbook/admin/views/sources.py index 2c979c043..68d908f3a 100644 --- a/passbook/admin/views/sources.py +++ b/passbook/admin/views/sources.py @@ -27,7 +27,7 @@ class SourceListView(LoginRequiredMixin, PermissionListMixin, ListView): def get_context_data(self, **kwargs): kwargs["types"] = { - x.__name__: x._meta.verbose_name for x in all_subclasses(Source) + x.__name__: x for x in all_subclasses(Source) } return super().get_context_data(**kwargs) diff --git a/passbook/admin/views/stages.py b/passbook/admin/views/stages.py index 311923210..103e34afc 100644 --- a/passbook/admin/views/stages.py +++ b/passbook/admin/views/stages.py @@ -27,7 +27,7 @@ class StageListView(LoginRequiredMixin, PermissionListMixin, ListView): def get_context_data(self, **kwargs): kwargs["types"] = { - x.__name__: x._meta.verbose_name for x in all_subclasses(Stage) + x.__name__: x for x in all_subclasses(Stage) } return super().get_context_data(**kwargs) diff --git a/passbook/lib/templatetags/passbook_utils.py b/passbook/lib/templatetags/passbook_utils.py index 9826c54b6..e11ed6ae0 100644 --- a/passbook/lib/templatetags/passbook_utils.py +++ b/passbook/lib/templatetags/passbook_utils.py @@ -100,3 +100,8 @@ def debug(obj) -> str: """Output object to logger""" LOGGER.debug(obj) return "" + +@register.filter +def doc(obj) -> str: + """Return docstring of object""" + return obj.__doc__ diff --git a/passbook/policies/expiry/models.py b/passbook/policies/expiry/models.py index 34565188b..dfba3b4b9 100644 --- a/passbook/policies/expiry/models.py +++ b/passbook/policies/expiry/models.py @@ -13,7 +13,7 @@ LOGGER = get_logger() class PasswordExpiryPolicy(Policy): - """If password change date is more than x days in the past, call set_unusable_password + """If password change date is more than x days in the past, invalidate the user's password and show a notice""" deny_only = models.BooleanField(default=False) diff --git a/passbook/sources/oauth/migrations/0002_auto_20200520_1108.py b/passbook/sources/oauth/migrations/0002_auto_20200520_1108.py new file mode 100644 index 000000000..9a5cce7d3 --- /dev/null +++ b/passbook/sources/oauth/migrations/0002_auto_20200520_1108.py @@ -0,0 +1,33 @@ +# Generated by Django 3.0.6 on 2020-05-20 11:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_sources_oauth', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='oauthsource', + name='access_token_url', + field=models.CharField(help_text='URL used by passbook to retrive tokens.', max_length=255, verbose_name='Access Token URL'), + ), + migrations.AlterField( + model_name='oauthsource', + name='request_token_url', + field=models.CharField(blank=True, help_text='URL used to request the initial token. This URL is only required for OAuth 1.', max_length=255, verbose_name='Request Token URL'), + ), + migrations.AlterField( + model_name='oauthsource', + name='authorization_url', + field=models.CharField(help_text='URL the user is redirect to to conest the flow.', max_length=255, verbose_name='Authorization URL'), + ), + migrations.AlterField( + model_name='oauthsource', + name='profile_url', + field=models.CharField(help_text='URL used by passbook to get user information.', max_length=255, verbose_name='Profile URL'), + ), + ] diff --git a/passbook/sources/oauth/models.py b/passbook/sources/oauth/models.py index 7fe6ba3a3..9097121ed 100644 --- a/passbook/sources/oauth/models.py +++ b/passbook/sources/oauth/models.py @@ -14,15 +14,20 @@ class OAuthSource(Source): provider_type = models.CharField(max_length=255) request_token_url = models.CharField( - blank=True, max_length=255, verbose_name=_("Request Token URL") + blank=True, max_length=255, verbose_name=_("Request Token URL"), + help_text=_("URL used to request the initial token. This URL is only required for OAuth 1.") ) authorization_url = models.CharField( - max_length=255, verbose_name=_("Authorization URL") + max_length=255, verbose_name=_("Authorization URL"), + help_text=_("URL the user is redirect to to conest the flow.") ) access_token_url = models.CharField( - max_length=255, verbose_name=_("Access Token URL") + max_length=255, verbose_name=_("Access Token URL"), + help_text=_("URL used by passbook to retrive tokens.") ) - profile_url = models.CharField(max_length=255, verbose_name=_("Profile URL")) + profile_url = models.CharField( + max_length=255, verbose_name=_("Profile URL"), + help_text=_("URL used by passbook to get user information.")) consumer_key = models.TextField() consumer_secret = models.TextField() @@ -140,6 +145,17 @@ class AzureADOAuthSource(OAuthSource): verbose_name = _("Azure AD OAuth Source") verbose_name_plural = _("Azure AD OAuth Sources") +class OpenIDOAuthSource(OAuthSource): + """Abstract subclass of OAuthSource to specify OpenID Form""" + + form = "passbook.sources.oauth.forms.OAuthSourceForm" + + class Meta: + + abstract = True + verbose_name = _("OpenID OAuth Source") + verbose_name_plural = _("OpenID OAuth Sources") + class UserOAuthSourceConnection(UserSourceConnection): """Authorized remote OAuth provider."""