Beispiel #1
0
    def __delete_home_childcare_addresses(app_id):
        """
        Deletes childcare addresses that are the same as the home childcare address in all address fields.
        :param app_id: Applicant's id
        :return: None
        """
        nanny_actions = NannyGatewayActions()

        home_address_record = nanny_actions.read('applicant-home-address', params={'application_id': app_id}).record

        home_address_filter = {
            'application_id': app_id,
            'street_line1': home_address_record['street_line1'] if home_address_record['street_line1'] else "",
            'street_line2': home_address_record['street_line2'] if home_address_record['street_line2'] else "",
            'town': home_address_record['town'] if home_address_record['town'] else "",
            'county': home_address_record['county'] if home_address_record['county'] else "",
            'country': home_address_record['country'] if home_address_record['country'] else "",
            'postcode': home_address_record['postcode'] if home_address_record['postcode'] else ""
        }

        home_childcare_address_response = nanny_actions.list('childcare-address', params=home_address_filter)

        if home_childcare_address_response.status_code == 200:
            home_childcare_address_list = home_childcare_address_response.record

            for address in home_childcare_address_list:
                nanny_actions.delete('childcare-address', params={'childcare_address_id': address['childcare_address_id']})
    def __init__(self, *args, **kwargs):
        """
        Method to configure the initialisation of the childcare address postcode search
        :param args: arguments passed to the form
        :param kwargs: keyword arguments passed to the form, e.g. application ID
        """

        # extract the application id from the 'initial' or 'data' dictionaries.
        if 'id' in kwargs['initial']:
            self.application_id_local = kwargs['initial']['id']
        elif 'data' in kwargs and 'id' in kwargs['data']:
            self.application_id_local = kwargs['data']['id']

        # extract the childcare address id from the 'initial' dictionary.
        if 'childcare_address_id' in kwargs['initial']:
            self.childcare_address_id = kwargs['initial'][
                'childcare_address_id']

        super(ChildcareAddressForm, self).__init__(*args, **kwargs)

        # If information was previously entered, display it on the form
        postcode = None
        if 'childcare_address_id' in self:
            response = NannyGatewayActions().list(
                'childcare-address',
                params={'childcare_address_id': self.childcare_address_id})
            if response.status_code == 200:
                postcode = response.record[0]['postcode']
            self.pk = self.childcare_address_id

        self.fields['postcode'].initial = postcode
        self.field_list = ['postcode']
    def get_context_data(self):
        context = dict()
        application_id = app_id_finder(self.request)
        insurance_record = NannyGatewayActions().read('insurance-cover',
                                                      params={
                                                          'application_id':
                                                          application_id
                                                      }).record

        insurance_row = Row('public_liability',
                            'Do you have public liability insurance?',
                            insurance_record['public_liability'],
                            'insurance:Public-Liability',
                            "answer to having public liability insurance")

        insurance_summary_table = Table(application_id)
        insurance_summary_table.row_list = [
            insurance_row,
        ]
        insurance_summary_table.get_errors()

        context['table_list'] = [insurance_summary_table]
        context['application_id'] = application_id
        context['page_title'] = 'Check your answers: insurance cover'

        context['id'] = self.request.GET['id']
        return context
Beispiel #4
0
    def get_initial(self):
        """
        Get initial defines the initial data for the form instance that is to be rendered on the page
        :return: a dictionary mapping form field names, to values of the correct type
        """
        initial = super().get_initial()

        application_id = app_id_finder(self.request)

        response = NannyGatewayActions().read(
            "applicant-personal-details",
            params={"application_id": application_id})
        if response.status_code == 200:
            personal_details_record = response.record
        elif response.status_code == 404:
            return initial

        if personal_details_record["title"] in settings.TITLE_OPTIONS:
            initial["title"] = personal_details_record["title"]
        else:
            initial["title"] = "Other"
            initial["other_title"] = personal_details_record["title"]
        initial["first_name"] = personal_details_record["first_name"]
        initial["middle_names"] = personal_details_record["middle_names"]
        initial["last_name"] = personal_details_record["last_name"]
        # If there has yet to be an entry for the model associated with the form, then no population necessary

        return initial
Beispiel #5
0
    def get_initial(self):
        """
        Get initial defines the initial data for the form instance that is to be rendered on the page
        :return: a dictionary mapping form field names, to values of the correct type
        """
        initial = super().get_initial()

        application_id = app_id_finder(self.request)

        response = NannyGatewayActions().read(
            "applicant-personal-details",
            params={"application_id": application_id})
        if response.status_code == 200:
            personal_details_record = response.record
        elif response.status_code == 404:
            return initial

        try:
            initial["date_of_birth"] = datetime.datetime.strptime(
                personal_details_record["date_of_birth"], "%Y-%m-%d")
        except TypeError:
            initial["date_of_birth"] = None

        # If there has yet to be an entry for the model associated with the form, then no population necessary

        return initial
    def __init__(self, *args, **kwargs):
        """
        Method to configure the initialisation of the manual entry form for childcare addresses
        :param args: arguments passed to the form
        :param kwargs: keyword arguments passed to the form, e.g. application ID
        """
        if 'id' in kwargs['initial']:
            self.application_id_local = kwargs['initial']['id']
        elif 'data' in kwargs and 'id' in kwargs['data']:
            self.application_id_local = kwargs['data']['id']

        if 'childcare_address_id' in kwargs['initial']:
            self.childcare_address_id = kwargs['initial'][
                'childcare_address_id']

        super(ChildcareAddressManualForm, self).__init__(*args, **kwargs)

        if hasattr(self, 'childcare_address_id'):
            response = NannyGatewayActions().list(
                'childcare-address',
                params={'childcare_address_id': self.childcare_address_id})
            if response.status_code == 200:
                record = response.record[0]
                self.fields['street_line1'].initial = record['street_line1']
                self.fields['street_line2'].initial = record['street_line2']
                self.fields['town'].initial = record['town']
                self.fields['county'].initial = record['county']
                self.fields['postcode'].initial = record['postcode']
                self.pk = self.childcare_address_id
                self.field_list = [
                    'street_line1', 'street_line2', 'town', 'county',
                    'postcode'
                ]
    def form_valid(self, form):
        application_id = self.request.GET['id']
        record = IdentityGatewayActions().read('user',
                                               params={
                                                   'application_id':
                                                   application_id
                                               }).record
        record['sms_resend_attempts'] = 0
        record['email_expiry_date'] = 0
        IdentityGatewayActions().put('user', params=record)
        response = login_redirect_helper.redirect_by_status(
            record['application_id'])
        CustomAuthenticationHandler.create_session(response,
                                                   {'email': record['email']})

        # Update last accessed time when successfully signed in
        nanny_actions = NannyGatewayActions()
        app_response = nanny_actions.read(
            'application', params={'application_id': application_id})
        if app_response.status_code == 200 and hasattr(app_response, 'record'):
            # application might not exist yet, if user signed out before completing contact details task
            application = app_response.record
            application['date_last_accessed'] = datetime.datetime.now()
            application['application_expiry_email_sent'] = False
            nanny_actions.put('application', application)

        return response
Beispiel #8
0
    def post(self, request, *args, **kwargs):
        """
        Handles POST requests for lookup form
        """
        self.get_context_data()
        form = self.get_form()

        # Clear incomplete addresses from the API record
        app_id = self.request.GET["id"]

        delete_action = ([
            k for k, v in self.request.POST.items() if k.startswith("delete-")
        ] + [None])[0]

        if delete_action is not None:

            # param name in the form 'delete-[id]'
            delete_id = delete_action[len("delete-"):]

            # id will be blank if user is removing the new, empty form. Can safely ignore
            if delete_id != "":
                response = NannyGatewayActions().delete(
                    "previous-name", params={"previous_name_id": delete_id})

            # redirect back to page
            return self._previous_names_page_redirect(app_id, show_extra=False)

        formset = self._previous_names_page_formset(data=self.request.POST)

        return self.form_valid(formset)
Beispiel #9
0
    def form_valid(self, form):
        application_id = self.request.GET['id']
        criminal_checks_record = {'application_id': application_id}
        dbs_number = form.cleaned_data['dbs_number']
        response = read_dbs(dbs_number)
        if response.status_code == 200:
            dbs_record = getattr(read_dbs(dbs_number), 'record', None)
            if dbs_record is not None:
                info = dbs_record['certificate_information']
                if dbs_within_three_months(dbs_record):
                    if not info in NO_ADDITIONAL_CERTIFICATE_INFORMATION:
                        self.success_url = 'dbs:Post-DBS-Certificate'
                    else:
                        self.success_url = 'dbs:Criminal-Record-Check-Summary-View'
                    criminal_checks_record['within_three_months'] = True
                else:
                    self.success_url = 'dbs:DBS-Type-View'
                    criminal_checks_record['within_three_months'] = False
                criminal_checks_record['dbs_number'] = dbs_number
                criminal_checks_record['is_ofsted_dbs'] = True
                criminal_checks_record['certificate_information'] = info
        else:
            self.success_url = 'dbs:DBS-Type-View'
            criminal_checks_record['dbs_number'] = dbs_number
            criminal_checks_record['is_ofsted_dbs'] = False

        NannyGatewayActions().put('dbs-check', params=criminal_checks_record)

        return super(CapitaDBSDetailsFormView, self).form_valid(form)
Beispiel #10
0
    def __get_errors_many_to_one_handler(arc_comments_response, row):
        """
        Handler for many-to-one arc comment relations.
        :param arc_comments_response: A nanny_gateway response for ArcComments.
            Assumed that the response.record contains multiple dictionaries.
        :param row: The current table row.
        :return: An error string, or None.
        """
        if row.row_pk in [None, ""]:
            raise ValueError(
                "row_pk must not be left blank when a many_to_one error relation exists."
            )

        arc_comments_record_list = arc_comments_response.record

        for ac_record in arc_comments_record_list:
            endpoint = ac_record["endpoint_name"]

            endpoint_pk = Table.__get_endpoint_pk(endpoint)
            endpoint_response = NannyGatewayActions().read(
                endpoint, params={endpoint_pk: row.row_pk})

            if endpoint_response.status_code == 200:
                if ac_record.get("table_pk") == row.row_pk:
                    if bool(ac_record["flagged"]):
                        return ac_record["comment"]
                    else:
                        return None

        # If this return is reached, no arc_comment was found for this row.
        return None
Beispiel #11
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data()
     application_id = app_id_finder(self.request)
     context['id'] = application_id
     application_record = NannyGatewayActions().read('application', params={'application_id': application_id}).record
     context['personal_details_status'] = application_record['personal_details_status']
     return context
    def post(self, request, *args, **kwargs):
        application_id = self.request.POST.get('id')
        delete_action = ([
            k for k, v in self.request.POST.items() if k.startswith('remove-')
        ] + [None])[0]
        if delete_action is not None:

            # param name in the form 'remove-[id]'
            delete_id = delete_action[len('remove-'):]

            # id will be blank if user is removing the new, empty form. Can safely ignore
            if delete_id != '':
                response = NannyGatewayActions().delete(
                    'previous-address',
                    params={'previous_address_id': delete_id})
            return HttpResponseRedirect(
                build_url(
                    "personal-details:Personal-Details-Previous-Address-Summary",
                    get={'id': application_id}))

        form = self.get_form()
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Beispiel #13
0
    def check_flags(self, application_id, endpoint=None, pk=None):
        """
        For a class to call this method it must set self.pk - this is the primary key of the entry against which the
        ArcComments table is being filtered.
        This method simply checks whether or not a field is flagged, raising a validation error if it is.
        """
        for field in self.fields:
            arc_comments_filter = NannyGatewayActions().list(
                "arc-comments",
                params={
                    "application_id": application_id,
                    "field_name": field,
                    "endpoint_name": self.get_endpoint(endpoint),
                    "table_pk": self.get_pk(pk),
                },
            )

            if arc_comments_filter.status_code == 200 and bool(
                    arc_comments_filter.record[0]["flagged"]):
                comment = arc_comments_filter.record[0]["comment"]
                self.cleaned_data = ""
                self.add_error(field, forms.ValidationError(comment))
            # If fields cannot be flagged individually, check for flags using the bespoke methods.
            else:
                self.if_name(application_id, field, True, pk)
                self.if_home_address(application_id, field, True, endpoint, pk)
Beispiel #14
0
    def get_initial(self):
        """
        Get initial defines the initial data for the form instance that is to be rendered on the page
        :return: a dictionary mapping form field names, to values of the correct type
        """
        initial = super().get_initial()

        application_id = app_id_finder(self.request)

        responses_list = NannyGatewayActions().list(
            "previous-name", params={"application_id": application_id})

        if responses_list.status_code == 200:
            personal_details_record = responses_list.record[0]

            initial["first_name"] = personal_details_record["first_name"]
            initial["middle_names"] = personal_details_record["middle_names"]
            initial["last_name"] = personal_details_record["last_name"]
            initial["end_date"] = datetime.datetime(
                personal_details_record["end_year"],
                personal_details_record["end_month"],
                personal_details_record["end_day"],
            )

            if len(responses_list.record) > 1:
                initial["previous_name"] = True
            else:
                initial["previous_name"] = False
        # If there has yet to be an entry for the model associated with the form, then no population necessary

        return initial
    def get_security_question_form(self):
        """
        Grab the security question for a given applicant, depending upon the status of their application.
        """
        application_id = self.request.GET['id']
        app_record = NannyGatewayActions().read('application',
                                                params={
                                                    'application_id':
                                                    application_id
                                                }).record
        personal_details_record = IdentityGatewayActions().read(
            'user', params={
                'application_id': application_id
            }).record

        if app_record is None:
            form = MobileNumberSecurityQuestionForm
        elif app_record['dbs_status'] == 'COMPLETED':
            form = DBSSecurityQuestionForm
        elif app_record['personal_details_status'] == 'COMPLETED':
            form = PersonalDetailsSecurityQuestionForm
        elif len(personal_details_record['mobile_number']) != 0:
            form = MobileNumberSecurityQuestionForm

        self.form_class = form

        return form
def generate_expiring_applications_list_nanny_applications():
    """
    Method to return a list of nanny applications that have not been accessed in the last 55 days
    """

    threshold_datetime = datetime.now() - timedelta(
        days=settings.WARNING_EMAIL_THRESHOLD_DAYS)
    log.debug('nanny drafts not accessed for {} days (before {})'.format(
        settings.WARNING_EMAIL_THRESHOLD_DAYS, threshold_datetime))
    response = NannyGatewayActions().list('application',
                                          params={
                                              "application_status":
                                              'DRAFTING',
                                              "last_accessed_before":
                                              threshold_datetime.isoformat()
                                          })
    if response.status_code == 200:
        expiring_applications = response.record
    elif response.status_code == 404:
        expiring_applications = []
    else:
        raise ConnectionError(response.status_code)

    log.debug('found {}'.format(len(expiring_applications)))
    return expiring_applications
    def __nullify_answers(app_id):
        """
        Function to nullify any relevant workflow answers.
        :param app_id: Applicant's id
        :return: None
        """
        nanny_actions = NannyGatewayActions()

        # Nullify answer to 'Will you work and live at the same address?'
        applicant_home_address_response = NannyGatewayActions().read(
            'applicant-home-address', params={'application_id': app_id})

        if applicant_home_address_response.status_code == 200:
            put_record = applicant_home_address_response.record
            put_record['childcare_address'] = 'null'

            nanny_actions.put('applicant-home-address', params=put_record)
Beispiel #18
0
    def get_initial(self):
        initial = super().get_initial()

        application_id = app_id_finder(self.request)
        api_response = NannyGatewayActions().read('dbs-check', params={'application_id': application_id})
        dbs_record = api_response.record
        initial['dbs_number'] = dbs_record['dbs_number']
        return initial
Beispiel #19
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data()
     application_id = app_id_finder(self.request)
     context["id"] = application_id
     application_record = NannyGatewayActions().read(
         "application", params={"application_id": application_id}).record
     context["suitability_details_status"] = application_record["suitability_details_status"]
     return context
 def remove_previous_address(self, pk):
     """
     :param pk: the missing gap id for the address gap that is to be removed.
     :return: None
     """
     NannyGatewayActions().delete(
         "missing-address-gap", params={"missing_address_gap_id": pk}
     )
Beispiel #21
0
    def form_valid(self, form):
        application_id = app_id_finder(self.request)
        application_record = NannyGatewayActions().read(
            "application", params={"application_id": application_id}).record
        if application_record["suitability_details_status"] not in (
            "COMPLETED",
            "FLAGGED",
        ):
            application_record["suitability_details_status"] = "IN_PROGRESS"
        NannyGatewayActions().put("application", params=application_record)

        answer = form.cleaned_data["other_suitability_circumstances"]
        data_dict = {
            "application_id": application_id,
            "other_suitability_circumstances": answer,
        }
        if answer == "False":
            data_dict["suitability_circumstances_details"] = ""
            arc_comments_response = NannyGatewayActions().list(
            "arc-comments", params={"application_id": application_id, 'field_name': 'suitability_circumstances_details', 'endpoint_name': 'suitability'})
            if arc_comments_response.status_code == 200:
                arc_record = arc_comments_response.record[0]
                arc_record['flagged'] = False
                NannyGatewayActions().put('arc-comments', params=arc_record)

        existing_record = NannyGatewayActions().read(
            "suitability", params={"application_id": application_id})
        if existing_record.status_code == 200:
            NannyGatewayActions().patch("suitability", params=data_dict)
        elif existing_record.status_code == 404:
            NannyGatewayActions().create("suitability", params=data_dict)
        return super().form_valid(form)
Beispiel #22
0
    def form_valid(self, form):
        application_id = app_id_finder(self.request)
        application_record = (
            NannyGatewayActions()
            .read("application", params={"application_id": application_id})
            .record
        )
        applicant_name = NannyGatewayActions().list('applicant-personal-details', params={'application_id': application_id})
        applicant_name_record = applicant_name.record[0]
        if not applicant_name_record['name_start_day']:
            applicant_name_record['name_start_day'] = 1
            NannyGatewayActions().put('applicant-personal-details', params=applicant_name_record)

        if (
            application_record["personal_details_status"] != "COMPLETED"
            or application_record["personal_details_status"] != "FLAGGED"
        ):
            application_record["personal_details_status"] = "IN_PROGRESS"
        NannyGatewayActions().put("application", params=application_record)

        data_dict = {
            "application_id": application_id,
        }

        existing_record = NannyGatewayActions().read(
            "applicant-personal-details", params={"application_id": application_id}
        )
        if existing_record.status_code == 200:
            NannyGatewayActions().patch("applicant-personal-details", params=data_dict)
        elif existing_record.status_code == 404:
            NannyGatewayActions().create("applicant-personal-details", params=data_dict)

        return super().form_valid(form)
Beispiel #23
0
    def get_initial(self):
        initial = super(PersonalDetailHomeAddressView, self).get_initial()
        app_id = app_id_finder(self.request)
        api_response = NannyGatewayActions().read('applicant-home-address', params={'application_id': app_id})

        if api_response.status_code == 200:
            initial['postcode'] = api_response.record['postcode']

        return initial
Beispiel #24
0
 def get_initial(self):
     initial = super().get_initial()
     app_id = app_id_finder(self.request)
     api_response = NannyGatewayActions().read(
         'declaration', params={'application_id': app_id})
     if api_response.status_code == 200:
         record = api_response.record
         initial['confirm_declare'] = record['confirm_declare']
     return initial
 def post(self, request):
     application_id = app_id_finder(request)
     NannyGatewayActions().patch('application',
                                 params={
                                     'application_id': application_id,
                                     'dbs_status': 'IN_PROGRESS'
                                 })
     return HttpResponseRedirect(
         build_url(self.success_url_name, get={'id': application_id}))
Beispiel #26
0
    def get_initial(self):
        initial = super(PersonalDetailSelectAddressView, self).get_initial()
        app_id = app_id_finder(self.request)
        api_response = NannyGatewayActions().read('applicant-home-address', params={'application_id': app_id})

        if api_response.status_code == 200:
            postcode = api_response.record['postcode']
            initial['postcode'] = postcode
            initial['id'] = app_id
            address_choices = AddressHelper.create_address_lookup_list(postcode)
            initial['choices'] = address_choices

        pd_api_response = NannyGatewayActions().read('applicant-personal-details', params={'application_id': app_id})
        if pd_api_response.status_code == 200:
            record = pd_api_response.record
            if record['moved_in_date'] is not None:
                initial['moved_in_date'] = initial['moved_in_date'] = datetime.strptime(record['moved_in_date'], '%Y-%m-%d').date()

        return initial
Beispiel #27
0
    def post(self, request):
        """ Handle POST request. Create session for user if the request does not return a record. If a record exists,
        a check is completed on if the user has completed the personal details task. If they have, they are presented
        with the task-list, if not they are presented with the personal details task"""

        application_id = request.GET['id']
        nanny_api_response = NannyGatewayActions().read(
            'application', params={'application_id': application_id})

        if nanny_api_response.status_code == 200:
            application_record = NannyGatewayActions().read(
                'application', params={
                    'application_id': application_id
                }).record

            # This differentiates between a new user and one who has signed out during the personal details task.
            if application_record['personal_details_status'] == 'COMPLETED':
                response = HttpResponseRedirect(
                    build_url('Task-List', get={'id': application_id}))
                return response

            else:
                return HttpResponseRedirect(
                    build_url('personal-details:Personal-Details-Name',
                              get={'id': application_id}))

        if nanny_api_response.status_code == 404:
            NannyGatewayActions().create('application',
                                         params={
                                             'application_id':
                                             application_id,
                                             'application_status':
                                             'DRAFTING',
                                             'login_details_status':
                                             'COMPLETED',
                                             'date_last_accessed':
                                             datetime.datetime.now(),
                                             'application_expiry_email_sent':
                                             False
                                         })
            return HttpResponseRedirect(
                build_url('personal-details:Personal-Details-Name',
                          get={'id': application_id}))
    def get_initial(self):
        initial = super().get_initial()
        app_id = app_id_finder(self.request)
        initial['id'] = app_id

        api_response = NannyGatewayActions().list('previous-address',
                                                  params={
                                                      'person_id': app_id,
                                                      'order': '0'
                                                  })
        if api_response.status_code == 200:
            initial['postcode'] = api_response.record[0]['postcode']

        crc_api_response = NannyGatewayActions().read(
            "dbs-check", params={'application_id': app_id})
        if crc_api_response.status_code == 200:
            initial['lived_abroad'] = crc_api_response.record['lived_abroad']

        return initial
Beispiel #29
0
    def get_context_data(self, **kwargs):
        """
        Grab the redirect url to the task list, the application id, and the full dbs record (render order occurs in
        the template)
        :param kwargs:
        :return:
        """
        context = dict()
        application_id = app_id_finder(self.request)
        dbs_record = NannyGatewayActions().read('dbs-check',
                                                params={
                                                    'application_id':
                                                    application_id
                                                }).record

        dbs_page_link = 'dbs:Capita-DBS-Details-View'

        dbs_number_row = Row('dbs_number', 'DBS certificate number',
                             dbs_record['dbs_number'], dbs_page_link,
                             'DBS certificate number')
        dbs_enhanced_check_row = Row(
            'enhanced_check',
            mark_safe(
                'Is it an enhanced check with barred lists as well as being for a <a '
                'href="https://www.gov.uk/government/publications/dbs-home-based'
                '-positions-guide/home-based-position-definition-and-guidance" '
                'target="_blank">home-based childcare role</a>?'),
            dbs_record['enhanced_check'], 'dbs:DBS-Type-View',
            'answer to DBS being enhanced and home-based')
        dbs_update_service_row = Row(
            'on_dbs_update_service', 'Are you on the DBS Update Service?',
            dbs_record['on_dbs_update_service'], 'dbs:DBS-Type-View',
            "answer to being on the DBS Update Service")
        if dbs_record['is_ofsted_dbs']:
            if dbs_record['within_three_months']:
                row_list = [dbs_number_row]
            else:
                row_list = [dbs_number_row, dbs_update_service_row]
        elif not dbs_record['is_ofsted_dbs']:
            row_list = [
                dbs_number_row, dbs_enhanced_check_row, dbs_update_service_row
            ]

        dbs_summary_table = Table(application_id)
        dbs_summary_table.row_list = row_list
        dbs_summary_table.get_errors()
        table_list = [dbs_summary_table]

        context['id'] = self.request.GET['id']
        context['table_list'] = table_list
        context['application_id'] = application_id
        context['page_title'] = 'Check your answers: criminal record checks'

        return context
Beispiel #30
0
    def form_valid(self, form):
        application_id = app_id_finder(self.request)
        postcode = form.cleaned_data['postcode']

        api_response = NannyGatewayActions().read('applicant-home-address', params={'application_id': application_id})
        if api_response.status_code == 200:
            address_record = api_response.record
            address_record['postcode'] = postcode
            NannyGatewayActions().put('applicant-home-address', params=address_record)
        else:
            personal_details = NannyGatewayActions().read('applicant-personal-details', params={'application_id': application_id}).record
            NannyGatewayActions().create(
                'applicant-home-address',
                params={
                     'application_id': application_id,
                     'personal_detail_id': personal_details['personal_detail_id'],
                     'postcode': postcode,
                 })

        return super().form_valid(form)