class WTOStatusForm(APIFormMixin, forms.Form): wto_has_been_notified = YesNoBooleanField( label="Has this measure been notified to the WTO?", error_messages={"required": "Enter yes or no"}, ) wto_should_be_notified = YesNoBooleanField( label="Should the measure be notified to the WTO?", required=False, ) def clean(self): cleaned_data = super().clean() if cleaned_data.get("wto_has_been_notified") is False: if cleaned_data.get("wto_should_be_notified") is None: self.add_error("wto_should_be_notified", "Enter yes or no") elif cleaned_data.get("wto_has_been_notified") is True: cleaned_data["wto_should_be_notified"] = None def get_api_params(self): wto_profile = { "wto_has_been_notified": self.cleaned_data.get("wto_has_been_notified"), "wto_should_be_notified": self.cleaned_data.get("wto_should_be_notified"), } return {"wto_profile": wto_profile} def save(self): client = MarketAccessAPIClient(self.token) client.barriers.patch(id=self.id, **self.get_api_params())
class NewReportBarrierSummaryForm(forms.Form): summary = forms.CharField( label="Describe the barrier", help_text= "Include how the barrier is affecting the export or investment " "and why the barrier exists. For example, because of specific " "laws or measures, which government body imposed them and any " "political context; the HS code; and when the problem started.", error_messages={ 'required': "Enter a brief description for this barrier" }, ) is_summary_sensitive = YesNoBooleanField( label="Does the summary contain OFFICIAL-SENSITIVE information?", error_messages={ "required": ("Indicate if summary contains OFFICIAL-SENSITIVE information or not" ) }, ) next_steps_summary = forms.CharField( label="What steps will be taken to resolve the barrier?", help_text="Include all your agreed team actions.", required=False, )
class ArchiveAssessmentBaseForm(APIFormMixin, forms.Form): are_you_sure = YesNoBooleanField( label="Are you sure you want to archive this assessment?", error_messages={"required": "Enter yes or no"}, ) archived_reason = forms.CharField( label="Why are you archiving this assessment? (optional)", widget=forms.Textarea, max_length=500, required=False, ) def archive_assessment(self): raise NotImplementedError def save(self): if self.cleaned_data.get("are_you_sure") is True: self.archive_assessment()
class UpdateEconomicAssessmentEligibilityForm(APIFormMixin, forms.Form): economic_assessment_eligibility = YesNoBooleanField( label="Is the barrier eligible for an initial economic assessment?", error_messages={ "required": ("Select yes if the barrier is eligible for an initial economic assessment" ) }, ) economic_assessment_eligibility_summary = forms.CharField( label= "Why is this barrier not eligible for an initial economic assessment?", help_text="Please explain why this barrier is not eligible", max_length=1500, widget=forms.Textarea, required=False, ) def clean(self): cleaned_data = super().clean() economic_assessment_eligibility = cleaned_data.get( "economic_assessment_eligibility") economic_assessment_eligibility_summary = cleaned_data.get( "economic_assessment_eligibility_summary") if economic_assessment_eligibility is False: if not economic_assessment_eligibility_summary: self.add_error( "economic_assessment_eligibility_summary", "Enter why this barrier is not eligible", ) else: cleaned_data["economic_assessment_eligibility_summary"] = "" def save(self): client = MarketAccessAPIClient(self.token) client.barriers.patch( id=self.id, economic_assessment_eligibility=self. cleaned_data["economic_assessment_eligibility"], economic_assessment_eligibility_summary=self. cleaned_data["economic_assessment_eligibility_summary"], )
class PublicEligibilityForm(APIFormMixin, forms.Form): public_eligibility = YesNoBooleanField( label="Does this barrier meet the criteria to be made public?", choices=( ("yes", "Allowed, it can be viewed by the public"), ("no", "Not allowed"), ), error_messages={"required": "Enter yes or no"}, ) allowed_summary = forms.CharField( label="Why is it allowed to be public? (optional)", widget=forms.Textarea, max_length=250, required=False, error_messages={ "max_length": "Public eligibility summary should be %(limit_value)d characters or fewer", }, ) not_allowed_summary = forms.CharField( label="Why is it not allowed to be public? (optional)", widget=forms.Textarea, max_length=250, required=False, error_messages={ "max_length": "Public eligibility summary should be %(limit_value)d characters or fewer", }, ) def get_summary(self): if self.cleaned_data.get("public_eligibility") is True: return self.cleaned_data.get("allowed_summary") elif self.cleaned_data.get("public_eligibility") is False: return self.cleaned_data.get("not_allowed_summary") return "" def save(self): client = MarketAccessAPIClient(self.token) client.barriers.patch( id=self.id, public_eligibility=self.cleaned_data.get("public_eligibility"), public_eligibility_summary=self.get_summary(), )
class UpdateBarrierSummaryForm(APIFormMixin, forms.Form): summary = forms.CharField( label="Give us a summary of the barrier and how you found out about it", widget=forms.Textarea, error_messages={ "required": "Enter a brief description for this barrier" }, ) is_summary_sensitive = YesNoBooleanField( label="Does the summary contain OFFICIAL-SENSITIVE information?", error_messages={ "required": ("Indicate if summary contains OFFICIAL-SENSITIVE information or not" ) }, ) def save(self): client = MarketAccessAPIClient(self.token) client.barriers.patch( id=self.id, summary=self.cleaned_data["summary"], is_summary_sensitive=self.cleaned_data["is_summary_sensitive"], )