From 3312f3058a05464095c48bc47cde67c790ce430f Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 15 Nov 2025 23:02:12 +0000 Subject: [PATCH] Enhance CaseCollectionForm: replace collection_type field with radio buttons and add custom styling --- atlas/forms.py | 21 +++++++++++- .../templates/atlas/casecollection_form.html | 34 +++++++++++++++++++ .../widgets/radioselect_buttons.html | 24 +++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 atlas/templates/widgets/radioselect_buttons.html diff --git a/atlas/forms.py b/atlas/forms.py index d9e45115..427c1e57 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -142,6 +142,25 @@ class CaseCollectionForm(ModelForm): ModelForm.__init__(self, *args, **kwargs) super(CaseCollectionForm, self).__init__(*args, **kwargs) + # Render collection_type as radio buttons and ensure it appears near the top + if "collection_type" in self.fields: + # Replace the model field with an explicit ChoiceField that uses RadioSelect + original = self.fields["collection_type"] + choices = getattr(original, "choices", ()) + initial = original.initial if hasattr(original, "initial") else None + required = original.required + label = original.label + widget = RadioSelect(attrs={"class": "btn-check"}) + # assign custom template for rendering as button group + #widget.template_name = "widgets/radioselect_buttons.html" + self.fields["collection_type"] = forms.ChoiceField( + choices=choices, + widget=widget, + initial=initial, + required=required, + label=label, + ) + # Identify show_ fields show_fields = [f for f in self.fields if f.startswith("show_")] show_pre_fields = [f for f in show_fields if f.endswith("_pre")] @@ -187,6 +206,7 @@ class CaseCollectionForm(ModelForm): Fieldset( "Collection Details", "name", + Field("collection_type", css_class="mb-2"), Fieldset( "Dates", "restrict_to_dates", @@ -214,7 +234,6 @@ class CaseCollectionForm(ModelForm): "exam_mode", "self_review", "feedback_once_collection_complete", - "collection_type", "viewer_mode", "question_time_limit", "prerequisites", diff --git a/atlas/templates/atlas/casecollection_form.html b/atlas/templates/atlas/casecollection_form.html index cc6d02cc..4b919d56 100755 --- a/atlas/templates/atlas/casecollection_form.html +++ b/atlas/templates/atlas/casecollection_form.html @@ -3,6 +3,40 @@ {% load crispy_forms_tags %} {% block css %} + {% endblock %} {% block js %} diff --git a/atlas/templates/widgets/radioselect_buttons.html b/atlas/templates/widgets/radioselect_buttons.html new file mode 100644 index 00000000..eea19d5f --- /dev/null +++ b/atlas/templates/widgets/radioselect_buttons.html @@ -0,0 +1,24 @@ +{% load i18n %} +
+ {% for val, label in widget.choices %} + {% with forloop.counter0 as idx %} + {% with id=widget.name|add:"_"|add:idx %} + + + {% endwith %} + {% endwith %} + {% endfor %} +