Only use one create template, get title from Form's Model

This commit is contained in:
Jens Langhammer 2019-02-27 16:06:20 +01:00
parent 5584f5bda8
commit d7c4697625
10 changed files with 36 additions and 21 deletions

View File

@ -1,11 +1,12 @@
{% extends "generic/form.html" %}
{% load utils %}
{% load i18n %}
{% block above_form %}
<h1>{% blocktrans with type=type %}Create {{ type }}{% endblocktrans %}</h1>
<h1>{% blocktrans with type=form|form_verbose_name %}Create {{ type }}{% endblocktrans %}</h1>
{% endblock %}
{% block action %}
{% blocktrans with type=type %}Create {{ type }}{% endblocktrans %}
{% blocktrans with type=form|form_verbose_name %}Create {{ type }}{% endblocktrans %}
{% endblock %}

View File

@ -1,11 +0,0 @@
{% extends "generic/create.html" %}
{% load i18n %}
{% block title %}
{% blocktrans with type=request.GET.type %}Create {{ type }}{% endblocktrans %}
{% endblock %}
{% block above_form %}
<h1>{% blocktrans with type=request.GET.type %}Create {{ type }}{% endblocktrans %}</h1>
{% endblock %}

View File

@ -1,11 +1,12 @@
{% extends "generic/form.html" %}
{% load utils %}
{% load i18n %}
{% block above_form %}
<h1>{% trans 'Update' %}</h1>
<h1>{% blocktrans with type=form|form_verbose_name %}Update {{ type }}{% endblocktrans %}</h1>
{% endblock %}
{% block action %}
{% trans 'Update' %}
{% blocktrans with type=form|form_verbose_name %}Update {{ type }}{% endblocktrans %}
{% endblock %}

View File

@ -34,7 +34,7 @@ class FactorListView(AdminRequiredMixin, ListView):
class FactorCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
"""Create new Factor"""
template_name = 'generic/create_inheritance.html'
template_name = 'generic/create.html'
success_url = reverse_lazy('passbook_admin:factors')
success_message = _('Successfully created Factor')

View File

@ -32,7 +32,7 @@ class PolicyListView(AdminRequiredMixin, ListView):
class PolicyCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
"""Create new Policy"""
template_name = 'generic/create_inheritance.html'
template_name = 'generic/create.html'
success_url = reverse_lazy('passbook_admin:policies')
success_message = _('Successfully created Policy')

View File

@ -29,7 +29,7 @@ class ProviderListView(AdminRequiredMixin, ListView):
class ProviderCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
"""Create new Provider"""
template_name = 'generic/create_inheritance.html'
template_name = 'generic/create.html'
success_url = reverse_lazy('passbook_admin:providers')
success_message = _('Successfully created Provider')

View File

@ -34,7 +34,7 @@ class SourceListView(AdminRequiredMixin, ListView):
class SourceCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
"""Create new Source"""
template_name = 'generic/create_inheritance.html'
template_name = 'generic/create.html'
success_url = reverse_lazy('passbook_admin:sources')
success_message = _('Successfully created Source')

View File

@ -0,0 +1,17 @@
# Generated by Django 2.1.7 on 2019-02-27 15:05
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('passbook_hibp_policy', '0002_auto_20190225_1912'),
]
operations = [
migrations.AlterModelOptions(
name='haveibeenpwendpolicy',
options={'verbose_name': 'Have I Been Pwned Policy', 'verbose_name_plural': 'Have I Been Pwned Policies'},
),
]

View File

@ -41,5 +41,5 @@ class HaveIBeenPwendPolicy(Policy):
class Meta:
verbose_name = _('have i been pwned Policy')
verbose_name_plural = _('have i been pwned Policies')
verbose_name = _('Have I Been Pwned Policy')
verbose_name_plural = _('Have I Been Pwned Policies')

View File

@ -208,7 +208,14 @@ def gravatar(email, size=None, rating=None):
return escape(gravatar_url)
@register.filter
def verbose_name(obj):
"""Return Object's Verbose Name"""
return obj._meta.verbose_name
@register.filter
def form_verbose_name(obj):
"""Return ModelForm's Object's Verbose Name"""
return obj._meta.model._meta.verbose_name