Esempio n. 1
0
    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)
Esempio n. 2
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")
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        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()
        else:
            return render(request, self.template_name, {'profile_form': profile_form,
                                                        'address_form': address_form})

        messages.success(request, "The profile '%s' was created." % profile.name)

        return redirect('main:list_profiles')
Esempio n. 4
0
    def post(self, request, *args, **kwargs):
        if request.user.pk != int(request.POST['user']):
            return HttpResponse('Unauthorized', status=401)

        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()
        else:
            return render(request, self.template_name, {'profile_form': profile_form,
                                                        'address_form': address_form})

        messages.success(request, "The profile '%s' was created." % profile.name)

        return redirect('wl_main:list_profiles')
Esempio n. 5
0
    def post(self, request, *args, **kwargs):
        profile = get_object_or_404(Profile, pk=args[0])

        if profile.user != request.user or request.user.pk != int(request.POST['user']):
            return HttpResponse('Unauthorized', status=401)
        profile_form = ProfileForm(request.POST, instance=profile)
        address_form = AddressForm(request.POST, instance=profile.postal_address)

        if profile_form.is_valid() and address_form.is_valid():
            profile = profile_form.save()
            address_form.save()
        else:
            return render(request, self.template_name, {'profile_form': profile_form,
                                                        'address_form': address_form})

        messages.success(request, "The profile '%s' was updated." % profile.name)

        return redirect('wl_main:list_profiles')
Esempio n. 6
0
    def get(self, request, *args, **kwargs):
        profile = get_object_or_404(Profile, pk=args[0])

        if profile.user != request.user:
            return HttpResponse('Unauthorized', status=401)

        return render(
            request, self.template_name, {
                'profile_form': ProfileForm(instance=profile),
                'address_form': AddressForm(instance=profile.postal_address)
            })
Esempio n. 7
0
    def post(self, request, *args, **kwargs):
        if request.user.pk != int(request.POST['user']):
            return HttpResponse('Unauthorized', status=401)

        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()
        else:
            return render(request, self.template_name, {
                'profile_form': profile_form,
                'address_form': address_form
            })

        messages.success(request,
                         "The profile '%s' was created." % profile.name)

        return redirect('wl_main:list_profiles')
Esempio n. 8
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')
Esempio n. 9
0
    def post(self, request, *args, **kwargs):
        customer = get_object_or_404(EmailUser, pk=self.args[0])

        if len(self.args) > 1:
            profile = get_object_or_404(Profile, pk=args[1])
            profile_form = ProfileForm(request.POST, instance=profile)
            address_form = AddressForm(request.POST, instance=profile.postal_address)
        else:
            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)
            address = address_form.save()
            profile.user = customer
            profile.postal_address = address
            profile.save()
        else:
            return render(request, self.template_name, {'customer': customer,
                                                        'profile_form': profile_form,
                                                        'address_form': address_form})

        messages.success(request, "The profile '%s' was updated." % profile.name)

        return redirect('wl_customer_management:customer_lookup', profile.user.pk)
Esempio n. 10
0
    def post(self, request, *args, **kwargs):
        profile = get_object_or_404(Profile, pk=args[0])

        if profile.user != request.user or request.user.pk != int(
                request.POST['user']):
            return HttpResponse('Unauthorized', status=401)
        profile_form = ProfileForm(request.POST, instance=profile)
        address_form = AddressForm(request.POST,
                                   instance=profile.postal_address)

        if profile_form.is_valid() and address_form.is_valid():
            profile = profile_form.save()
            profile.postal_address = address_form.save()
            profile.save()
        else:
            return render(request, self.template_name, {
                'profile_form': profile_form,
                'address_form': address_form
            })

        messages.success(request,
                         "The profile '%s' was updated." % profile.name)

        return redirect('wl_main:list_profiles')
Esempio n. 11
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)
Esempio n. 12
0
 def get(self, request, *args, **kwargs):
     return render(
         request, self.template_name, {
             'profile_form': ProfileForm(user=request.user),
             'address_form': AddressForm(user=request.user)
         })