def post_originating_authority_page():
    authority = request.form.get('authority-search-field')

    local_authority_service = LocalAuthorityService(current_app.config)
    response = local_authority_service.get_organisations()
    authorities = list(map(lambda org: org.get('title'), response))

    current_app.logger.info("Running validation")
    validation_errors = AuthorityValidator.validate(authority, authorities)

    if validation_errors.errors:
        current_app.logger.warning("Validation errors occurred")
        return render_template(
            'originating_authority.html',
            authorities=authorities,
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            submit_url=url_for(
                'add_land_charge.post_originating_authority_page')), 400

    ReviewRouter.update_edited_field('originating_authority', authority)
    g.session.add_charge_state.originating_authority = authority
    g.session.commit()

    return redirect(
        ReviewRouter.get_redirect_url('add_land_charge.get_charge_type'))
예제 #2
0
def post_charge_description():
    current_app.logger.info("Endpoint called with charge-description = '{}'".format(
        request.form.get('charge-description', '').strip()
    ))

    if g.session.add_charge_state is None:
        current_app.logger.info('Redirecting to: {}'.format(url_for('add_land_charge.new')))
        return redirect(url_for('add_land_charge.new'))

    description = request.form['charge-description'].strip()

    current_app.logger.info('Running validation')
    validation_errors = ChargeDescriptionValidator.validate(description)

    if validation_errors.errors:
        current_app.logger.warning('Validation errors occurred')
        return render_template('charge_description.html',
                               validation_errors=validation_errors.errors,
                               validation_summary_heading=validation_errors.summary_heading_text,
                               data=description,
                               submit_url=url_for('add_land_charge.post_charge_description')), 400

    current_app.logger.info('Updating session object')
    if has_value_changed(g.session.add_charge_state.supplementary_information, description):
        ReviewRouter.update_edited_field('supplementary_information', description)
        g.session.add_charge_state.supplementary_information = description
        g.session.commit()

    return redirect(ReviewRouter.get_redirect_url('add_land_charge.get_review'))
    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_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_redirect_route_set_and_pass_non_matching_field(
            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)
예제 #5
0
def post_expiry():
    current_app.logger.info(
        "Endpoint called with does_charge_expire = '{}', charge_expiry_day = '{}', "
        "charge_expiry_month = '{}', charge_expiry_year = '{}'".format(
            request.form.get('does_charge_expire', ''),
            request.form.get('charge_expiry_day', ''),
            request.form.get('charge_expiry_month', ''),
            request.form.get('charge_expiry_year', '')))

    if g.session.add_charge_state is None:
        current_app.logger.info('Redirecting to: {}'.format(
            url_for('add_land_charge.new')))
        return redirect(url_for('add_land_charge.new'))

    does_charge_expire = request.form.get('does_charge_expire', '')
    charge_expiry_day = request.form.get('charge_expiry_day', '')
    charge_expiry_month = request.form.get('charge_expiry_month', '')
    charge_expiry_year = request.form.get('charge_expiry_year', '')

    validation_errors = ExpiryValidator.validate(does_charge_expire,
                                                 charge_expiry_day,
                                                 charge_expiry_month,
                                                 charge_expiry_year)

    current_app.logger.info('Running validation')
    if validation_errors.errors:
        current_app.logger.warning('Validation errors occurred')
        return render_template(
            'expiry.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            submit_url=url_for('add_land_charge.post_expiry'),
            request_body=request.form), 400

    if does_charge_expire == 'yes':
        charge_expiry_date = None

        if (charge_expiry_day and charge_expiry_month and charge_expiry_year):
            charge_expiry_date = date(int(charge_expiry_year),
                                      int(charge_expiry_month),
                                      int(charge_expiry_day))

        current_app.logger.info('Update expiry_date in session object')
        ReviewRouter.update_edited_field('expiry_date', charge_expiry_date)

        g.session.add_charge_state.expiry_date = charge_expiry_date
        g.session.commit()
    else:
        g.session.add_charge_state.expiry_date = None
        g.session.commit()

    return redirect(
        ReviewRouter.get_redirect_url('add_land_charge.get_additional_info'))
예제 #6
0
def post_financial_charge_details():
    current_app.logger.info(
        "Endpoint called with amount-secured = '%s', interest-paid-indicator = '%s', "
        "interest-rate = '%s' and ", request.form.get('amount-secured', ''),
        request.form.get('interest-paid-indicator', ''),
        request.form.get('interest-rate', ''))
    if g.session.add_charge_state is None:
        current_app.logger.info("Redirecting to: %s",
                                url_for("add_land_charge.new"))
        return redirect(url_for("add_land_charge.new"))

    amount_secured = NumberConverter.format_number_string(request.form.get(
        'amount-secured', ''),
                                                          leading_char='£',
                                                          force_two_dp=True)

    interest_paid_indicator = request.form.get('interest-paid-indicator', '')
    interest_rate = request.form.get('interest-rate', '')

    current_app.logger.info("Running validation")
    validation_errors = FinancialChargeDetailsValidator.validate(
        amount_secured, interest_paid_indicator, interest_rate)
    if validation_errors.errors:
        current_app.logger.warning("Validation errors occurred")
        return render_template(
            'financial_charge_details.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            request_body=request.form,
            submit_url=url_for(
                'add_land_charge.post_financial_charge_details')), 400

    if interest_paid_indicator == "No":
        interest_rate = NO_INTEREST_IS_PAYABLE
        current_app.logger.info(
            "Updating session object with charge amount: '%s' and no interest rate",
            amount_secured)

    ReviewRouter.update_edited_field('amount_originally_secured',
                                     amount_secured)
    ReviewRouter.update_edited_field('rate_of_interest', interest_rate)

    g.session.add_charge_state.amount_originally_secured = amount_secured
    g.session.add_charge_state.rate_of_interest = interest_rate
    g.session.commit()

    current_app.logger.info(
        "Redirecting to next step: %s",
        ReviewRouter.get_redirect_url("add_land_charge.get_charge_date"))
    return redirect(
        ReviewRouter.get_redirect_url("add_land_charge.get_charge_date"))
def post_location():
    current_app.logger.info('Endpoint called')

    features = None
    selected_address = None

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

    if request.form.get('selected-address'):
        selected_address = json.loads(request.form['selected-address'])

    current_app.logger.info('Running validation')
    validation_errors = AddLocationMapValidator.validate(features)

    if validation_errors.errors:
        current_app.logger.warning('Validation errors occurred')
        return render_template(
            'location.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            information=features,
            submit_url=url_for('add_land_charge.post_location')), 400

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

    select_address_param = False
    add_extent_anywhere_redirect_url = 'add_land_charge.get_address_for_charge'

    if selected_address and select_address_valid(selected_address):
        g.session.previously_selected_address = selected_address
        select_address_param = True
        add_extent_anywhere_redirect_url = 'add_land_charge.get_address_confirmation'

    g.session.add_charge_state.geometry = features
    g.session.commit()

    if Permissions.add_extent_anywhere not in g.session.user.permissions:
        extent = build_extents_from_features(features)
        result = LocalAuthorityService(
            current_app.config).get_authorities_by_extent(extent)

        if should_show_confirmation_warning(result):
            return redirect(
                url_for('add_land_charge.get_location_confirmation',
                        address_selected=select_address_param))

    return redirect(
        ReviewRouter.get_redirect_url(add_extent_anywhere_redirect_url))
예제 #8
0
def post_land_compensation_owned():
    current_app.logger.info(
        "Endpoint called with land-owned-indicator = '%s' and land-owned-other = '%s'",
        request.form.get('land-owned-indicator', ''),
        request.form.get('land-owned-other', ''))
    if g.session.add_charge_state is None:
        current_app.logger.info("Redirecting to: %s",
                                url_for("add_land_charge.new"))
        return redirect(url_for("add_land_charge.new"))

    land_owned_indicator = request.form.get('land-owned-indicator', '')
    land_owned_other = request.form.get('land-owned-other', '').strip()

    current_app.logger.info("Running validation")
    validation_errors = LandCompensationOwnedValidator.validate(
        land_owned_indicator, land_owned_other)
    if validation_errors.errors:
        current_app.logger.warning("Validation errors occurred")
        return render_template(
            'land_compensation_owned.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            request_body=request.form,
            submit_url=url_for(
                'add_land_charge.post_land_compensation_owned')), 400

    if land_owned_indicator == "Other":
        ReviewRouter.update_edited_field('land_capacity_description',
                                         land_owned_other)
        g.session.add_charge_state.land_capacity_description = land_owned_other
    else:
        ReviewRouter.update_edited_field('land_capacity_description',
                                         land_owned_indicator)
        g.session.add_charge_state.land_capacity_description = land_owned_indicator

    current_app.logger.info(
        "Updating session object with land capacity description: '%s'",
        g.session.add_charge_state.land_capacity_description)

    g.session.commit()

    current_app.logger.info(
        "Redirecting to next step: %s",
        ReviewRouter.get_redirect_url("add_land_charge.get_charge_date"))
    return redirect(
        ReviewRouter.get_redirect_url("add_land_charge.get_charge_date"))
def post_additional_info():
    current_app.logger.info(
        "Endpoint called with additional-info = '{}', reference = '{}'".format(
            request.form.get('additional-info', '').strip(),
            request.form.get('reference', '').strip()))

    if g.session.add_charge_state is None:
        current_app.logger.info('Redirecting to: {}'.format(
            url_for('add_land_charge.new')))
        return redirect(url_for('add_land_charge.new'))

    information = request.form['additional-info'].strip()
    reference = request.form['reference'].strip()

    current_app.logger.info('Running validation')
    validation_errors = AddChargeAdditionalInfoValidator.validate(
        information, reference)

    if validation_errors.errors:
        current_app.logger.warning('Validation errors occurred')
        return render_template(
            'additional_info.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            information=information,
            submit_url=url_for('add_land_charge.post_additional_info'),
            source_information_list=get_source_information_list(),
            reference=reference), 400

    current_app.logger.info('Updating session object')
    ReviewRouter.update_edited_field('further_information_location',
                                     information)
    if has_value_changed(
            g.session.add_charge_state.further_information_reference,
            reference):
        ReviewRouter.update_edited_field('further_information_reference',
                                         reference)
        g.session.add_charge_state.further_information_reference = reference

    g.session.add_charge_state.further_information_location = information
    g.session.commit()

    return redirect(
        ReviewRouter.get_redirect_url(
            'add_land_charge.get_charge_description'))
예제 #10
0
def post_address_for_charge():
    if g.session.add_charge_state is None:
        current_app.logger.info('Redirecting to: {}'.format(url_for('add_land_charge.new')))
        return redirect(url_for('add_land_charge.new'))

    has_address = request.form.get('has-address')
    charge_geographic_description = request.form.get('charge-geographic-description')
    selected_address = request.form.get('selected-address')

    current_app.logger.info("Running validation")
    validation_errors = AddressForChargeValidator.validate(has_address, selected_address,
                                                           charge_geographic_description)
    if validation_errors.errors:
        current_app.logger.warning("Validation errors occurred")
        return render_template(
            'address_for_charge.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            has_address=has_address,
            charge_geographic_description=charge_geographic_description,
            submit_url=url_for('add_land_charge.post_address_for_charge')
        ), 400

    if selected_address:
        selected_address = json.loads(selected_address)
        charge_address = AddressConverter.to_charge_address(selected_address)
        ReviewRouter.update_edited_field('charge_address', charge_address)
        ReviewRouter.remove_edited_field('charge_geographic_description')
        g.session.add_charge_state.charge_address = charge_address
        g.session.add_charge_state.charge_geographic_description = None
        g.session.previously_selected_address = None
    elif charge_geographic_description:
        ReviewRouter.update_edited_field('charge_geographic_description', charge_geographic_description)
        ReviewRouter.remove_edited_field('charge_address')
        g.session.add_charge_state.charge_geographic_description = charge_geographic_description
        g.session.add_charge_state.charge_address = None
        g.session.previously_selected_address = None
    g.session.commit()

    return redirect(ReviewRouter.get_redirect_url('add_land_charge.get_expiry'))
예제 #11
0
def post_land_compensation_payment():
    land_compensation_paid = NumberConverter.format_number_string(
        request.form.get('land-compensation-paid'),
        leading_char='£',
        force_two_dp=True)

    amount_of_compensation = NumberConverter.format_number_string(
        request.form.get('amount-of-compensation'),
        leading_char='£',
        force_two_dp=True)
    land_compensation_amount_type = request.form.get(
        'land-compensation-amount-type')

    current_app.logger.info(
        "Endpoint called with land-compensation-paid = '%s', land-compensation-amount-type = '%s'",
        land_compensation_paid, amount_of_compensation,
        land_compensation_amount_type)
    if g.session.add_charge_state is None:
        current_app.logger.info("Redirecting to: %s",
                                url_for("add_land_charge.new"))
        return redirect(url_for("add_land_charge.new"))

    current_app.logger.info("Running validation")
    validation_errors = LandCompensationPaymentValidator.validate(
        land_compensation_paid, amount_of_compensation, False)
    if validation_errors.errors:
        current_app.logger.warning("Validation errors occurred")
        return render_template(
            'land_compensation_payment.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            request_body=request.form,
            submit_url=url_for(
                'add_land_charge.post_land_compensation_payment')), 400

    current_app.logger.info(
        "Updating session object with land compensation amount: '%s' and \
                            land compensation amount type: '%s'",
        land_compensation_paid, land_compensation_amount_type)

    ReviewRouter.update_edited_field('land_compensation_paid',
                                     land_compensation_paid)
    ReviewRouter.update_edited_field('amount_of_compensation',
                                     amount_of_compensation)
    ReviewRouter.update_edited_field('land_compensation_amount_type',
                                     land_compensation_amount_type)

    g.session.add_charge_state.land_compensation_paid = land_compensation_paid
    g.session.add_charge_state.amount_of_compensation = amount_of_compensation
    g.session.add_charge_state.land_compensation_amount_type = land_compensation_amount_type
    g.session.commit()

    # Force the flow to go to the next page if that value is not in the session (in case browser back button is used)
    if not g.session.add_charge_state.land_capacity_description:
        next_url = url_for("add_land_charge.get_land_compensation_owned")
    else:
        next_url = ReviewRouter.get_redirect_url(
            "add_land_charge.get_land_compensation_owned")
    current_app.logger.info("Redirecting to next step: %s", next_url)
    return redirect(next_url)
def post_land_compensation_land_sold():
    current_app.logger.info(
        "Endpoint called with land-sold-description = '%s' and land-works-particulars = '%s'",
        request.form.get('land-sold-description', ''),
        request.form.get('land-works-particulars', ''))

    if g.session.add_charge_state is None:
        current_app.logger.info('Redirecting to: {}'.format(
            url_for('add_land_charge.new')))
        return redirect(url_for('add_land_charge.new'))

    description = request.form['land-sold-description'].strip()
    land_works_particulars = request.form['land-works-particulars'].strip()

    current_app.logger.info('Running validation')
    validation_errors = LandCompensationLandSoldValidator.validate(
        description, land_works_particulars)

    if validation_errors.errors:
        current_app.logger.warning('Validation errors occurred')
        return render_template(
            'land_compensation_land_sold.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            request_body=request.form,
            submit_url=url_for(
                'add_land_charge.post_land_compensation_land_sold')), 400

    current_app.logger.info('Updating session object')
    ReviewRouter.update_edited_field('land_sold_description', description)
    g.session.add_charge_state.land_sold_description = description

    ReviewRouter.update_edited_field('land_works_particulars',
                                     land_works_particulars)
    g.session.add_charge_state.land_works_particulars = land_works_particulars

    g.session.commit()

    return redirect(
        ReviewRouter.get_redirect_url('add_land_charge.get_charge_date'))
예제 #13
0
def post_charge_date():
    current_app.logger.info(
        "Endpoint called with date-day = '{}', date-month = '{}', date-year = '{}'"
        .format(request.form.get('date-day', ''),
                request.form.get('date-month', ''),
                request.form.get('date-year', '')))

    if g.session.add_charge_state is None:
        current_app.logger.info('Redirecting to: {}'.format(
            url_for('add_land_charge.new')))
        return redirect(url_for('add_land_charge.new'))

    day = request.form.get('date-day')
    month = request.form.get('date-month')
    year = request.form.get('date-year')

    current_app.logger.info('Running validation')
    validation_errors = ChargeDateValidator.validate(day, month, year)
    if validation_errors.errors:
        charge_date = {'day': day, 'month': month, 'year': year}
        current_app.logger.warning('Validation errors occurred')
        return render_template(
            'charge_date.html',
            validation_errors=validation_errors.errors,
            validation_summary_heading=validation_errors.summary_heading_text,
            submit_url=url_for('add_land_charge.post_charge_date'),
            request=request,
            date=charge_date)

    if year and month and day:
        current_app.logger.info('Updating session object')
        charge_creation_date = date(int(year), int(month), int(day))

        ReviewRouter.update_edited_field('charge_creation_date',
                                         charge_creation_date)
        g.session.add_charge_state.charge_creation_date = charge_creation_date
        g.session.commit()

    return redirect(
        ReviewRouter.get_redirect_url('add_land_charge.get_location'))