예제 #1
0
    def get_context_data(self, **kwargs):
        try:
            application = utils.get_session_application(self.request.session)
        except Exception as e:
            messages.error(self.request, str(e))
            return redirect('wl_applications:new_application')

        kwargs['application'] = application

        profile_exists = application.applicant.profiles.count() > 0

        if application.applicant_profile is not None:
            kwargs['profile_selection_form'] = ProfileSelectionForm(
                user=application.applicant,
                selected_profile=application.applicant_profile)
        else:
            if profile_exists:
                kwargs['profile_selection_form'] = ProfileSelectionForm(
                    user=application.applicant)

        if profile_exists:
            kwargs['profile_creation_form'] = ProfileForm(
                user=application.applicant)
        else:
            kwargs['profile_creation_form'] = ProfileForm(
                initial_display_name='Default',
                initial_email=application.applicant.email,
                user=application.applicant)

        kwargs['address_form'] = AddressForm(user=application.applicant)

        return super(CreateSelectProfileView, self).get_context_data(**kwargs)
예제 #2
0
파일: entry.py 프로젝트: ropable/ledger
    def post(self, request, *args, **kwargs):
        if 'select' in request.POST:
            profile_selection_form = ProfileSelectionForm(request.POST, user=request.user)

            if profile_selection_form.is_valid():
                request.session['application']['profile'] = profile_selection_form.cleaned_data.get('profile').id
                request.session.modified = True
            else:
                return render(request, self.template_name, {'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.user = request.user
                profile.save()

                request.session['application']['profile'] = profile.id
                request.session.modified = True
            else:
                return render(request, self.template_name,
                              {'profile_selection_form': ProfileSelectionForm(user=request.user),
                               'profile_creation_form': profile_form, 'address_form': address_form})

        return redirect('applications:enter_details', *args)
예제 #3
0
    def post(self, request, *args, **kwargs):
        try:
            application = utils.get_session_application(request.session)
        except Exception as e:
            messages.error(self.request, str(e))
            return redirect('wl_applications:new_application')

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

            if profile_selection_form.is_valid():
                application.applicant_profile = profile_selection_form.cleaned_data.get(
                    'profile')
                application.save()
            else:
                return render(
                    request, self.template_name, {
                        'licence_type': application.licence_type,
                        'profile_selection_form': profile_selection_form,
                        'profile_creation_form': ProfileForm(),
                        'address_form': AddressForm(user=application.applicant)
                    })
        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()

                application.applicant_profile = profile
                application.save()
                application.log_user_action(
                    ApplicationUserAction.ACTION_CREATE_PROFILE_.format(
                        profile), request)
            else:
                return render(
                    request, self.template_name, {
                        'licence_type':
                        application.licence_type,
                        'profile_selection_form':
                        ProfileSelectionForm(user=request.user),
                        'profile_creation_form':
                        profile_form,
                        'address_form':
                        address_form
                    })

        return redirect('wl_applications:enter_details')
예제 #4
0
    def post(self, request, *args, **kwargs):
        try:
            application = utils.get_session_application(request.session)
        except Exception as e:
            messages.error(self.request, e.message)
            return redirect("wl_applications:new_application")

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

            if profile_selection_form.is_valid():
                application.applicant_profile = profile_selection_form.cleaned_data.get("profile")
                application.save()
            else:
                return render(
                    request,
                    self.template_name,
                    {
                        "licence_type": application.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()

                application.applicant_profile = profile
                application.save()
            else:
                return render(
                    request,
                    self.template_name,
                    {
                        "licence_type": application.licence_type,
                        "profile_selection_form": ProfileSelectionForm(user=request.user),
                        "profile_creation_form": profile_form,
                        "address_form": address_form,
                    },
                )

        return redirect("wl_applications:enter_details")
예제 #5
0
    def post(self, request, *args, **kwargs):
        try:
            application = utils.get_session_application(request.session)
        except Exception as e:
            messages.error(self.request, e.message)
            return redirect('wl_applications:new_application')

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

            if profile_selection_form.is_valid():
                application.applicant_profile = profile_selection_form.cleaned_data.get('profile')
                application.save()
            else:
                return render(request, self.template_name, {'licence_type': application.licence_type,
                                                            'profile_selection_form': profile_selection_form,
                                                            'profile_creation_form': ProfileForm(),
                                                            'address_form': AddressForm(user=application.applicant)})
        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()

                application.applicant_profile = profile
                application.save()
                application.log_user_action(
                    ApplicationUserAction.ACTION_CREATE_PROFILE_.format(profile),
                    request
                )
            else:
                return render(request, self.template_name,
                              {'licence_type': application.licence_type,
                               'profile_selection_form': ProfileSelectionForm(user=request.user),
                               'profile_creation_form': profile_form, 'address_form': address_form})

        return redirect('wl_applications:enter_details')
예제 #6
0
파일: entry.py 프로젝트: serge-gaia/ledger
    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)