admin: show object's docstring on inheritance based lists

This commit is contained in:
Jens Langhammer 2020-05-20 13:47:58 +02:00
parent c61c84e9f3
commit 969da05437
16 changed files with 140 additions and 24 deletions

View File

@ -26,7 +26,12 @@
<ul class="pf-c-dropdown__menu" hidden>
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:policy-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:policy-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>
@ -92,7 +97,12 @@
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item"
href="{% url 'passbook_admin:policy-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
href="{% url 'passbook_admin:policy-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>

View File

@ -28,7 +28,12 @@
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item"
href="{% url 'passbook_admin:property-mapping-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
href="{% url 'passbook_admin:property-mapping-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>
@ -86,7 +91,12 @@
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item"
href="{% url 'passbook_admin:property-mapping-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
href="{% url 'passbook_admin:property-mapping-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>

View File

@ -28,7 +28,12 @@
<ul class="pf-c-dropdown__menu" hidden>
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:provider-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:provider-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>
@ -104,7 +109,12 @@
<ul class="pf-c-dropdown__menu" hidden>
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:provider-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:provider-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>

View File

@ -28,7 +28,12 @@
<ul class="pf-c-dropdown__menu" hidden>
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:source-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:source-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>
@ -98,7 +103,12 @@
<ul class="pf-c-dropdown__menu" hidden>
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:source-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:source-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>

View File

@ -28,7 +28,12 @@
<ul class="pf-c-dropdown__menu" hidden>
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:stage-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
<a class="pf-c-dropdown__menu-item" href="{% url 'passbook_admin:stage-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>
@ -93,7 +98,12 @@
{% for type, name in types.items %}
<li>
<a class="pf-c-dropdown__menu-item"
href="{% url 'passbook_admin:stage-create' %}?type={{ type }}&back={{ request.get_full_path }}">{{ name }}</a>
href="{% url 'passbook_admin:stage-create' %}?type={{ type }}&back={{ request.get_full_path }}">
{{ name|verbose_name }}<br>
<small>
{{ trans|doc }}
</small>
</a>
</li>
{% endfor %}
</ul>

View File

@ -4,9 +4,15 @@
{% load i18n %}
{% block above_form %}
<h1>{% blocktrans with type=form|form_verbose_name %}Create {{ type }}{% endblocktrans %}</h1>
<h1>
{% blocktrans with type=form|form_verbose_name|title %}
Create {{ type }}
{% endblocktrans %}
</h1>
{% 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 %}

View File

@ -4,9 +4,15 @@
{% load i18n %}
{% block above_form %}
<h1>{% blocktrans with type=form|form_verbose_name %}Update {{ type }}{% endblocktrans %}</h1>
<h1>
{% blocktrans with type=form|form_verbose_name|title inst=form.instance %}
Update {{ type }}: {{ inst }}
{% endblocktrans %}
</h1>
{% 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 %}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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__

View File

@ -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)

View File

@ -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'),
),
]

View File

@ -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."""