Enhance bulk add groups form with crispy forms for improved styling and usability

This commit is contained in:
Ross
2025-11-12 21:23:41 +00:00
parent ec0245fe7c
commit da04138861
2 changed files with 33 additions and 12 deletions
+27
View File
@@ -328,6 +328,33 @@ class ExamCollectionBulkAddGroupsForm(Form):
self.fields["cid_user_groups"].widget.attrs["size"] = 8
self.fields["user_user_groups"].widget.attrs["size"] = 8
# Crispy helper: render fields prettily in templates. We set form_tag=False
# because the HTMX partial includes the <form> tag with hx attributes.
try:
self.helper = FormHelper()
# render only the fields (the template contains the form element)
self.helper.form_tag = False
# use bootstrap5 templates if available in the project
self.helper.template_pack = "bootstrap5"
self.helper.form_class = "form-vertical"
self.helper.layout = Layout(
Div(
Field("cid_user_groups", css_class="form-select", template="bootstrap5/layout/multi_select.html"),
css_class="mb-3",
),
Div(
Field("user_user_groups", css_class="form-select", template="bootstrap5/layout/multi_select.html"),
css_class="mb-3",
),
Div(
Field("exam_types", css_class="form-select"),
css_class="mb-3",
),
)
except Exception:
# If crispy isn't available for some reason, degrade gracefully.
self.helper = None
class ExaminationForm(ModelForm):
def __init__(self, *args, **kwargs):