diff --git a/generic/forms.py b/generic/forms.py index ec59bc88..524136e7 100755 --- a/generic/forms.py +++ b/generic/forms.py @@ -65,6 +65,9 @@ from django.core.exceptions import ValidationError import datetime from django.forms.utils import from_current_timezone, to_current_timezone +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Submit + class SplitDateTimeFieldDefaultTime(SplitDateTimeField): def compress(self, data_list): if data_list: @@ -107,6 +110,15 @@ class ExamFormMixin: def __init__(self, *args, user, **kwargs) -> None: super(ModelForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_id = 'id-exam-form' + self.helper.form_class = 'exam-form' + self.helper.form_method = 'post' + self.helper.form_action = 'submit' + + + self.helper.add_input(Submit('submit', 'Submit')) + #if user.is_superuser or user.groups.filter(name="cid_user_manager").exists(): # cid_user_group_queryset = CidUserGroup.objects.filter(archive=False) # user_user_group_queryset = UserUserGroup.objects.filter(archive=False) @@ -130,6 +142,7 @@ class ExamFormMixin: time_format="%H:%M", ), required=False, + help_text="The date the exam is due to start (time is optional)", ) self.fields["end_date"] = SplitDateTimeFieldDefaultTimeEnd( widget=SplitDateTimeWidget( @@ -139,6 +152,7 @@ class ExamFormMixin: time_format="%H:%M", ), required=False, + help_text="The date the exam is due to start (time is optional)", ) class Meta: @@ -149,9 +163,9 @@ class ExamFormMixin: "authors_only", "exam_mode", "include_history", + "restrict_to_dates", "start_date", "end_date", - "restrict_to_dates", "active", "publish_results", "archive", diff --git a/rad/settings.py b/rad/settings.py index cab48e2f..fc3d21c1 100644 --- a/rad/settings.py +++ b/rad/settings.py @@ -76,7 +76,7 @@ INSTALLED_APPS = [ "django_unused_media", "django_htmx", "crispy_forms", - "crispy_bootstrap4", + "crispy_bootstrap5", "autocomplete", 'markdownify.apps.MarkdownifyConfig', 'django_jsonforms', @@ -291,8 +291,8 @@ EMAIL_USE_SSL = True ADMINS = [("Ross","ross@xkjq.uk")] -CRISPY_ALLOWED_TEMPLATE_PACK = 'bootstrap4' -CRISPY_TEMPLATE_PACK = 'bootstrap4' +CRISPY_ALLOWED_TEMPLATE_PACK = 'bootstrap5' +CRISPY_TEMPLATE_PACK = 'bootstrap5' DEBUG_CONTAINER = False diff --git a/requirements.txt b/requirements.txt index c2d961a8..307fe5de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,8 @@ debugpy git+https://github.com/jazzband/django-cookie-consent#django-cookie-consent django-crispy-forms django-ninja -crispy-bootstrap4 +#crispy-bootstrap4 +crispy-bootstrap5 django-rich ipython django-htmx-autocomplete diff --git a/templates/exam_create_form.html b/templates/exam_create_form.html index bcd12a6f..20d87e1e 100644 --- a/templates/exam_create_form.html +++ b/templates/exam_create_form.html @@ -1,5 +1,6 @@ {% extends view.model.app_name|add:"/base.html" %} +{% load crispy_forms_tags %} {% block js %} {{ form.media }} {% endblock %} @@ -7,12 +8,10 @@ {% block content %}

Add Exam

+ Create a new exam. Questions and candidates can be added later.
{% csrf_token %} - - {{ form }} -
- + {% crispy form form.helper %}
{% endblock %} diff --git a/templates/exam_list.html b/templates/exam_list.html index 75ca0d6f..3efcc860 100644 --- a/templates/exam_list.html +++ b/templates/exam_list.html @@ -60,9 +60,9 @@ {% if view_all %} - Hide archived + Hide archived {% else %} - View all + View all {% endif %} {% include 'exam_overview_js.html' %} diff --git a/templates/exam_update_form.html b/templates/exam_update_form.html index 00145258..4731b5a1 100644 --- a/templates/exam_update_form.html +++ b/templates/exam_update_form.html @@ -1,5 +1,7 @@ {% extends exam.app_name|add:"/exams.html" %} +{% load crispy_forms_tags %} + {% block js %} {{ form.media }} {% endblock %} @@ -14,10 +16,11 @@ {% block content %}

Update Exam

+ This form allows you to edit the exam details. To manage candidates head to the candidates page.
{% csrf_token %} - {{ form.as_table }} + {{ form|crispy }}