def assign_sites(request): return Form( title=strings.users.AssignToSitesForm.ASSIGN_USER_TO_SITES_TITLE, description=strings.users.AssignToSitesForm. ASSIGN_USER_TO_SITES_DESCRIPTION, questions=[ Checkboxes(name="sites[]", options=get_sites(request, request.session["organisation"], True)) ], default_button_name=strings.SAVE, )
def sites_form(request, application_type): exclude = "" if application_type in [CaseTypes.SITL, CaseTypes.SICL, CaseTypes.OICL]: exclude = "GB" return Form( title="Select locations", questions=[ Filter(), Checkboxes( name="sites[]", options=get_sites(request, request.session["organisation"], True, False, exclude), filterable=True, ), ], default_button_name=generic.SAVE_AND_CONTINUE, )
def add_user_form(request): return Form( title=strings.users.AddUserForm.USER_ADD_TITLE, questions=[ TextInput(title=strings.users.AddUserForm.USER_EMAIL_QUESTION, name="email"), Select( name="role", options=get_roles(request, request.session["organisation"], True), title=strings.users.AddUserForm.USER_ROLE_QUESTION, include_default_select=False, ), Checkboxes( title=strings.users.AddUserForm.ASSIGN_USER_QUESTION, name="sites[]", options=get_sites(request, request.session["organisation"], True), ), ], back_link=BackLink( strings.users.AddUserForm.USER_ADD_FORM_BACK_TO_USERS, reverse_lazy("organisation:members:members")), )
def new_site_forms(request): is_individual = request.POST.get("type") == "individual" in_uk = request.POST.get("location", "").lower() == "united_kingdom" sites = [] if request.POST.get("address.postcode"): sites = get_sites(request, request.session["organisation"], postcode=request.POST.get("address.postcode", "")) return FormGroup([ Form( caption="Step 1 of 4", title=AddSiteForm.WhereIsYourSiteBased.TITLE, description=AddSiteForm.WhereIsYourSiteBased.DESCRIPTION, questions=[ RadioButtons( name="location", options=[ Option( key="united_kingdom", value=AddSiteForm.WhereIsYourSiteBased.IN_THE_UK, description=AddSiteForm.WhereIsYourSiteBased. IN_THE_UK_DESCRIPTION, ), Option( key="abroad", value=AddSiteForm.WhereIsYourSiteBased. OUTSIDE_THE_UK, description=AddSiteForm.WhereIsYourSiteBased. OUTSIDE_THE_UK_DESCRIPTION, ), ], ) ], default_button_name=generic.CONTINUE, back_link=BackLink(AddSiteForm.BACK_LINK, reverse_lazy("organisation:sites:sites")), ), Form( caption="Step 2 of 4", title=AddSiteForm.Details.TITLE, description=AddSiteForm.Details.DESCRIPTION, questions=[ TextInput(title=AddSiteForm.Details.NAME, name="name"), Heading( conditional(in_uk, AddSiteForm.Details.ADDRESS_HEADER_UK, AddSiteForm.Details.ADDRESS_HEADER_ABROAD), HeadingStyle.M, ), *conditional( in_uk, address_questions(None, is_individual), foreign_address_questions( is_individual, get_countries(request, True, ["GB"])), ), HiddenField("validate_only", True), ], default_button_name=generic.CONTINUE, ), conditional( sites, Form( title=AddSiteForm.Postcode.TITLE, description=AddSiteForm.Postcode.DESCRIPTION.format(", ".join( site["name"] for site in sites)), questions=[ HiddenField(name="are_you_sure", value=None), RadioButtons( name="are_you_sure", title=AddSiteForm.Postcode.CONTROL_TITLE, options=[ Option(True, AddSiteForm.Postcode.YES), Option(False, AddSiteForm.Postcode.NO), ], ), ], default_button_name=generic.CONTINUE, ), ), site_records_location(request, in_uk), Form( caption="Step 4 of 4", title=AddSiteForm.AssignUsers.TITLE, description=AddSiteForm.AssignUsers.DESCRIPTION, questions=[ Filter(placeholder=AddSiteForm.AssignUsers.FILTER), Checkboxes( name="users[]", options=get_organisation_users( request, request.session["organisation"], { "disable_pagination": True, "exclude_permission": Permissions.ADMINISTER_SITES }, True, ), filterable=True, ), HiddenField("validate_only", False), ], default_button_name=generic.SAVE_AND_CONTINUE, ), ])
def site_records_location(request, in_uk=True, is_editing=False): return Form( caption="" if is_editing else "Step 3 of 4", title=strings.sites.AddSiteForm.SiteRecords.SiteInUK.TITLE if in_uk else strings.sites.AddSiteForm.SiteRecords.SiteNotInUK.TITLE, description=strings.sites.AddSiteForm.SiteRecords.DESCRIPTION, questions=[ *conditional( in_uk, [ RadioButtons( name="site_records_stored_here", options=[ Option(key=True, value=strings.YES), Option( key=False, value=strings.sites.AddSiteForm.SiteRecords. SiteInUK.NO_RECORDS_HELD_ELSEWHERE, components=[ RadioButtons( name="site_records_located_at", options=[ Option(site["id"], site["name"]) for site in filter_sites_in_the_uk( get_sites( request, request. session["organisation"])) ], ), Label( 'If the site isn\'t listed, you need to <a id="site-dashboard" href="' + str( reverse_lazy( "organisation:sites:sites")) + '" class="govuk-link govuk-link--no-visited-state">' + "add the site" + "</a> " + "from your account dashboard."), ], ), ], ), ], [ HiddenField("site_records_stored_here", False), Label( 'If the site isn\'t listed, you need to <a id="site-dashboard" href="' + str(reverse_lazy("organisation:sites:sites")) + '" class="govuk-link govuk-link--no-visited-state">' + "add the site" + "</a> " + "from your account dashboard."), RadioButtons( name="site_records_located_at", options=[ Option(site["id"], site["name"]) for site in filter_sites_in_the_uk( get_sites(request, request.session["organisation"])) ], ), ], ), HiddenField("validate_only", True), HiddenField("records_located_step", True), ], default_button_name=generic.CONTINUE, )
def get_additional_context(self): return { "sites": get_sites(self.request, self.organisation_id, get_total_users=True) }
def open_general_licence_forms(request, **kwargs): open_general_licence_type = OpenGeneralExportLicenceTypes.get_by_acronym( kwargs["ogl"]) control_list_entries = get_control_list_entries(request, True) countries = get_countries(request, True) selected_entry = request.POST.get("control_list_entry") selected_country = next((country.value for country in countries if country.key == request.POST.get("country")), "") open_general_licences = get_open_general_licences( request, convert_to_options=True, case_type=open_general_licence_type.id, control_list_entry=request.POST.get("control_list_entry"), country=request.POST.get("country"), status="active", ) sites = get_sites(request, request.session["organisation"], True) selected_open_general_licence = {} if request.POST.get("open_general_licence"): selected_open_general_licence = get_open_general_licence( request, request.POST.get("open_general_licence")) if open_general_licence_type.acronym == OpenGeneralExportLicenceTypes.open_general_export_licence.acronym: back_link_url = reverse("apply_for_a_licence:export_licence_questions") elif open_general_licence_type.acronym == OpenGeneralExportLicenceTypes.open_general_transhipment_licence.acronym: back_link_url = reverse("apply_for_a_licence:transhipment_questions") else: back_link_url = reverse( "apply_for_a_licence:trade_control_licence_questions") return FormGroup([ Form( title=OpenGeneralLicenceQuestions.ControlListEntry.TITLE, description=OpenGeneralLicenceQuestions.ControlListEntry. DESCRIPTION, questions=[ AutocompleteInput(name="control_list_entry", options=control_list_entries) ], default_button_name=generic.CONTINUE, back_link=BackLink(url=back_link_url), ), Form( title=OpenGeneralLicenceQuestions.Country.TITLE, description=OpenGeneralLicenceQuestions.Country.DESCRIPTION, questions=[AutocompleteInput(name="country", options=countries)], default_button_name=generic.CONTINUE, ), *conditional( open_general_licences, [ Form( title=OpenGeneralLicenceQuestions.OpenGeneralLicences. TITLE.format(open_general_licence_type.name.lower()), questions=[ Label( OpenGeneralLicenceQuestions.OpenGeneralLicences. DESCRIPTION.format( open_general_licence_type.name.lower(), selected_entry, selected_country)), Label(OpenGeneralLicenceQuestions.OpenGeneralLicences. HELP_TEXT), RadioButtons( name="open_general_licence", options=[ *open_general_licences, Option( "", OpenGeneralLicenceQuestions. OpenGeneralLicences.NONE_OF_THE_ABOVE, show_or=True, ), ], ), ], default_button_name=generic.CONTINUE, ) ], [ no_open_general_licence_form(open_general_licence_type, selected_entry, selected_country) ], ), conditional( selected_open_general_licence, Form( caption=conditional( selected_open_general_licence.get("registration_required"), OpenGeneralLicenceQuestions.OpenGeneralLicenceDetail. CAPTION, ), title=open_general_licence_type.name + " (" + selected_open_general_licence.get("name", "") + ")", questions=[ conditional( not selected_open_general_licence.get( "registration_required"), WarningBanner( "warning", OpenGeneralLicenceQuestions. OpenGeneralLicenceDetail.NO_REGISTRATION_REQUIRED. format(open_general_licence_type.name.lower()), ), ), HiddenField("application_type", open_general_licence_type.acronym.lower()), *conditional( selected_open_general_licence.get( "registration_required"), [ Heading( OpenGeneralLicenceQuestions. OpenGeneralLicenceDetail.Summary.HEADING, HeadingStyle.S), Custom( "components/ogl-step-list.html", data={ **selected_open_general_licence, "sites": sites }, ), Custom("components/ogl-warning.html"), Checkboxes( name="confirmation[]", options=[ Option( "read", OpenGeneralLicenceQuestions. Conditions.READ), Option( "comply", OpenGeneralLicenceQuestions. Conditions.COMPLY), ], ), ], [], ), ], buttons=[ conditional( selected_open_general_licence.get( "registration_required"), Button("Register", "submit"), ) ], ), no_open_general_licence_form(open_general_licence_type, selected_entry, selected_country), ), ])