Recognise title and template attributes on item_forms signal (#3492)

This commit is contained in:
Kian Cross
2023-07-24 16:35:39 +01:00
committed by GitHub
parent 63ae0724cf
commit 65ecdc184e
3 changed files with 37 additions and 4 deletions

View File

@@ -304,6 +304,10 @@ an instance of a form class that you bind yourself when appropriate. Your form w
as part of the standard validation and rendering cycle and rendered using default bootstrap as part of the standard validation and rendering cycle and rendered using default bootstrap
styles. It is advisable to set a prefix for your form to avoid clashes with other plugins. styles. It is advisable to set a prefix for your form to avoid clashes with other plugins.
Your forms may also have two special properties: ``template`` with a template that will be
included to render the form, and ``title``, which will be used as a headline. Your template
will be passed a ``form`` variable with your form.
As with all plugin signals, the ``sender`` keyword argument will contain the event. As with all plugin signals, the ``sender`` keyword argument will contain the event.
""" """

View File

@@ -186,8 +186,12 @@
{% bootstrap_field form.media_type layout="control" %} {% bootstrap_field form.media_type layout="control" %}
{% endif %} {% endif %}
{% for f in plugin_forms %} {% for f in plugin_forms %}
{% if f.is_layouts %} {% if f.is_layouts and not f.title %}
{% bootstrap_form f layout="control" %} {% if f.template %}
{% include f.template with form=f %}
{% else %}
{% bootstrap_form f layout="control" %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</fieldset> </fieldset>
@@ -256,11 +260,27 @@
{% endif %} {% endif %}
{% bootstrap_field form.show_quota_left layout="control" %} {% bootstrap_field form.show_quota_left layout="control" %}
{% for f in plugin_forms %} {% for f in plugin_forms %}
{% if not f.is_layouts %} {% if not f.is_layouts and not f.title %}
{% bootstrap_form f layout="control" %} {% if f.template %}
{% include f.template with form=f %}
{% else %}
{% bootstrap_form f layout="control" %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</fieldset> </fieldset>
{% for f in plugin_forms %}
{% if not f.is_layouts and f.title %}
<fieldset>
<legend>{{ f.title }}</legend>
{% if f.template %}
{% include f.template with form=f %}
{% else %}
{% bootstrap_form f layout="control" %}
{% endif %}
</fieldset>
{% endif %}
{% endfor %}
</div> </div>
<div class="form-group submit-group"> <div class="form-group submit-group">
<button type="submit" class="btn btn-primary btn-save"> <button type="submit" class="btn btn-primary btn-save">

View File

@@ -88,6 +88,10 @@ from ...helpers.compat import CompatDeleteView
from . import ChartContainingView, CreateView, PaginationMixin, UpdateView from . import ChartContainingView, CreateView, PaginationMixin, UpdateView
def has_truthy_attr(cls, attr):
return hasattr(cls, attr) and getattr(cls, attr)
class ItemList(ListView): class ItemList(ListView):
model = Item model = Item
context_object_name = 'items' context_object_name = 'items'
@@ -1293,6 +1297,11 @@ class ItemUpdateGeneral(ItemDetailMixin, EventPermissionRequiredMixin, MetaDataE
forms.extend(resp) forms.extend(resp)
else: else:
forms.append(resp) forms.append(resp)
for form in forms:
if has_truthy_attr(form, "title") and has_truthy_attr(form, "is_layout"):
raise ValueError("`title` and `is_layout` must not both be truthy values")
return forms return forms
def get_success_url(self) -> str: def get_success_url(self) -> str: