Skip to content

Commit

Permalink
Use DummyForm as generic form class
Browse files Browse the repository at this point in the history
  • Loading branch information
eadpearce committed Dec 20, 2024
1 parent 1667ca1 commit b59c4ee
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 32 deletions.
5 changes: 5 additions & 0 deletions common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,8 @@ def add_extra_error(self, field, error):
self._errors[field].extend(error_list)
if field in self.cleaned_data:
del self.cleaned_data[field]


class DummyForm(forms.Form):
"""Form with no fields used as a placeholder for when the view requires a
form class."""
4 changes: 0 additions & 4 deletions measures/forms/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ def deserialize_init_kwargs(cls, form_kwargs: Dict) -> Dict:
return kwargs


class MeasureCreateStartForm(forms.Form):
pass


class MeasureDetailsForm(
SerializableFormMixin,
ValidityPeriodForm,
Expand Down
23 changes: 13 additions & 10 deletions measures/views/wizard.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import logging
from typing import Dict
from typing import List

from crispy_forms_gds.helper import FormHelper
from django.conf import settings
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.shortcuts import render
from django.template.loader import render_to_string
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
from formtools.wizard.views import NamedUrlSessionWizardView

from common.forms import DummyForm
from geo_areas import constants
from geo_areas.models import GeographicalArea
from geo_areas.models import GeographicalMembership
Expand Down Expand Up @@ -177,7 +174,9 @@ def edit_measures(self, selected_measures, cleaned_data):
wizard forms."""

measures_editor = MeasuresEditor(
self.workbasket, selected_measures, cleaned_data
self.workbasket,
selected_measures,
cleaned_data,
)
return measures_editor.edit_measures()

Expand Down Expand Up @@ -205,7 +204,9 @@ def sync_done(self, form_list, **kwargs):

@method_decorator(require_current_workbasket, name="dispatch")
class MeasureCreateWizard(
PermissionRequiredMixin, NamedUrlSessionWizardView, MeasureSerializableWizardMixin
PermissionRequiredMixin,
NamedUrlSessionWizardView,
MeasureSerializableWizardMixin,
):
"""
Multipart form wizard for creating a single measure.
Expand Down Expand Up @@ -244,7 +245,7 @@ class MeasureCreateWizard(
"""Forms in this wizard's steps that collect user data."""

form_list = [
(START, forms.MeasureCreateStartForm),
(START, DummyForm),
*data_form_list,
(SUMMARY, forms.MeasureReviewForm),
]
Expand Down Expand Up @@ -613,7 +614,8 @@ def get_template_names(self):


class MeasuresWizardAsyncConfirm(TemplateView):
"""A success view that serves both the bulk create and bulk edit asynchronous pathways."""
"""A success view that serves both the bulk create and bulk edit
asynchronous pathways."""

template_name = "measures/confirm-create-multiple-async.jinja"

Expand All @@ -624,13 +626,14 @@ def get_context_data(self, **kwargs):


class MeasuresWizardSyncConfirm(TemplateView):
"""A success view that serves both the bulk create and bulk edit synchronous pathways."""
"""A success view that serves both the bulk create and bulk edit synchronous
pathways."""

template_name = "measures/confirm-edit-multiple.jinja"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["edited_or_created_measures_count"] = self.kwargs.get(
"edited_or_created_measures_count"
"edited_or_created_measures_count",
)
return context
12 changes: 0 additions & 12 deletions quotas/forms/wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
from workbaskets.forms import SelectableObjectsForm


class DuplicateQuotaDefinitionPeriodStartForm(forms.Form):
pass


class QuotaOrderNumbersSelectForm(forms.Form):
main_quota_order_number = AutoCompleteField(
label="Main quota order number",
Expand Down Expand Up @@ -129,14 +125,6 @@ def clean(self):
return cleaned_data


class BulkQuotaDefinitionCreateStartForm(forms.Form):
pass


class BulkQuotaDefinitionCreateIntroductoryPeriod(forms.Form):
pass


class QuotaDefinitionCreateForm(
ValidityPeriodForm,
forms.ModelForm,
Expand Down
3 changes: 2 additions & 1 deletion quotas/views/wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.views.generic import TemplateView
from formtools.wizard.views import NamedUrlSessionWizardView

from common.forms import DummyForm
from common.serializers import serialize_date
from common.validators import UpdateType
from common.views import BusinessRulesMixin
Expand Down Expand Up @@ -43,7 +44,7 @@ class DuplicateDefinitionsWizard(
COMPLETE = "complete"

form_list = [
(START, forms.DuplicateQuotaDefinitionPeriodStartForm),
(START, DummyForm),
(QUOTA_ORDER_NUMBERS, forms.QuotaOrderNumbersSelectForm),
(SELECT_DEFINITION_PERIODS, forms.SelectSubQuotaDefinitionsForm),
(SELECTED_DEFINITIONS, forms.SelectedDefinitionsForm),
Expand Down
4 changes: 0 additions & 4 deletions workbaskets/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,3 @@ def __init__(self, *args, **kwargs):
css_class="govuk-button-group",
),
)


class WorkbasketMeasuresCheckForm(forms.Form):
pass
3 changes: 2 additions & 1 deletion workbaskets/views/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from checks.models import MissingMeasureCommCode
from checks.models import TrackedModelCheck
from common.filters import TamatoFilter
from common.forms import DummyForm
from common.inspect_tap_tasks import TAPTasks
from common.models import Transaction
from common.models.transactions import TransactionPartition
Expand Down Expand Up @@ -1064,7 +1065,7 @@ def post(self, request, *args, **kwargs):
class WorkBasketCommCodeChecks(SortingMixin, ListView, FormView):
success_url = reverse_lazy("workbaskets:workbasket-ui-missing-measures-check")
template_name = "workbaskets/checks/missing_measures.jinja"
form_class = forms.WorkbasketMeasuresCheckForm
form_class = DummyForm

model = MissingMeasureCommCode
sort_by_fields = ["commodity"]
Expand Down

0 comments on commit b59c4ee

Please sign in to comment.