Exemplo n.º 1
0
def post_applicant_info():
    address_form = request.form

    current_app.logger.info("Running validation")
    validation_error_builder = ApplicantInfoValidator.validate(address_form)

    if validation_error_builder.errors:
        current_app.logger.warning("Validation errors occurred")
        return render_template(
            'applicant_info.html',
            validation_errors=validation_error_builder.errors,
            validation_summary_heading=validation_error_builder.
            summary_heading_text,
            submit_url=url_for('add_lon.post_applicant_info'),
            country_list=get_sorted_countries(),
            request_body=request.form), 400

    applicant_address = AddressConverter.condense_address(address_form)
    applicant_name = address_form.get('applicant_name')

    current_app.logger.info("Updating session object")
    ReviewRouter.update_edited_field('applicant_name', applicant_name)
    ReviewRouter.update_edited_field('applicant_address', applicant_address)

    g.session.add_lon_charge_state.applicant_name = applicant_name
    g.session.add_lon_charge_state.applicant_address = applicant_address
    g.session.commit()

    return redirect(
        ReviewRouter.get_redirect_url('add_lon.get_dominant_building_info'))
    def test_update_edited_field_with_redirect_route_not_set(self):
        """Should not update edited_fields if the redirect_route in session is not set."""
        with main.app.test_request_context():
            self.build_session()
            g.session.add_lon_charge_state.charge_type = CHARGE_TYPE
            g.session.redirect_route = None

            ReviewRouter.update_edited_field('charge_type', CHARGE_TYPE)
            self.assertTrue(len(g.session.edited_fields) == 0)
    def test_update_edited_field_with_empty_session(self):
        """Should add an entry to the edited_fields if the given value does not match the value stored in session."""
        with main.app.test_request_context():
            self.build_session()
            g.session.redirect_route = REDIRECT_ROUTE

            ReviewRouter.update_edited_field('charge_type', CHARGE_TYPE)
            self.assertTrue(len(g.session.edited_fields) == 1)
            self.assertIn('charge_type', g.session.edited_fields)
    def test_update_edited_field_with_matching_field(self):
        """Should not add an entry to the edited_fields if the given value matches the value stored in session."""
        with main.app.test_request_context():
            self.build_session()
            g.session.add_lon_charge_state.charge_type = CHARGE_TYPE
            g.session.redirect_route = REDIRECT_ROUTE

            ReviewRouter.update_edited_field('charge_type', CHARGE_TYPE)
            self.assertTrue(len(g.session.edited_fields) == 0)
Exemplo n.º 5
0
def post_land_interest():
    if g.session.add_lon_charge_state is None:
        current_app.logger.info("Redirecting to: %s", url_for("add_lon.new"))
        return redirect(url_for("add_lon.new"))

    current_app.logger.info("Running validation")

    # Different validation and error messages are required for other instead of the existing options.
    land_interest = request.form.get("servient-land-interest-description")
    if land_interest == "Other":
        land_interest = request.form.get("servient-land-interest-detail")
        validation_error_builder = ValidationErrorBuilder()
        FieldValidator(land_interest, 'servient-land-interest-detail', 'Land Interest', validation_error_builder,
                       summary_message="There are errors on the page. Describe the interest in land",
                       inline_message="Explain how the person applying for the light obstruction notice "
                       "owns or uses the land") \
            .is_required()
        checked = "Other"
    else:
        validation_error_builder = ValidationErrorBuilder()
        FieldValidator(land_interest, 'servient-land-interest-description', 'Land Interest', validation_error_builder,
                       summary_message="Choose one",
                       inline_message="Choose one") \
            .is_required()
        checked = request.form.get("servient-land-interest-description")

    if validation_error_builder.errors:
        current_app.logger.warning("Validation errors occurred")
        return render_template(
            'lon_land_interest.html',
            submit_url=url_for("add_lon.post_land_interest"),
            validation_errors=validation_error_builder.errors,
            validation_summary_heading=validation_error_builder.
            summary_heading_text,
            checked=checked,
            request_body=land_interest), 400

    current_app.logger.info("Updating session object")
    ReviewRouter.update_edited_field('servient_land_interest_description',
                                     land_interest)

    g.session.add_lon_charge_state.servient_land_interest_description = land_interest
    g.session.commit()

    return redirect(
        ReviewRouter.get_redirect_url("add_lon.get_upload_lon_documents"))
Exemplo n.º 6
0
def post_dominant_building_extent():
    if g.session.add_lon_charge_state is None:
        current_app.logger.info("Redirecting to: %s", url_for("add_lon.new"))
        return redirect(url_for("add_lon.new"))

    information = None

    if 'saved-features' in request.form:
        information = json.loads(request.form['saved-features'].strip())

    current_app.logger.info("Running validation")
    validation_errors = AddLocationMapValidator.validate(information, "Draw the extent", "Draw the extent")

    if validation_errors.errors:
        current_app.logger.warning("Validation errors occurred")

        postcode_to_zoom = ''
        if g.session.add_lon_charge_state.charge_address:
            postcode_to_zoom = g.session.add_lon_charge_state.charge_address['postcode']

        return render_template(
            'dominant_building_extent.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            submit_url=url_for("add_lon.post_dominant_building_extent"),
            information=information,
            postcode=postcode_to_zoom
        ), 400

    current_app.logger.info("Updating session object")
    ReviewRouter.update_edited_field('geometry', information)

    g.session.add_lon_charge_state.geometry = information
    g.session.commit()

    return redirect(ReviewRouter.get_redirect_url("add_lon.get_land_interest"))
def update_lon_document_fields(upload_lon_documents_form):
    definitive_cert = "Definitive LON certificate"
    temporary_cert = "Temporary LON certificate"

    if definitive_cert in upload_lon_documents_form.getlist('certificate'):
        tribunal_definitive_certificate_date = datetime.date(
            int(upload_lon_documents_form.get('definitive_cert_year')),
            int(upload_lon_documents_form.get('definitive_cert_month')),
            int(upload_lon_documents_form.get('definitive_cert_day')))

        if tribunal_definitive_certificate_date:
            current_app.logger.info(
                "Update tribunal_definitive_certificate_date in session object"
            )
            ReviewRouter.update_edited_field(
                'tribunal_definitive_certificate_date',
                tribunal_definitive_certificate_date)
            g.session.add_lon_charge_state.tribunal_definitive_certificate_date = tribunal_definitive_certificate_date
            g.session.add_lon_charge_state.expiry_date = datetime.date.today(
            ) + relativedelta(years=+21)
    else:
        # Need this in case they are coming from review page and are removing an existing date by un-checking box
        ReviewRouter.remove_from_edited_fields(
            'tribunal_definitive_certificate_date')
        g.session.add_lon_charge_state.tribunal_definitive_certificate_date = None
        g.session.add_lon_charge_state.expiry_date = None

    if temporary_cert in upload_lon_documents_form.getlist('certificate'):
        tribunal_temporary_certificate_date = datetime.date(
            int(upload_lon_documents_form.get('temp_cert_year')),
            int(upload_lon_documents_form.get('temp_cert_month')),
            int(upload_lon_documents_form.get('temp_cert_day')))

        if tribunal_temporary_certificate_date:
            current_app.logger.info(
                "Update tribunal_temporary_certificate_date in session object")
            ReviewRouter.update_edited_field(
                'tribunal_temporary_certificate_date',
                tribunal_temporary_certificate_date)
            g.session.add_lon_charge_state.tribunal_temporary_certificate_date = tribunal_temporary_certificate_date

        tribunal_temporary_certificate_expiry_date = datetime.date(
            int(upload_lon_documents_form.get('temp_expiry_year')),
            int(upload_lon_documents_form.get('temp_expiry_month')),
            int(upload_lon_documents_form.get('temp_expiry_day')))

        if tribunal_temporary_certificate_expiry_date:
            current_app.logger.info(
                "Update tribunal_temporary_certificate_expiry_date in session object"
            )
            ReviewRouter.update_edited_field(
                'tribunal_temporary_certificate_expiry_date',
                tribunal_temporary_certificate_expiry_date)
            g.session.add_lon_charge_state.tribunal_temporary_certificate_expiry_date = \
                tribunal_temporary_certificate_expiry_date

    else:
        # Need this in case they are coming from review page and are removing an existing date by un-checking box
        ReviewRouter.remove_from_edited_fields(
            'tribunal_temporary_certificate_date')
        ReviewRouter.remove_from_edited_fields(
            'tribunal_temporary_certificate_expiry_date')
        g.session.add_lon_charge_state.tribunal_temporary_certificate_date = None
        g.session.add_lon_charge_state.tribunal_temporary_certificate_expiry_date = None