def get_thank_you(schema, session_store): thank_you = ThankYou(schema, session_store) if request.method == "POST": confirmation_email = thank_you.confirmation_email if not confirmation_email: return redirect(url_for(".get_thank_you")) if confirmation_email.form.validate(): return redirect( url_for( ".confirm_confirmation_email", email=confirmation_email.get_url_safe_serialized_email(), )) logger.info( "email validation error", error_message=str(confirmation_email.form.errors["email"][0]), ) show_feedback_call_to_action = Feedback.is_enabled( schema) and not Feedback.is_limit_reached(session_store.session_data) return render_template( template=thank_you.template, content={ **thank_you.get_context(), "show_feedback_call_to_action": show_feedback_call_to_action, }, survey_id=schema.json["survey_id"], page_title=thank_you.get_page_title(), )
def send_confirmation_email(session_store, schema): try: confirmation_email = ConfirmationEmail( session_store, schema, serialised_email=request.args.get("email")) except (ConfirmationEmailLimitReached, ConfirmationEmailNotEnabled): return redirect(url_for(".get_thank_you")) if request.method == "POST": if confirmation_email.form.validate(): return redirect( url_for( ".confirm_confirmation_email", email=confirmation_email.get_url_safe_serialized_email(), )) logger.info( "email validation error", error_message=str(confirmation_email.form.errors["email"][0]), ) return render_template( template="confirmation-email", content=confirmation_email.get_context(), hide_sign_out_button=True, page_title=confirmation_email.get_page_title(), )
def individual_response_text_message_confirmation(schema, questionnaire_store): language_code = get_session_store().session_data.language_code individual_response_handler = IndividualResponseHandler( schema=schema, questionnaire_store=questionnaire_store, language=language_code, request_args=request.args, form_data=request.form, list_item_id=None, ) if request.method == "POST": return redirect(url_for("questionnaire.get_questionnaire")) try: mobile_number = url_safe_serializer().loads(request.args["mobile_number"]) except BadSignature: raise BadRequest return render_template( template="individual_response/confirmation-text-message", mobile_number=mobile_number, page_title=individual_response_handler.page_title( lazy_gettext("An individual access code has been sent by text") ), )
def get_confirmation_email_sent(session_store, schema): if not session_store.session_data.confirmation_email_count: raise NotFound try: email = url_safe_serializer().loads(request.args["email"]) except BadSignature: raise BadRequest show_send_another_email_guidance = not ConfirmationEmail.is_limit_reached( session_store.session_data) show_feedback_call_to_action = Feedback.is_enabled( schema) and not Feedback.is_limit_reached(session_store.session_data) return render_template( template="confirmation-email-sent", content={ "email": email, "send_confirmation_email_url": url_for("post_submission.send_confirmation_email"), "hide_sign_out_button": False, "show_send_another_email_guidance": show_send_another_email_guidance, "sign_out_url": url_for("session.get_sign_out"), "show_feedback_call_to_action": show_feedback_call_to_action, }, )
def handle_get(self): individual_section_first_block_id = self._schema.get_first_block_id_for_section( self.individual_section_id) if self._request_args.get("journey") == "remove-person": previous_location_url = url_for( "questionnaire.block", list_name=self._list_name, list_item_id=self._list_item_id, block_id=self._schema.get_remove_block_id_for_list( self._list_name), ) elif self._list_item_id: previous_location_url = url_for( "questionnaire.block", list_name=self._list_name, list_item_id=self._list_item_id, block_id=individual_section_first_block_id, ) else: previous_location_url = url_for("questionnaire.get_questionnaire") return render_template( template="individual_response/interstitial", language=self._language, previous_location_url=previous_location_url, page_title=self.page_title( lazy_gettext( "Cannot answer questions for others in your household")), )
def submit_questionnaire( schema: QuestionnaireSchema, questionnaire_store: QuestionnaireStore) -> Union[Response, str]: try: submit_questionnaire_handler = SubmitQuestionnaireHandler( schema, questionnaire_store, flask_babel.get_locale().language) except InvalidLocationException: raise NotFound if not submit_questionnaire_handler.router.is_questionnaire_complete: return redirect(submit_questionnaire_handler.router. get_first_incomplete_location_in_questionnaire_url()) if request.method == "POST": submit_questionnaire_handler.handle_post() return redirect(url_for("post_submission.get_thank_you")) context = submit_questionnaire_handler.get_context() return render_template( submit_questionnaire_handler.template, content=context, page_title=context["title"], previous_location_url=submit_questionnaire_handler. get_previous_location_url(), )
def _render_error_page(status_code, template=None, **kwargs): handle_language() template = template or status_code return ( render_template(template=f"errors/{template}", **kwargs), status_code, )
def _render_error_page(status_code, template=None): handle_language() template = template or status_code using_edge = request.user_agent.browser == "edge" return ( render_template(template=f"errors/{template}", using_edge=using_edge), status_code, )
def handle_get(self): return render_template( template="individual_response/interstitial", language=self._language, previous_location_url=self._get_previous_location_url(), next_location_url=self._get_next_location_url(), page_title=self.page_title( lazy_gettext( "Cannot answer questions for others in your household")), )
def internal_server_error(exception=None): try: log_exception(exception, 500) return _render_error_page(500) except Exception: # pylint:disable=broad-except logger.exception( "an error has occurred when rendering 500 error", url=request.url, status_code=500, ) return render_template(template="errors/500"), 500
def get_feedback_sent(session_store): if not session_store.session_data.feedback_count: raise NotFound return render_template( template="feedback-sent", content={ "hide_sign_out_button": False, "sign_out_url": url_for("session.get_sign_out"), }, )
def _render_page(template, context, previous_location_url, schema, page_title): session_timeout = get_session_timeout_in_seconds(schema) return render_template( template=template, content=context, previous_location_url=previous_location_url, session_timeout=session_timeout, legal_basis=schema.json.get("legal_basis"), page_title=page_title, )
def handle_get(self): self._answers = { "individual-response-change-answer": self.request_separate_census_option } return render_template( "individual_response/question", language=self._language, content=self.get_context(), previous_location_url=url_for("questionnaire.get_questionnaire"), show_contact_us_guidance=True, )
def handle_get(self): previous_location_url = url_for( "individual_response.individual_response_how", list_item_id=self._list_item_id, journey=self._request_args.get("journey"), ) return render_template( "individual_response/question", language=self._language, content=self.get_context(), previous_location_url=previous_location_url, page_title=self.page_title(lazy_gettext("Confirm address")), )
def send_feedback(schema, session_store): try: feedback = Feedback(schema, session_store, form_data=request.form) except FeedbackNotEnabled: raise NotFound if request.method == "POST" and feedback.form.validate(): feedback.handle_post() return redirect(url_for(".get_feedback_sent")) return render_template( template="feedback", content=feedback.get_context(), page_title=feedback.get_page_title(), )
def handle_get(self): if len(self.non_primary_people_names) > 1: previous_location_url = url_for( "individual_response.request_individual_response", journey=self._request_args.get("journey"), ) return render_template( "individual_response/question", language=self._language, content=self.get_context(), previous_location_url=previous_location_url, page_title=self.page_title(lazy_gettext("Separate Census")), ) raise NotFound
def handle_get(self): if "mobile_number" in self._request_args: mobile_number = url_safe_serializer().loads( self._request_args["mobile_number"] ) self._answers = {"individual-response-enter-number-answer": mobile_number} previous_location_url = url_for( "individual_response.individual_response_how", list_item_id=self._list_item_id, journey=self._request_args.get("journey"), ) return render_template( "individual_response/question", language=self._language, content=self.get_context(), previous_location_url=previous_location_url, page_title=self.page_title(lazy_gettext("Mobile number")), )
def get_questionnaire(schema, questionnaire_store): router = Router( schema, questionnaire_store.answer_store, questionnaire_store.list_store, questionnaire_store.progress_store, questionnaire_store.metadata, questionnaire_store.response_metadata, ) if not router.can_access_hub(): redirect_location_url = ( router.get_first_incomplete_location_in_questionnaire_url() ) return redirect(redirect_location_url) if request.method == "POST": if router.is_questionnaire_complete: submission_handler = SubmissionHandler( schema, questionnaire_store, router.full_routing_path() ) submission_handler.submit_questionnaire() return redirect(url_for("post_submission.get_thank_you")) return redirect(router.get_first_incomplete_location_in_questionnaire_url()) hub_context = HubContext( language=flask_babel.get_locale().language, schema=schema, answer_store=questionnaire_store.answer_store, list_store=questionnaire_store.list_store, progress_store=questionnaire_store.progress_store, metadata=questionnaire_store.metadata, response_metadata=questionnaire_store.response_metadata, ) context = hub_context( survey_complete=router.is_questionnaire_complete, enabled_section_ids=router.enabled_section_ids, ) return render_template( "hub", content=context, page_title=context["title"], )
def confirm_confirmation_email(session_store, schema): try: confirm_email = ConfirmEmail(schema, session_store, request.args["email"], form_data=request.form) except (ConfirmationEmailLimitReached, ConfirmationEmailNotEnabled): return redirect(url_for(".get_thank_you")) if request.method == "POST" and confirm_email.form.validate(): confirm_email.handle_post() next_location_url = confirm_email.get_next_location_url() return redirect(next_location_url) return render_template( template="confirm-email", content=confirm_email.get_context(), page_title=confirm_email.get_page_title(), )
def get_confirmation_email_sent(): if not get_session_store().session_data.confirmation_email_count: raise NotFound email = URLParamSerializer().loads(request.args.get("email")) return render_template( template="confirmation-email-sent", content={ "email": email, "send_confirmation_email_url": url_for("post_submission.send_confirmation_email"), "hide_signout_button": False, "show_send_another_email_guidance": not ConfirmationEmail.is_limit_reached(), "sign_out_url": url_for("session.get_sign_out"), }, )
def individual_response_post_address_confirmation(schema, questionnaire_store): language_code = get_session_store().session_data.language_code individual_response_handler = IndividualResponseHandler( schema=schema, questionnaire_store=questionnaire_store, language=language_code, request_args=request.args, form_data=request.form, list_item_id=None, ) if request.method == "POST": return redirect(url_for("questionnaire.get_questionnaire")) return render_template( template="individual_response/confirmation-post", display_address=questionnaire_store.metadata.get("display_address"), page_title=individual_response_handler.page_title( lazy_gettext("An individual access code has been sent by post") ), )
def get_questionnaire(schema, questionnaire_store): router = Router( schema, questionnaire_store.answer_store, questionnaire_store.list_store, questionnaire_store.progress_store, questionnaire_store.metadata, ) if not router.can_access_hub(): redirect_location_url = router.get_first_incomplete_location_in_survey_url( ) return redirect(redirect_location_url) if request.method == "POST": if router.is_survey_complete(): submission_handler = SubmissionHandler(schema, questionnaire_store, router.full_routing_path()) submission_handler.submit_questionnaire() return redirect(url_for("post_submission.get_thank_you")) return redirect(router.get_first_incomplete_location_in_survey_url()) language_code = get_session_store().session_data.language_code hub = HubContext( language=language_code, schema=schema, answer_store=questionnaire_store.answer_store, list_store=questionnaire_store.list_store, progress_store=questionnaire_store.progress_store, metadata=questionnaire_store.metadata, ) hub_context = hub.get_context(router.is_survey_complete(), router.enabled_section_ids) return render_template("hub", content=hub_context, page_title=hub_context["title"])
def handle_get(self): if self._request_args.get("journey") == "hub": if len(self._list_model.non_primary_people) == 1: previous_location_url = url_for( "individual_response.request_individual_response", journey=self._request_args.get("journey"), ) else: previous_location_url = url_for( "individual_response.individual_response_who", journey=self._request_args.get("journey"), ) elif self._request_args.get("journey") == "change": previous_location_url = url_for( "individual_response.individual_response_change", list_item_id=self._list_item_id, ) elif self._request_args.get("journey") == "remove-person": previous_location_url = url_for( "individual_response.request_individual_response", list_item_id=self._list_item_id, journey="remove-person", ) else: previous_location_url = url_for( "individual_response.request_individual_response", list_item_id=self._list_item_id, ) return render_template( "individual_response/question", language=self._language, content=self.get_context(), previous_location_url=previous_location_url, show_contact_us_guidance=True, page_title=self.page_title( lazy_gettext("Send individual access code")), )
def send_confirmation_email(): if not get_session_store().session_data.confirmation_email_count: raise NotFound try: confirmation_email = ConfirmationEmail() except ConfirmationEmailLimitReached: return redirect(url_for("post_submission.get_thank_you")) if request.method == "POST" and confirmation_email.form.validate(): confirmation_email.handle_post() return redirect( url_for( "post_submission.get_confirmation_email_sent", email=confirmation_email.get_url_safe_serialized_email(), )) return render_template( template="confirmation-email", content=confirmation_email.get_context(), hide_signout_button=True, page_title=confirmation_email.get_page_title(), )
def get_thank_you(schema): thank_you = ThankYou(schema) if request.method == "POST": if not thank_you.confirmation_email: raise NotFound confirmation_email = thank_you.confirmation_email if confirmation_email.form.validate(): confirmation_email.handle_post() return redirect( url_for( "post_submission.get_confirmation_email_sent", email=confirmation_email.get_url_safe_serialized_email(), )) return render_template( template=thank_you.template, content=thank_you.get_context(), survey_id=schema.json["survey_id"], page_title=thank_you.get_page_title(), )
def get_session_expired(): # Check for GET as we don't want to log out for HEAD requests if request.method == "GET": logout_user() return render_template("errors/session-expired")
def get_rendered_html(self) -> str: return render_template( template="view-submitted-response", content=self.get_context(), page_title=self.get_page_title(), )
def accessibility(): return render_template("static/accessibility")
def get_signed_out(): return render_template(template="signed-out")
def privacy(): return render_template("static/privacy")