Skip to content

Commit

Permalink
Split out address views
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Rees authored and Morgan Rees committed Aug 27, 2024
1 parent 4a25698 commit 0887a68
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ <h3 class="govuk-heading-m" style="float:left;">Business {{ forloop.counter }} <
class="govuk-visually-hidden"> Business {{forloop.counter}} details </span></a>
{% elif business.cleaned_data.country == "GB" %}
<a class="govuk-link" style="font-size: 19px; text-align:right"
href="{% url 'add_a_business' location='in_the_uk' %}?business_uuid={{ id }}">Change<span
href="{% url 'add_a_business_uk' %}?business_uuid={{ id }}">Change<span
class="govuk-visually-hidden"> Business {{forloop.counter}} details </span></a>
{% else %}
<a class="govuk-link" style="font-size: 19px; text-align:right"
href="{% url 'add_a_business' location='outside_the_uk' %}?business_uuid={{ id }}">Change<span
href="{% url 'add_a_business_non_uk' %}?business_uuid={{ id }}">Change<span
class="govuk-visually-hidden"> Business {{forloop.counter}} details </span></a>
{% endif %}
</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ <h3 class="govuk-heading-s" style="float:left"> Business {{ forloop.counter }}</
<a class="govuk-link" style="font-size: 19px; text-align:right"
href="{% url 'do_you_know_the_registered_company_number' %}?change=yes&business_uuid={{ id }}">Change<span
class="govuk-visually-hidden">business {{ forloop.counter }} details </span></a>
{% elif business.cleaned_data.country == "GB" %}
<a class="govuk-link" style="font-size: 19px; text-align:right"
href="{% url 'add_a_business_uk' %}?business_uuid={{ id }}">Change<span
class="govuk-visually-hidden">business {{ forloop.counter }} details</span></a>
{% else %}
<a class="govuk-link" style="font-size: 19px; text-align:right"
href="{% url 'add_a_business' location=business.cleaned_data.url_location %}?business_uuid={{ id }}">Change<span
href="{% url 'add_a_business_non_uk' %}?business_uuid={{ id }}">Change<span
class="govuk-visually-hidden">business {{ forloop.counter }} details</span></a>
{% endif %}
</dd>
Expand Down Expand Up @@ -140,8 +144,9 @@ <h3 class="govuk-heading-s"> Your Details</h3>
{% include "apply_for_a_licence/partials/truncated_text.html" with text=form_data.add_yourself_address.readable_address|linebreaksbr %}
</dd>
<dd class="govuk-summary-list__actions">

<a class="govuk-link"
href="{% url 'add_yourself_address' %}">Change<span
href="{% url 'add_yourself_address_uk' %}">Change<span
class="govuk-visually-hidden">your address</span></a>
</dd>
</div>
Expand Down Expand Up @@ -194,12 +199,23 @@ <h3 class="govuk-heading-s"> Individual {{ forloop.counter }}</h3>
Address
</dt>
<dd class="govuk-summary-list__value">
{% include "apply_for_a_licence/partials/truncated_text.html" with text=form_data.add_yourself_address.readable_address|linebreaksbr %}
{% if form_data.add_yourself_address_uk %}
{% include "apply_for_a_licence/partials/truncated_text.html" with text=form_data.add_yourself_address_uk.readable_address|linebreaksbr %}
{% elif form_data.add_yourself_address_non_uk %}
{% include "apply_for_a_licence/partials/truncated_text.html" with text=form_data.add_yourself_address_non_uk.readable_address|linebreaksbr %}
{% endif %}
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link"
href="{% url 'add_yourself_address' %}">Change<span
class="govuk-visually-hidden">address of individual {{ forloop.counter }}</span></a>
{% if form_data.add_yourself_address_uk %}

<a class="govuk-link"
href="{% url 'add_yourself_address_uk' %}">Change<span
class="govuk-visually-hidden">address of individual {{ forloop.counter }}</span></a>
{% elif form_data.add_yourself_address_non_uk %}
<a class="govuk-link"
href="{% url 'add_yourself_address_non_uk' %}">Change<span
class="govuk-visually-hidden">address of individual {{ forloop.counter }}</span></a>
{% endif %}
</dd>
</div>
</dl>
Expand Down Expand Up @@ -293,10 +309,17 @@ <h3 class="govuk-heading-s"> Individual {{ forloop.counter }}</h3>
{% include "apply_for_a_licence/partials/truncated_text.html" with text=individual.address_data.cleaned_data.readable_address|linebreaksbr %}
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link"
href="{% url 'what_is_individuals_address' individual_uuid=id location=individual.address_data.cleaned_data.url_location %}?redirect_to_url=check_your_answers">Change<span
class="govuk-visually-hidden">address of individual {{ forloop.counter }}</span></a>
{% if individual.address_data.cleaned_data.url_location == "in_the_uk" %}
<a class="govuk-link"
href="{% url 'what_is_individuals_address_uk' individual_uuid=id %}?redirect_to_url=check_your_answers">Change<span
class="govuk-visually-hidden">address of individual {{ forloop.counter }}</span></a>
{% else %}
<a class="govuk-link"
href="{% url 'c' individual_uuid=id %}?redirect_to_url=check_your_answers">Change<span
class="govuk-visually-hidden">address of individual {{ forloop.counter }}</span></a>
{% endif %}
</dd>

</div>
</dl>
{% endif %}
Expand Down Expand Up @@ -399,7 +422,7 @@ <h2 class="govuk-heading-s">Recipient {{ forloop.counter }}</h2>
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link"
href="{% url 'add_a_recipient' location='in_the_uk' %}?recipient_uuid={{ id }}">Change<span
href="{% url 'add_a_recipient_uk' %}?recipient_uuid={{ id }}">Change<span
class="govuk-visually-hidden">location of recipient {{ forloop.counter }}</span></a>
</dd>
{% else %}
Expand All @@ -408,7 +431,7 @@ <h2 class="govuk-heading-s">Recipient {{ forloop.counter }}</h2>
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link"
href="{% url 'add_a_recipient' location='outside_the_uk' %}?recipient_uuid={{ id }}&redirect_to_url=check_your_answers">Change<span
href="{% url 'add_a_recipient_non_uk' %}?recipient_uuid={{ id }}&redirect_to_url=check_your_answers">Change<span
class="govuk-visually-hidden">location of recipient {{ forloop.counter }}</span></a>
</dd>
{% endif %}
Expand All @@ -425,11 +448,11 @@ <h2 class="govuk-heading-s">Recipient {{ forloop.counter }}</h2>
<dd class="govuk-summary-list__actions">
{% if recipient.cleaned_data.country == "GB" %}
<a class="govuk-link"
href="{% url 'add_a_recipient' location='in_the_uk' %}?recipient_uuid={{ id }}">Change<span
href="{% url 'add_a_recipient_uk' %}?recipient_uuid={{ id }}">Change<span
class="govuk-visually-hidden">name and address of recipient {{ forloop.counter }}</span></a>
{% else %}
<a class="govuk-link"
href="{% url 'add_a_recipient' location='outside_the_uk' %}?recipient_uuid={{ id }}">Change<span
href="{% url 'add_a_recipient_non_uk' %}?recipient_uuid={{ id }}">Change<span
class="govuk-visually-hidden">name and address of recipient {{ forloop.counter }}</span></a>
{% endif %}
</dd>
Expand All @@ -447,11 +470,11 @@ <h2 class="govuk-heading-s">Recipient {{ forloop.counter }}</h2>
<dd class="govuk-summary-list__actions">
{% if recipient.cleaned_data.country == "GB" %}
<a class="govuk-link"
href="{% url 'add_a_recipient' location='in_the_uk' %}?recipient_uuid={{ id }}">Change<span
href="{% url 'add_a_recipient_uk' %}?recipient_uuid={{ id }}">Change<span
class="govuk-visually-hidden">website of recipient {{ forloop.counter }}</span></a>
{% else %}
<a class="govuk-link"
href="{% url 'add_a_recipient' location='outside_the_uk' %}?recipient_uuid={{ id }}">Change<span
href="{% url 'add_a_recipient_non_uk' %}?recipient_uuid={{ id }}">Change<span
class="govuk-visually-hidden">website of recipient {{ forloop.counter }}</span></a>
{% endif %}
</dd>
Expand All @@ -468,11 +491,11 @@ <h2 class="govuk-heading-s">Recipient {{ forloop.counter }}</h2>
<dd class="govuk-summary-list__actions">
{% if recipient.cleaned_data.country == "GB" %}
<a class="govuk-link"
href="{% url 'add_a_recipient' location='in_the_uk' %}?recipient_uuid={{ id }}">Change<span
href="{% url 'add_a_recipient_uk' %}?recipient_uuid={{ id }}">Change<span
class="govuk-visually-hidden">additional contact information of recipient {{ forloop.counter }}</span></a>
{% else %}
<a class="govuk-link"
href="{% url 'add_a_recipient' location='outside_the_uk' %}?recipient_uuid={{ id }}">Change<span
href="{% url 'add_a_recipient_non_uk' %}?recipient_uuid={{ id }}">Change<span
class="govuk-visually-hidden">additional contact information of recipient {{ forloop.counter }}</span></a>
{% endif %}
</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ <h3 class="govuk-heading-m" style="float:left;">Recipient {{ forloop.counter }}
<dd class="govuk-summary-list__action govuk-!-font-weight-regular">
{% if recipient.cleaned_data.country == "GB" %}
<a class="govuk-link" style="font-size: 19px; text-align:right"
href="{% url 'add_a_recipient' location='in_the_uk' %}?recipient_uuid={{ id }} ">Change<span
href="{% url 'add_a_recipient_uk' %}?recipient_uuid={{ id }} ">Change<span
class="govuk-visually-hidden"> recipient {{forloop.counter}} details </span></a>
{% else %}
<a class="govuk-link" style="font-size: 19px; text-align:right"
href="{% url 'add_a_recipient' location='outside_the_uk' %}?recipient_uuid={{ id }} ">Change<span
href="{% url 'add_a_recipient_non_uk' %}?recipient_uuid={{ id }} ">Change<span
class="govuk-visually-hidden"> recipient {{forloop.counter}} details </span></a>
{% endif %}
</dd>
Expand Down
22 changes: 16 additions & 6 deletions django_app/apply_for_a_licence/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,23 @@
views_business.ManualCompaniesHouseInputView.as_view(),
name="manual_companies_house_input",
),
path("add_a_business/<str:location>", views_business.AddABusinessView.as_view(), name="add_a_business"),
path("add_a_business/uk", views_business.AddAUKBusinessView.as_view(), name="add_a_business_uk"),
path("add_a_business/non_uk", views_business.AddANonUKBusinessView.as_view(), name="add_a_business_non_uk"),
path("delete_business", views_business.DeleteBusinessView.as_view(), name="delete_business"),
path("business_added", views_business.BusinessAddedView.as_view(), name="business_added"),
]

views_individual_urls = [
path("add_an_individual", views_individual.AddAnIndividualView.as_view(), name="add_an_individual"),
path(
"what_is_individuals_address/<str:location>/<str:individual_uuid>",
views_individual.WhatIsIndividualsAddressView.as_view(),
name="what_is_individuals_address",
"what_is_individuals_address/uk/<str:individual_uuid>",
views_individual.WhatIsIndividualsUKAddressView.as_view(),
name="what_is_individuals_address_uk",
),
path(
"what_is_individuals_address/non_uk/<str:individual_uuid>",
views_individual.WhatIsIndividualsNonUKAddressView.as_view(),
name="what_is_individuals_address_non_uk",
),
path("delete_individual", views_individual.DeleteIndividualView.as_view(), name="delete_individual"),
path("individual_added", views_individual.IndividualAddedView.as_view(), name="individual_added"),
Expand All @@ -70,7 +76,10 @@

views_yourself_urls = [
path("add_yourself", views_yourself.AddYourselfView.as_view(), name="add_yourself"),
path("add_yourself_address", views_yourself.AddYourselfAddressView.as_view(), name="add_yourself_address"),
path("add_yourself_address/uk/", views_yourself.AddYourselfUKAddressView.as_view(), name="add_yourself_address_uk"),
path(
"add_yourself_address/non_uk/", views_yourself.AddYourselfNonUKAddressView.as_view(), name="add_yourself_address_non_uk"
),
path(
"yourself_and_individual_added",
views_yourself.YourselfAndIndividualAddedView.as_view(),
Expand Down Expand Up @@ -104,7 +113,8 @@
views_recipients.WhereIsTheRecipientLocatedView.as_view(),
name="where_is_the_recipient_located",
),
path("add_a_recipient/<str:location>", views_recipients.AddARecipientView.as_view(), name="add_a_recipient"),
path("add_a_recipient/uk", views_recipients.AddAUKRecipientView.as_view(), name="add_a_recipient_uk"),
path("add_a_recipient/non_uk", views_recipients.AddANonUKRecipientView.as_view(), name="add_a_recipient_non_uk"),
path("delete_recipient", views_recipients.DeleteRecipientView.as_view(), name="delete_recipient"),
path("recipient_added", views_recipients.RecipientAddedView.as_view(), name="recipient_added"),
path(
Expand Down
3 changes: 2 additions & 1 deletion django_app/apply_for_a_licence/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def get_all_cleaned_data(request: HttpRequest) -> dict:
from apply_for_a_licence.urls import step_to_view_dict

all_cleaned_data = {}
form_views = [step for step, view in step_to_view_dict.items() if getattr(view, "form_class", None)]
form_views = [step for step, view in step_to_view_dict.items() if (getattr(view, "form_class", None))]

for step_name in form_views:
all_cleaned_data[step_name] = get_cleaned_data_for_step(request, step_name)

Expand Down
31 changes: 18 additions & 13 deletions django_app/apply_for_a_licence/views/views_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class AddABusinessView(BaseFormView):
success_url = reverse_lazy("business_added")
redirect_after_post = False

def setup(self, request, *args, **kwargs):
self.location = kwargs["location"]
return super().setup(request, *args, **kwargs)

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()

Expand All @@ -34,13 +30,6 @@ def get_form_kwargs(self):
kwargs["data"] = businesses_dict["dirty_data"]
return kwargs

def get_form_class(self):
if self.location == "in_the_uk":
form_class = forms.AddAUKBusinessForm
else:
form_class = forms.AddANonUKBusinessForm
return form_class

def form_valid(self, form: forms.AddAUKBusinessForm | forms.AddANonUKBusinessForm) -> HttpResponse:
current_businesses = self.request.session.get("businesses", {})
# get the business_uuid if it exists, otherwise create it
Expand All @@ -54,6 +43,14 @@ def form_valid(self, form: forms.AddAUKBusinessForm | forms.AddANonUKBusinessFor
return super().form_valid(form)


class AddAUKBusinessView(AddABusinessView):
form_class = forms.AddAUKBusinessForm


class AddANonUKBusinessView(BaseFormView):
form_class = forms.AddANonUKBusinessForm


class BusinessAddedView(BaseFormView):
form_class = forms.BusinessAddedForm
template_name = "apply_for_a_licence/form_steps/business_added.html"
Expand Down Expand Up @@ -147,7 +144,11 @@ class ManualCompaniesHouseInputView(BaseFormView):

def get_success_url(self) -> str:
location = self.form.cleaned_data["manual_companies_house_input"]
return reverse("add_a_business", kwargs={"location": location})
if location == "in_the_uk":
success_url = reverse("add_a_business_uk")
else:
success_url = reverse("add_a_business_non_uk")
return success_url


class CheckCompanyDetailsView(BaseFormView):
Expand All @@ -168,7 +169,11 @@ class WhereIsTheBusinessLocatedView(BaseFormView):

def get_success_url(self) -> str:
location = self.form.cleaned_data["where_is_the_address"]
success_url = reverse("add_a_business", kwargs={"location": location})
if location == "in_the_uk":
success_url = reverse("add_a_business_uk")
else:
success_url = reverse("add_a_business_non_uk")
return success_url

if get_parameters := urllib.parse.urlencode(self.request.GET):
success_url += "?" + get_parameters
Expand Down
Loading

0 comments on commit 0887a68

Please sign in to comment.