Skip to content

Commit

Permalink
separate out the context from reference document version details
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmills-DIT committed Mar 8, 2024
1 parent c8b5294 commit 30770c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
54 changes: 25 additions & 29 deletions reference_documents/forms/preferential_quota_order_number_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ class Meta:
"valid_between",
]

def __init__(self, reference_document_version, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields[
"main_order_number"
].queryset = reference_document_version.preferential_quota_order_numbers.all()
self.helper = FormHelper(self)
self.helper.label_size = Size.SMALL
self.helper.legend_size = Size.SMALL
self.helper.layout = Layout(
Field.text(
"quota_order_number",
),
"coefficient",
"main_order_number",
"start_date",
"end_date",
Submit(
"submit",
"Save",
data_module="govuk-button",
data_prevent_double_click="true",
),
)

quota_order_number = forms.CharField(
label="Order number",
help_text="Enter a six digit number",
Expand Down Expand Up @@ -49,7 +73,7 @@ class Meta:
widget=forms.TextInput(attrs={"style": "max-width: 6em"}),
)

main_order_number = forms.ModelChoiceField(
main_order_number_id = forms.ModelChoiceField(
label="Main order number",
help_text="Select a main order number",
queryset=PreferentialQuotaOrderNumber.objects.all(),
Expand All @@ -58,37 +82,9 @@ class Meta:
"invalid": "Main Order number is invalid",
},
required=False,
to_field_name="main_order_number_id",
widget=forms.Select(attrs={"class": "form-control"}),
)

def __init__(self, reference_document_version, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields[
"main_order_number"
].choices = reference_document_version.preferential_quota_order_numbers.all().values_list(
"id",
"quota_order_number",
)
self.helper = FormHelper(self)
self.helper.label_size = Size.SMALL
self.helper.legend_size = Size.SMALL
self.helper.layout = Layout(
Field.text(
"quota_order_number",
),
"coefficient",
"main_order_number",
"start_date",
"end_date",
Submit(
"submit",
"Save",
data_module="govuk-button",
data_prevent_double_click="true",
),
)


class PreferentialQuotaOrderNumberDeleteForm(forms.ModelForm):
class Meta:
Expand Down
3 changes: 3 additions & 0 deletions reference_documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class PreferentialQuotaOrderNumber(models.Model):
default=None,
)

def __str__(self):
return f"{self.quota_order_number}"


class PreferentialQuota(models.Model):
preferential_quota_order_number = models.ForeignKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class PreferentialQuotaOrderNumberEditView(PermissionRequiredMixin, UpdateView):

def get_form_kwargs(self):
kwargs = super(PreferentialQuotaOrderNumberEditView, self).get_form_kwargs()
kwargs["reference_document_version"] = "x"
return kwargs

def get_success_url(self):
Expand Down

0 comments on commit 30770c1

Please sign in to comment.