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

        if 'select' in request.POST:
            application.applicant = EmailUser.objects.get(id=request.POST.get('customer'))
            application.save()
        elif 'create' in request.POST:
            create_customer_form = EmailUserForm(request.POST, email_required=False)
            if create_customer_form.is_valid():
                customer = create_customer_form.save()
                application.applicant = customer
                application.save()
                application.log_user_action(
                    ApplicationUserAction.ACTION_CREATE_CUSTOMER_.format(render_user_name(customer)),
                    request
                )
            else:
                context = {'create_customer_form': create_customer_form}
                return render(request, self.template_name, context)

        return redirect('wl_applications:select_licence_type', *args, **kwargs)
Example #2
0
    def post(self, request, *args, **kwargs):
        emailuser = get_object_or_404(EmailUser, pk=request.user.pk)
        # Save the original user data.
        original_first_name = emailuser.first_name
        original_last_name = emailuser.last_name
        emailuser_form = EmailUserForm(request.POST, instance=emailuser)
        if emailuser_form.is_valid():
            emailuser = emailuser_form.save(commit=False)
            is_name_changed = any([
                original_first_name != emailuser.first_name,
                original_last_name != emailuser.last_name
            ])

            # send signal if either first name or last name is changed
            if is_name_changed:
                messages.warning(
                    request,
                    "Please upload new identification after you changed your name."
                )
                return redirect(self.identification_url)
            elif not emailuser.identification:
                messages.warning(request, "Please upload your identification.")
            else:
                messages.success(request, "User account was saved.")

        return render(request, self.template_name, {
            'emailuser_form': emailuser_form,
        })
Example #3
0
    def post(self, request, *args, **kwargs):
        try:
            application = utils.get_session_application(request.session)
        except Exception as e:
            messages.error(request, str(e))
            return redirect('wl_applications:new_application')

        if 'select' in request.POST:
            application.applicant = EmailUser.objects.get(
                id=request.POST.get('customer'))
            application.save()
        elif 'create' in request.POST:
            create_customer_form = EmailUserForm(request.POST,
                                                 email_required=False)
            if create_customer_form.is_valid():
                customer = create_customer_form.save()
                application.applicant = customer
                application.save()
                application.log_user_action(
                    ApplicationUserAction.ACTION_CREATE_CUSTOMER_.format(
                        render_user_name(customer)), request)
            else:
                context = {'create_customer_form': create_customer_form}
                return render(request, self.template_name, context)

        return redirect('wl_applications:select_licence_type', *args, **kwargs)
Example #4
0
    def post(self, request, *args, **kwargs):
        if 'select' in request.POST:
            utils.set_app_session_data(request.session, 'customer_pk', request.POST.get('customer'))
        elif 'create' in request.POST:
            create_customer_form = EmailUserForm(request.POST, email_required=False)
            if create_customer_form.is_valid():
                customer = create_customer_form.save()
                utils.set_app_session_data(request.session, 'customer_pk', customer.id)
            else:
                context = {'create_customer_form': create_customer_form}
                return render(request, self.template_name, context)

        return redirect('wl_applications:select_licence_type', *args, **kwargs)
Example #5
0
    def get(self, request, *args, **kwargs):
        emailuser = get_object_or_404(EmailUser, pk=request.user.id)
        # if user doesn't choose a identification, display a warning message
        #if not emailuser.identification:
        #    messages.warning(request, "Please upload your identification.")

        return render(request, self.template_name, {'emailuser_form': EmailUserForm(instance=emailuser),})
Example #6
0
    def get_context_data(self, **kwargs):
        kwargs['application'] = utils.get_session_application(
            self.request.session)

        kwargs['create_customer_form'] = EmailUserForm(email_required=False)

        return super(CreateSelectCustomer, self).get_context_data(**kwargs)
Example #7
0
 def post(self, request, *args, **kwargs):
     emailuser = get_object_or_404(EmailUser, pk=request.user.pk)
     new_user = not (emailuser.first_name or emailuser.last_name
                     or emailuser.dob)
     if 'discontinue' in request.POST:
         return self._process_discontinue(emailuser)
     else:
         allow_discontinue = False
         # Save the original user data.
         original_first_name = emailuser.first_name
         original_last_name = emailuser.last_name
         emailuser_form = EmailUserForm(request.POST, instance=emailuser)
         if emailuser_form.is_valid():
             emailuser = emailuser_form.save(commit=False)
             # New user test case. Check the uniqueness of the user (first, last, dob).
             # https://kanboard.dpaw.wa.gov.au/?controller=TaskViewController&action=show&task_id=2994&project_id=24
             # TODO: This should be done at the ledger level !!!
             unique = EmailUser.objects.filter(
                 first_name=emailuser.first_name,
                 last_name=emailuser.last_name,
                 dob=emailuser.dob).count() == 0
             emailuser.save()
             if new_user and not unique:
                 message = """This combination of given name(s), last name and date of birth is not unique.
                 If you already have a Parks and Wildlife customer account under another email address, please discontinue this registration and sign in with your existing account and add any additional email addresses as new profiles."""
                 messages.error(request, message)
                 allow_discontinue = True
             else:
                 is_name_changed = any([
                     original_first_name != emailuser.first_name,
                     original_last_name != emailuser.last_name
                 ])
                 # send signal if either first name or last name is changed
                 if is_name_changed:
                     messages.warning(
                         request,
                         "Please upload new identification after you changed your name."
                     )
                     return redirect(self.identification_url)
                 else:
                     messages.success(request, "User account was saved.")
                     return redirect('wl_home')
         return render(
             request, self.template_name, {
                 'emailuser_form': emailuser_form,
                 'allow_discontinue': allow_discontinue
             })
Example #8
0
    def post(self, request, *args, **kwargs):
        emailuser = get_object_or_404(EmailUser, pk=request.user.pk)
        # Save the original user data.
        original_first_name = emailuser.first_name
        original_last_name = emailuser.last_name
        emailuser_form = EmailUserForm(request.POST, instance=emailuser)
        if emailuser_form.is_valid():
            emailuser = emailuser_form.save()
            is_name_changed = any([original_first_name != emailuser.first_name, original_last_name != emailuser.last_name])

            # send signal if either first name or last name is changed
            if is_name_changed:
                messages.warning(request, "Please upload new identification after you changed your name.")
                return redirect(self.identification_url)
            else:
                messages.success(request, "User account was saved.")

        return render(request, self.template_name, {'emailuser_form': emailuser_form,})
Example #9
0
    def post(self, request, *args, **kwargs):
        try:
            application = utils.get_session_application(request.session)
        except Exception as e:
            messages.error(request, e.message)
            return redirect("wl_applications:new_application")

        if "select" in request.POST:
            application.applicant = EmailUser.objects.get(id=request.POST.get("customer"))
            application.save()
        elif "create" in request.POST:
            create_customer_form = EmailUserForm(request.POST, email_required=False)
            if create_customer_form.is_valid():
                customer = create_customer_form.save()
                application.applicant = customer
                application.save()
            else:
                context = {"create_customer_form": create_customer_form}
                return render(request, self.template_name, context)

        return redirect("wl_applications:select_licence_type", *args, **kwargs)
Example #10
0
    def get_context_data(self, **kwargs):
        kwargs['create_customer_form'] = EmailUserForm(email_required=False)

        return super(CreateSelectCustomer, self).get_context_data(**kwargs)
Example #11
0
    def post(self, request, *args, **kwargs):
        #validate request
        #residential_address_source_type = request.POST.get("residential_address-source_type")
        #if not residential_address_source_type:
        #    return HttpResponseBadRequest("Missing resiential address source type.")

        #postal_address_source_type = request.POST.get("postal_address-source_type")
        #if not postal_address_source_type:
        #    return HttpResponseBadRequest("Missing postal address source type.")

        #billing_address_source_type = request.POST.get("billing_address-source_type")
        #if not billing_address_source_type:
        #    return HttpResponseBadRequest("Missing billing address source type.")


        emailuser = get_object_or_404(EmailUser, pk=request.user.pk)
        #Save the original user data.
        original_first_name = emailuser.first_name
        original_last_name = emailuser.last_name
        #original_identification = emailuser.identification

        #original_residential_address_source_type = "added" if emailuser.residential_address else "removed"
        #original_postal_address_source_type =  "removed" if not emailuser.postal_address else ("residential_address" if emailuser.postal_address == emailuser.residential_address else "added")
        #original_billing_address_source_type =  "removed" if not emailuser.billing_address else ("residential_address" if emailuser.billing_address == emailuser.residential_address else ("postal_address" if emailuser.billing_address == emailuser.postal_address else "added"))

        #original_residential_address = emailuser.residential_address
        #original_postal_address =  emailuser.postal_address
        #original_billing_address =  emailuser.billing_address

        emailuser_form = EmailUserForm(request.POST,instance=emailuser)

        #populate address form to validate and save if required
        #if residential_address_source_type == "added":
        #    residential_address_form = AddressForm(request.POST,prefix="residential_address",instance=emailuser.residential_address)
        #else:
        #    residential_address_form = None

        #if postal_address_source_type == "added":
        #    if original_postal_address_source_type == "added":
        #        postal_address_form = AddressForm(request.POST,prefix="postal_address",instance=emailuser.postal_address)
        #    else:
        #        postal_address_form = AddressForm(request.POST,prefix="postal_address")
        #else:
        #    postal_address_form = None

        #if billing_address_source_type == "added":
        #    if original_billing_address_source_type == "added":
        #        billing_address_form = AddressForm(request.POST,prefix="billing_address",instance=emailuser.billing_address)
        #    else:
        #        billing_address_form = AddressForm(request.POST,prefix="billing_address")
        #else:
        #    billing_address_form = None

        if (emailuser_form.is_valid() 
        #    and (not residential_address_form or  residential_address_form.is_valid())
        #    and (not postal_address_form or postal_address_form.is_valid())
        #    and (not billing_address_form or billing_address_form.is_valid())
        ):
            emailuser = emailuser_form.save(commit=False)
            is_name_changed = any([original_first_name != emailuser.first_name,original_last_name != emailuser.last_name])

            #save user address information.

            #if residential_address_source_type == "added":
            #    emailuser.residential_address = residential_address_form.save()
            #else:
            #    emailuser.residential_address = None

            #if postal_address_source_type == "added":
            #    emailuser.postal_address = postal_address_form.save()
            #elif postal_address_source_type == "residential_address":
            #    emailuser.postal_address = emailuser.residential_address
            #else:
            #    emailuser.postal_address = None

            #if billing_address_source_type == "added":
            #    emailuser.billing_address = billing_address_form.save()
            #elif billing_address_source_type == "residential_address":
            #    emailuser.billing_address = emailuser.residential_address
            #elif billing_address_source_type == "postal_address":
            #    emailuser.billing_address = emailuser.postal_address
            #else:
            #    emailuser.billing_address = None

            #save user info
            emailuser.save()

            #remove old address if required.
            #if residential_address_source_type == "removed" and original_residential_address:
            #    original_residential_address.delete()

            #if original_postal_address_source_type == "added" and postal_address_source_type != "added":
            #    original_postal_address.delete()
                            
            #if original_billing_address_source_type == "added" and billing_address_source_type != "added":
            #    original_billing_address.delete()
                            
            #send signal if either first name or last name is changed
            if is_name_changed:
                messages.warning(request, "Please upload new identification after you changed your name.")
                return redirect(self.identification_url)
            elif not emailuser.identification:
                messages.warning(request, "Please upload your identification.")
            else:
                messages.success(request, "User account was saved.")

        return render(request, self.template_name, {'emailuser_form': emailuser_form,
                                                    #'residential_address_form': residential_address_form or AddressForm(prefix="residential_address"),
                                                    #'postal_address_form': postal_address_form or AddressForm(prefix="postal_address"),
                                                    #'billing_address_form': billing_address_form or AddressForm(prefix="billing_address"),
                                                    #'residential_address_source_type':residential_address_source_type,
                                                    #'postal_address_source_type':postal_address_source_type,
                                                    #'billing_address_source_type':billing_address_source_type,
                                                    })