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
Пример #2
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
    def get_context_data(self):
        context = dict()
        application_id = self.request.GET['id']
        first_aid_response = NannyGatewayActions().read(
            'first-aid', params={'application_id': application_id})
        if first_aid_response.status_code == 200:
            first_aid_record = first_aid_response.record
            course_date = datetime.datetime.strptime(
                first_aid_record['course_date'], '%Y-%m-%d').date()
            formatted_course_date = course_date.strftime('%d/%m/%Y')

            organisation_row = Row('training_organisation',
                                   'Training organisation',
                                   first_aid_record['training_organisation'],
                                   'first-aid:Training-Details',
                                   "training organisation")
            course_title_row = Row('course_title', 'Title of training course',
                                   first_aid_record['course_title'],
                                   'first-aid:Training-Details',
                                   "course title")
            course_date_row = Row('course_date',
                                  'Date you completed the course',
                                  formatted_course_date,
                                  'first-aid:Training-Details',
                                  "course completion date")

            first_aid_table = Table(application_id)
            first_aid_table.row_list = [
                organisation_row, course_title_row, course_date_row
            ]
            first_aid_table.get_errors()

            context['table_list'] = [first_aid_table]
            context['application_id'] = application_id
            context['page_title'] = 'Check your answers: first aid training'
            context['link_url'] = build_url(self.success_url_name,
                                            get={'id': application_id})
            context['id'] = self.request.GET['id']
            context['first_aid_record'] = first_aid_record
        else:
            raise Exception("A matching first aid record couldn't be found.")
        return context
    def get_context_data(self):
        context = dict()
        application_id = self.request.GET['id']
        childcare_record = NannyGatewayActions().read('childcare-training',
                                                      params={
                                                          'application_id':
                                                          application_id
                                                      }).record

        level_2_training = childcare_record['level_2_training']
        common_core_training = childcare_record['common_core_training']

        if level_2_training and common_core_training:
            row_value = 'Childcare qualification (level 2 or higher) and training in common core skills'
        elif level_2_training:
            row_value = 'Childcare qualification (level 2 or higher)'
        else:
            row_value = 'Training in common core skills'

        childcare_training_row = Row(
            'childcare_training',
            'What type of childcare course have you completed?', row_value,
            'Type-Of-Childcare-Training',
            'type of childcare course you have completed')

        childcare_training_summary_table = Table(application_id)
        childcare_training_summary_table.row_list = [childcare_training_row]
        childcare_training_summary_table.get_errors()

        context['table_list'] = [childcare_training_summary_table]
        context['application_id'] = application_id
        context['id'] = application_id
        context['page_title'] = 'Check your answers: childcare training'

        context['record'] = childcare_record

        return context
Пример #5
0
    def get_context_data(self):
        context = dict()
        context["table_list"] = []
        application_id = app_id_finder(self.request)

        # Accessing various records holding the necessary data dictionaries for the rows in the summary tables
        personal_details_record = (NannyGatewayActions().read(
            "applicant-personal-details",
            params={
                "application_id": application_id
            }).record)

        dbs_record = (NannyGatewayActions().read("dbs-check",
                                                 params={
                                                     "application_id":
                                                     application_id
                                                 }).record)

        address_record = (NannyGatewayActions().read("applicant-home-address",
                                                     params={
                                                         "application_id":
                                                         application_id
                                                     }).record)

        previous_address_list = NannyGatewayActions().list(
            "previous-address", params={"person_id": application_id})

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

        address_gaps_list = NannyGatewayActions().list(
            "missing-address-gap", params={"application_id": application_id})

        # Assigning all data to variables for the rows in the data tables
        name = (personal_details_record["first_name"] + " " +
                personal_details_record["middle_names"] + " " +
                personal_details_record["last_name"])
        if previous_names_list.status_code == 200:
            previous_names_record = previous_names_list.record
            previous_names_record.sort(key=sort_func)
            birth_name_record = previous_names_record[0]
            birth_name = (birth_name_record["first_name"] + " " +
                          birth_name_record["middle_names"] + " " +
                          birth_name_record["last_name"])
            birth_name_start_date = datetime.datetime(
                birth_name_record["start_year"],
                birth_name_record["start_month"],
                birth_name_record["start_day"],
            )
            birth_name_start_datetime = birth_name_start_date.strftime(
                "%d %B %Y")
            birth_name_end_date = datetime.datetime(
                birth_name_record["end_year"],
                birth_name_record["end_month"],
                birth_name_record["end_day"],
            )
            birth_name_end_datetime = birth_name_end_date.strftime("%d %B %Y")
        elif previous_names_list.status_code == 404:
            previous_names_record = []
        else:
            raise Exception("Unknown response for previous names data request")
        lived_abroad = dbs_record["lived_abroad"]
        date_of_birth_datetime = datetime.datetime.strptime(
            personal_details_record["date_of_birth"], "%Y-%m-%d")
        date_of_birth = date_of_birth_datetime.strftime("%d %B %Y")
        address = AddressHelper.format_address(address_record, ", ")
        name_history = len(previous_names_record) >= 1
        if previous_address_list.status_code == 200:
            previous_address_record = previous_address_list.record
        elif previous_address_list.status_code == 404:
            previous_address_record = []
        else:
            raise Exception(
                "Unknown response for previous address data request")
        if address_gaps_list.status_code == 200:
            address_gaps_record = address_gaps_list.record
        elif address_gaps_list.status_code == 404:
            address_gaps_record = []
        else:
            raise Exception("Unknown response for address gap data request")

        # Producing all rows for data tables
        """
        Parameters for the Row() function from table_util
        
        data_name: The name of the field as stored in the database
        row_name: The name of the field as rendered on the template
        value: The value of the field
        back_link: The view which, when reversed, redirects to the page where the value is defined
        change_link_description: An optional change link textual description value
        error: The error associated with the field, empty by default, only populated on table.get_errors
        """

        title_row = Row(
            "title",
            "Title",
            personal_details_record["title"],
            "personal-details:Personal-Details-Name",
            "your title",
        )
        name_row = Row(
            "name",
            "Your name",
            name,
            "personal-details:Personal-Details-Name",
            "your name",
        )
        date_of_birth_row = Row(
            "date_of_birth",
            "Date of birth",
            date_of_birth,
            "personal-details:Personal-Details-Date-Of-Birth",
            "your date of birth",
        )
        home_address_row = Row(
            "home_address",
            "Your home address",
            address,
            "personal-details:Personal-Details-Manual-Address",
            "your home address",
        )
        lived_abroad_row = Row(
            "lived_abroad",
            "Have you lived outside of the UK in the last 5 years?",
            lived_abroad,
            "personal-details:Personal-Details-Lived-Abroad",
            "have you lived abroad in the last 5 years",
        )
        previous_names_row = Row(
            "known_by_other_names",
            "Have you previously been known by any other names?",
            name_history,
            "personal-details:Personal-Details-Name-History",
            "have you been know by any previous names",
        )
        if previous_names_list.status_code == 200:
            birth_name_row = Row(
                "name_history",
                "Birth name",
                birth_name,
                "personal-details:Personal-Details-Birth-Name",
                "your birth name",
            )
            birth_name_start_date_row = Row(
                "start_date",
                "Start date",
                birth_name_start_datetime,
                "personal-details:Personal-Details-Birth-Name",
                "date birth name was used from",
            )
            birth_name_end_date_row = Row(
                "end_date",
                "End date",
                birth_name_end_datetime,
                "personal-details:Personal-Details-Birth-Name",
                "date birth name was used until",
            )

        # Your name and date of birth table
        name_and_dob_table = Table(application_id)

        name_and_dob_table.title = "Your name and date of birth"
        name_and_dob_table.row_list = [
            title_row,
            name_row,
            date_of_birth_row,
            previous_names_row,
        ]
        name_and_dob_table.get_errors("applicant-personal-details")
        context["table_list"].append(name_and_dob_table)

        # Name history table
        if previous_names_list.status_code == 200:
            name_history_table = Table(application_id)

            name_history_table.title = "Name history"

            name_history_table.row_list = [
                birth_name_row,
                birth_name_start_date_row,
                birth_name_end_date_row,
            ]

            previous_names_record.sort(key=lambda x: datetime.datetime(
                x["start_year"], x["start_month"], x["start_day"]))

            for i, name in enumerate(previous_names_record[1:]):
                count = i + 1
                previous_name = (name["first_name"] + " " +
                                 name["middle_names"] + " " +
                                 name["last_name"])
                previous_name_row = Row(
                    "previous_names",
                    "Previous name {}".format(count),
                    previous_name,
                    "personal-details:Personal-Details-Previous-Names",
                    "previous name applicant has been known by",
                )
                name_history_table.row_list.append(previous_name_row)

                previous_name_start_date = datetime.datetime(
                    name["start_year"], name["start_month"], name["start_day"])
                previous_name_start_datetime = previous_name_start_date.strftime(
                    "%d %B %Y")
                previous_name_start_date_row = Row(
                    "start_date",
                    "Start date",
                    previous_name_start_datetime,
                    "personal-details:Personal-Details-Previous-Names",
                    "date name was used from",
                )
                name_history_table.row_list.append(
                    previous_name_start_date_row)

                previous_name_end_date = datetime.datetime(
                    name["end_year"], name["end_month"], name["end_day"])
                previous_name_end_datetime = previous_name_end_date.strftime(
                    "%d %B %Y")
                previous_name_end_date_row = Row(
                    "end_date",
                    "End date",
                    previous_name_end_datetime,
                    "personal-details:Personal-Details-Previous-Names",
                    "date name was used until",
                )
                name_history_table.row_list.append(previous_name_end_date_row)
            name_history_table.get_errors(
                endpoint="applicant-personal-details")
            name_history_flagged = False
            if name_history_table.row_list[0].error:
                name_history_flagged = True
            context['name_history_flagged'] = name_history_flagged
            context["table_list"].append(name_history_table)

        # Your home and childcare address table
        home_and_childcare_address_table = Table(application_id)

        home_and_childcare_address_table.title = "Your home address"

        # Older applications won't have this - only try to do stuff if the date exists
        if personal_details_record["moved_in_date"]:
            moved_in_date_datetime = datetime.datetime.strptime(
                personal_details_record["moved_in_date"], "%Y-%m-%d").date()
            moved_in_date = moved_in_date_datetime.strftime("%d %B %Y")

            moved_in_date_row = Row(
                "moved_in_date",
                "Moved in date",
                moved_in_date,
                "personal-details:Personal-Details-Manual-Address",
                "your current address moved in date",
            )
            home_and_childcare_address_table.row_list = [
                home_address_row,
                moved_in_date_row,
                lived_abroad_row,
            ]
        else:
            home_and_childcare_address_table.row_list = [
                home_address_row,
                lived_abroad_row,
            ]

        home_and_childcare_address_table.get_errors(
            ["applicant-personal-details", "applicant-home-address"])

        context["table_list"].append(home_and_childcare_address_table)
        address_history_table = None
        # Address history table
        if previous_address_list.status_code == 200:
            address_history_table = Table(application_id)

            address_history_table.title = "Address history"

            address_history_table.row_list = []

            previous_address_record.sort(key=lambda x: x["moved_in_date"])

            for i, address in enumerate(previous_address_record):
                count = i + 1
                previous_address = (address["street_line1"] + ", " +
                                    address["street_line2"] + ", " +
                                    address["town"] + ", " +
                                    address["postcode"])
                previous_address_row = Row(
                    "address_history" if i == 0 else 'previous_address',
                    "Previous address {}".format(count),
                    previous_address,
                    "personal-details:Personal-Details-Previous-Address-Change",
                    "previous addresses applicant has lived at",
                    row_pk=address["previous_address_id"],
                )
                address_history_table.row_list.append(previous_address_row)

                previous_address_moved_in_date = datetime.datetime.strptime(
                    address["moved_in_date"], "%Y-%m-%d")
                previous_address_moved_in_datetime = (
                    previous_address_moved_in_date.strftime("%d %B %Y"))
                previous_address_moved_in_row = Row(
                    "moved_in_date",
                    "Date you moved in",
                    previous_address_moved_in_datetime,
                    "personal-details:Personal-Details-Previous-Address-Change",
                    "date address was used from",
                    row_pk=address["previous_address_id"],
                )
                address_history_table.row_list.append(
                    previous_address_moved_in_row)

                previous_address_moved_out_date = datetime.datetime.strptime(
                    address["moved_out_date"], "%Y-%m-%d")
                previous_address_moved_out_datetime = (
                    previous_address_moved_out_date.strftime("%d %B %Y"))
                previous_address_moved_out_row = Row(
                    "moved_out_date",
                    "Date you moved out",
                    previous_address_moved_out_datetime,
                    "personal-details:Personal-Details-Previous-Address-Change",
                    "date address was used until",
                    row_pk=address["previous_address_id"],
                )
                address_history_table.row_list.append(
                    previous_address_moved_out_row)

        if address_gaps_list.status_code == 200:
            if not address_history_table:
                address_history_table = Table(application_id)
                address_history_table.title = "Address history"

                address_history_table.row_list = []
            address_gaps_record.sort(key=lambda x: datetime.datetime(
                x["moved_in_year"], x["moved_in_month"], x["moved_in_day"]))

            for i, gap in enumerate(address_gaps_record):
                count = i + 1
                address_gap = gap["gap_reason"]
                address_gap_row = Row(
                    "previous_address_gap",
                    "Previous address gap {}".format(count),
                    address_gap,
                    "personal-details:Personal-Details-Address-Gap-Change",
                    "gaps in the applicants previous address history",
                    row_pk=gap["missing_address_gap_id"],
                )
                address_history_table.row_list.append(address_gap_row)

                address_gap_start_date = datetime.datetime(
                    gap["moved_in_year"], gap["moved_in_month"],
                    gap["moved_in_day"])
                address_gap_start_datetime = address_gap_start_date.strftime(
                    "%d %B %Y")
                address_gap_start_date_row = Row(
                    "gap_start_date",
                    "Start date",
                    address_gap_start_datetime,
                    "personal-details:Personal-Details-Address-Gap-Change",
                    "beginning of gap in applicant's address history",
                    row_pk=gap["missing_address_gap_id"],
                )
                address_history_table.row_list.append(
                    address_gap_start_date_row)

                address_gap_end_date = datetime.datetime(
                    gap["moved_out_year"], gap["moved_out_month"],
                    gap["moved_out_day"])
                address_gap_end_datetime = address_gap_end_date.strftime(
                    "%d %B %Y")
                address_gap_end_date_row = Row(
                    "gap_end_date",
                    "End date",
                    address_gap_end_datetime,
                    "personal-details:Personal-Details-Address-Gap-Change",
                    "end of gap in applicant's address history",
                    row_pk=gap["missing_address_gap_id"],
                )
                address_history_table.row_list.append(address_gap_end_date_row)

        if address_history_table:
            address_history_table.get_errors("applicant-personal-details")
            context["table_list"].append(address_history_table)
            context[
                'address_history_flagged'] = True if address_history_table.row_list[
                    0].error else False

        # Building the remaining context dictionary
        context["id"] = application_id
        context["application_id"] = application_id
        context["page_title"] = "Check your answers: your personal details"
        return context
    def get_context_data(self):
        context = dict()

        application_id = self.request.GET['id']

        app_record = NannyGatewayActions().read('application',
                                                params={
                                                    'application_id':
                                                    application_id
                                                }).record

        if app_record['address_to_be_provided']:
            address_to_be_provided = 'Yes'
        else:
            address_to_be_provided = 'No'

        known_childcare_location_row = Row(
            'address_to_be_provided', 'Do you know where you\'ll be working?',
            address_to_be_provided, 'Childcare-Address-Where-You-Work',
            'answer to knowing where you\'ll be working')

        childcare_address_summary_table = Table(application_id)
        childcare_address_summary_table.row_list = [
            known_childcare_location_row
        ]

        if app_record['address_to_be_provided']:
            address_response = NannyGatewayActions().list(
                'childcare-address', params={'application_id': application_id})
            address_records = address_response.record

            for index, address in enumerate(address_records):
                row = Row('childcare_address',
                          "Childcare address " + str(index + 1),
                          AddressHelper.format_address(address_records[index],
                                                       "</br>"),
                          'Childcare-Address-Details',
                          "childcare address " + str(index + 1),
                          row_pk=address['childcare_address_id'],
                          use_many_to_one=True)

                childcare_address_summary_table.row_list.append(row)

            home_address_resp = NannyGatewayActions().read(
                'applicant-home-address',
                params={'application_id': application_id})

            home_address = home_address_resp.record['childcare_address']
            home_address_value = 'Yes' if home_address else 'No'

            home_address_row = Row(
                'both_work_and_home_address',
                'Do you currently live and work at the same address?',
                home_address_value, 'Childcare-Address-Location',
                'answer to currently living and working at the same address')

            childcare_address_summary_table.row_list.insert(
                1, home_address_row)

        # FIXME: The childcare address 2 row renders with the same ARC flag as address 1
        childcare_address_summary_table.get_errors()

        context['table_list'] = [childcare_address_summary_table]
        context['application_id'] = application_id
        context['id'] = application_id
        context['page_title'] = 'Check your answers: childcare location'

        return context
Пример #7
0
    def get_context_data(self):
        context = dict()
        application_id = self.request.GET['id']
        suitability_record = NannyGatewayActions().read('suitability',
                                                        params={
                                                            'application_id':
                                                            application_id
                                                        }).record
        table_rows = []

        disqualified_row = Row('disqualification', 'Are you disqualified?', "",
                               'suitability:disqualification_question',
                               'answer to your disqualification status')
        if suitability_record['disqualification']:
            disqualified_row.value = "Yes"
            disqualified_details_row = Row(
                'disqualification_details',
                'Details about disqualification circumstances ',
                suitability_record['disqualification_details'],
                'suitability:disqualification_details',
                'answer to details about disqualification status')
            table_rows.append(disqualified_row)
            table_rows.append(disqualified_details_row)

        else:
            disqualified_row.value = "No"
            table_rows.append(disqualified_row)

        suitability_circumstances_row = Row(
            'other_suitability_circumstances',
            'Are you aware of any other circumstances that might affect your suitability?',
            "", 'suitability:other_circumstances',
            'answer to other circumstances which might affect suitability')
        if suitability_record['other_suitability_circumstances']:
            suitability_circumstances_row.value = "Yes"
            suitability_circumstances_details_row = Row(
                'suitability_circumstances_details',
                'Details of your suitability ',
                suitability_record['suitability_circumstances_details'],
                'suitability:suitability_details',
                'answer to details about other circumstances which might affect suitability'
            )
            table_rows.append(suitability_circumstances_row)
            table_rows.append(suitability_circumstances_details_row)
        else:
            suitability_circumstances_row.value = "No"
            table_rows.append(suitability_circumstances_row)

        social_services_row = Row(
            'social_services',
            'Have you ever been involved with social services in connection with your own children?',
            "", 'suitability:social_services',
            'answer to if you are known to social services')
        if suitability_record['social_services']:
            social_services_row.value = "Yes"
            social_services_row_details = Row(
                'social_services_details',
                'Details of your involvement with social services',
                suitability_record['social_services_details'],
                'suitability:social_services_details',
                'answer to details of your involvement with social services')
            table_rows.append(social_services_row)
            table_rows.append(social_services_row_details)
        else:
            social_services_row.value = "No"
            table_rows.append(social_services_row)

        criminal_convictions_row = Row(
            'criminal_convictions',
            'Do you have any criminal convictions or cautions?', "",
            'suitability:criminal_convictions',
            'answer to criminal conviction status')
        if suitability_record['criminal_convictions']:
            criminal_convictions_row.value = "Yes"
            criminal_convictions_details_row = Row(
                'criminal_convictions_details', 'Criminal convictions details',
                suitability_record['criminal_convictions_details'],
                'suitability:criminal_convictions_details',
                'answer to criminal conviction details')
            table_rows.append(criminal_convictions_row)
            table_rows.append(criminal_convictions_details_row)
        else:
            criminal_convictions_row.value = "No"
            table_rows.append(criminal_convictions_row)

        suitability_summary_table = Table(application_id)
        suitability_summary_table.row_list = table_rows
        suitability_summary_table.get_errors()

        context['table_list'] = [suitability_summary_table]
        context['application_id'] = application_id
        context['id'] = application_id
        context['page_title'] = 'Check your answers: Suitability'

        context['record'] = suitability_record

        return context