-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tss-2243 preliminary assessments (#854)
Preliminary Assessment Frontend --------- Co-authored-by: abarolo <asmundbekker@DBT000435.local> Co-authored-by: asmund bekker <145478290+abarolo@users.noreply.github.com>
- Loading branch information
1 parent
2079d3d
commit 5408e57
Showing
19 changed files
with
295 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django import forms | ||
|
||
from barriers.constants import PRELIMINARY_ASSESSMENT_CHOICES | ||
from barriers.forms.mixins import APIFormMixin | ||
from utils.api.client import MarketAccessAPIClient | ||
|
||
|
||
class UpdatePreliminaryAssessmentForm(APIFormMixin, forms.Form): | ||
preliminary_value = forms.ChoiceField( | ||
label="Barrier value", | ||
choices=PRELIMINARY_ASSESSMENT_CHOICES, | ||
widget=forms.RadioSelect, | ||
error_messages={ | ||
"required": "Select a value", | ||
}, | ||
) | ||
|
||
preliminary_value_details = forms.CharField( | ||
widget=forms.Textarea, | ||
label="Provide an explanation on how the value has been assessed", | ||
error_messages={"required": "Enter details of the preliminary value"}, | ||
) | ||
|
||
def __init__(self, preliminary_assessment=None, *args, **kwargs): | ||
self.token = kwargs.pop("token") | ||
self.barrier = kwargs.pop("barrier") | ||
self.preliminary_assessment = preliminary_assessment | ||
super().__init__(*args, **kwargs) | ||
|
||
def save(self): | ||
client = MarketAccessAPIClient(self.token) | ||
if self.preliminary_assessment: | ||
client.preliminary_assessment.patch_preliminary_assessment( | ||
barrier_id=self.barrier.id, | ||
value=self.cleaned_data["preliminary_value"], | ||
details=self.cleaned_data["preliminary_value_details"], | ||
) | ||
else: | ||
client.preliminary_assessment.create_preliminary_assessment( | ||
barrier_id=self.barrier.id, | ||
value=self.cleaned_data["preliminary_value"], | ||
details=self.cleaned_data["preliminary_value_details"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from django.urls import reverse | ||
from django.views.generic import FormView | ||
|
||
from barriers.forms.assessments.preliminary_assessment import ( | ||
UpdatePreliminaryAssessmentForm, | ||
) | ||
from barriers.views.mixins import APIBarrierFormViewMixin | ||
|
||
|
||
class PreliminaryAssessmentValue(APIBarrierFormViewMixin, FormView): | ||
template_name = "barriers/assessments/preliminary_assessment.html" | ||
form_class = UpdatePreliminaryAssessmentForm | ||
|
||
def get_form_kwargs(self): | ||
kwargs = super().get_form_kwargs() | ||
kwargs["token"] = self.request.session.get("sso_token") | ||
kwargs["barrier"] = self.barrier | ||
kwargs["preliminary_assessment"] = self.preliminary_assessment | ||
return kwargs | ||
|
||
def get_initial(self): | ||
if self.preliminary_assessment: | ||
return { | ||
"preliminary_value": self.preliminary_assessment.value, | ||
"preliminary_value_details": self.preliminary_assessment.details, | ||
} | ||
else: | ||
return | ||
|
||
def get_success_url(self): | ||
return reverse( | ||
"barriers:assessment_detail", | ||
kwargs={"barrier_id": self.kwargs.get("barrier_id")}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
templates/barriers/assessments/preliminary_assessment.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends "barriers/edit/base.html" %} | ||
|
||
{% block page_title %}{{ block.super }} - Commercial value estimate{% endblock %} | ||
|
||
{% block back_link %} | ||
<a href="{% url 'barriers:assessment_detail' barrier.id %}" class="govuk-back-link ma-back-link">Back</a> | ||
{% endblock %} | ||
|
||
{% block page_content %} | ||
|
||
{% include 'partials/heading.html' with text='Preliminary economic assessment' %} | ||
|
||
<form action="" method="POST" class="restrict-width"> | ||
|
||
{% csrf_token %} | ||
|
||
{% include "partials/forms/radio_input.html" with field=form.preliminary_value %} | ||
{% include "partials/forms/textarea.html" with field=form.preliminary_value_details %} | ||
|
||
<button class="govuk-button" data-module="govuk-button">Save and return</button> | ||
<a href="{% url 'barriers:assessment_detail' barrier.id %}" class="form-cancel">Cancel</a> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.