Example #1
0
    def get_context_data(self, **kwargs):
        if len(self.args) > 1:
            kwargs['application_pk'] = self.args[1]

        try:
            applicant = utils.determine_applicant(self.request)
        except utils.SessionDataMissingException as e:
            messages.error(self.request, six.text_type(e))
            return redirect('wl_applications:create_select_customer')

        profile_exists = applicant.profile_set.count() > 0

        if utils.is_app_session_data_set(self.request.session, 'profile_pk'):
            selected_profile = Profile.objects.get(id=utils.get_app_session_data(self.request.session, 'profile_pk'))
            kwargs['profile_selection_form'] = ProfileSelectionForm(user=applicant, selected_profile=selected_profile)
        else:
            if profile_exists:
                kwargs['profile_selection_form'] = ProfileSelectionForm(user=applicant)

        if profile_exists:
            kwargs['profile_creation_form'] = ProfileForm(user=utils.get_app_session_data(self.request.session, 'customer_pk'))
        else:
            kwargs['profile_creation_form'] = ProfileForm(initial_display_name='Default', initial_email=applicant.email,
                                                          user=utils.get_app_session_data(self.request.session, 'customer_pk'))

        kwargs['address_form'] = AddressForm()
        kwargs['licence_type'] = get_object_or_404(WildlifeLicenceType, code_slug=self.args[0])

        return super(CreateSelectProfileView, self).get_context_data(**kwargs)
Example #2
0
    def get(self, *args, **kwargs):
        licence_type = get_object_or_404(WildlifeLicenceType, code_slug=args[1])

        try:
            applicant = utils.determine_applicant(self.request)
        except utils.SessionDataMissingException as e:
            messages.error(self.request, six.text_type(e))
            return redirect('wl_applications:create_select_customer')

        if licence_type.identification_required and applicant.identification is None:
            return super(CheckIdentificationRequiredView, self).get(*args, **kwargs)
        else:
            return redirect('wl_applications:create_select_profile', args[1], **kwargs)
Example #3
0
    def form_valid(self, form):
        try:
            applicant = utils.determine_applicant(self.request)
        except utils.SessionDataMissingException as e:
            messages.error(self.request, six.text_type(e))
            return redirect('wl_applications:create_select_customer')

        if applicant.identification is not None:
            applicant.identification.delete()

        applicant.identification = Document.objects.create(file=self.request.FILES['identification_file'])
        applicant.save()

        # update any other applications for this user that are awaiting ID upload
        for application in Application.objects.filter(applicant_profile__user=applicant):
            if application.id_check_status == 'awaiting_update':
                application.id_check_status = 'updated'
                application.save()

        return redirect('wl_applications:create_select_profile', *self.args)
Example #4
0
    def post(self, request, *args, **kwargs):
        try:
            applicant = utils.determine_applicant(request)
        except utils.SessionDataMissingException as e:
            messages.error(request, six.text_type(e))
            return redirect('wl_applications:create_select_customer')

        licence_type = WildlifeLicenceType.objects.get(code_slug=args[0])

        if 'select' in request.POST:
            profile_selection_form = ProfileSelectionForm(request.POST, user=applicant)

            if profile_selection_form.is_valid():
                utils.set_app_session_data(request.session, 'profile_pk', profile_selection_form.cleaned_data.get('profile').id)
            else:
                return render(request, self.template_name, {'licence_type': licence_type,
                                                            'profile_selection_form': profile_selection_form,
                                                            'profile_creation_form': ProfileForm(),
                                                            'address_form': AddressForm()})
        elif 'create' in request.POST:
            profile_form = ProfileForm(request.POST)
            address_form = AddressForm(request.POST)

            if profile_form.is_valid() and address_form.is_valid():
                profile = profile_form.save(commit=False)
                profile.postal_address = address_form.save()
                profile.save()

                utils.set_app_session_data(request.session, 'profile_pk', profile.id)
            else:
                return render(request, self.template_name,
                              {'licence_type': licence_type,
                               'profile_selection_form': ProfileSelectionForm(user=request.user),
                               'profile_creation_form': profile_form, 'address_form': address_form})

        return redirect('wl_applications:enter_details', *args)