admin: parameterise generic from's base template

This commit is contained in:
Jens Langhammer 2020-02-17 20:29:41 +01:00
parent e57da71dcf
commit 9400b01a55
4 changed files with 13 additions and 4 deletions

View file

@ -1,4 +1,4 @@
{% extends "generic/form.html" %}
{% extends base_template|default:"generic/form.html" %}
{% load utils %}
{% load i18n %}

View file

@ -30,12 +30,12 @@
<div class="">
<form action="" method="post" class="form-horizontal">
{% include 'partials/form.html' with form=form %}
{% block beneath_form %}
{% endblock %}
<a class="btn btn-default" href="{% back %}">{% trans "Cancel" %}</a>
<input type="submit" class="btn btn-primary" value="{% block action %}{% endblock %}" />
</form>
</div>
{% block beneath_form %}
{% endblock %}
<script>
const attributes = document.getElementsByName('attributes');
if (attributes.length > 0) {

View file

@ -1,4 +1,4 @@
{% extends "generic/form.html" %}
{% extends base_template|default:"generic/form.html" %}
{% load utils %}
{% load i18n %}

View file

@ -66,6 +66,9 @@ class PropertyMappingCreateView(
if x.__name__ == property_mapping_type
)
kwargs["type"] = model._meta.verbose_name
form_cls = self.get_form_class()
if hasattr(form_cls, "template_name"):
kwargs["base_template"] = form_cls.template_name
return kwargs
def get_form_class(self):
@ -92,6 +95,12 @@ class PropertyMappingUpdateView(
success_url = reverse_lazy("passbook_admin:property-mappings")
success_message = _("Successfully updated Property Mapping")
def get_context_data(self, **kwargs):
form_cls = self.get_form_class()
if hasattr(form_cls, "template_name"):
kwargs["base_template"] = form_cls.template_name
return kwargs
def get_form_class(self):
form_class_path = self.get_object().form
form_class = path_to_class(form_class_path)