def accountSettings(r):
    customer=r.user.customer
    form=CustomerForm(instance=customer)
    if r.method=="POST":
        form=CustomerForm(r.POST,r.FILES,instance=customer)
        if form.is_valid():
            form.save()
    return render(r,"accounts/account_settings.html",{'form':form})
Example #2
0
def account_setting(request):
    customer = request.user.customers
    form = CustomerForm(instance=customer)
    if request.method == "POST":
        form = CustomerForm(request.POST, request.FILES, instance=customer)
        if form.is_valid():
            form.save()
    return render(request, 'crmaccounts/account_setting.html', {'form': form})
Example #3
0
def account_settings(request):
    customer = request.user.customer
    form = CustomerForm(instance=customer)
    if request.method == 'POST':
        form = CustomerForm(request.POST, request.FILES, instance=customer)
        if form.is_valid():
            form.save()
    context = {'form': form}
    return render(request, 'accounts/account_settings.html', context)
Example #4
0
def create_customer(request):
    if request.method == 'POST':
        form = CustomerForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/') #redirect to dashboard
    else:
        form = CustomerForm()
    return render(request, 'accounts/customer_form.html', {'form':form})
Example #5
0
def create_customer(request):
    form = CustomerForm()
    if request.method == 'POST':
        form = CustomerForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')
    
    context = { 'form': form}
    return render(request, 'accounts/create_customer.html', context)
Example #6
0
def account_settings(request):
    # customer = Customer.objects.get(id=pk)
    customer = request.user.customer
    form = CustomerForm(instance=customer)
    if request.method == "POST":
        form = CustomerForm(request.POST, request.FILES, instance=customer)
        if form.is_valid():
            form.save()
    context = {"form": form}
    return render(request, "accounts/account_settings.html", context=context)
Example #7
0
def update_customer(request, pk):
    customer = Customers.objects.get(id=pk)
    form = CustomerForm(instance=customer)
    if request.method == "POST":
        form = CustomerForm(request.POST, instance=customer)
        if form.is_valid():
            form.save()
            return redirect('/')
    else:
        context = {'form': form}
        return render(request, 'crmaccounts/update_customer.html', context)
Example #8
0
def createcustomer(request):
    form = CustomerForm()
    if request.method == 'POST':           #same save function as above
        form = CustomerForm(request.POST)  #again saves that specific instance instead of making a new one.
        if form.is_valid():
            form.save()
            return redirect('/')
    context = {
    'form': form,
    }
    return render(request, 'accounts/customerform.html', context)
Example #9
0
def customer_settings(request):
    customer = request.user.customer
    form = CustomerForm(instance=customer)
    if request.method == 'POST':
        form = CustomerForm(request.POST, request.FILES, instance=customer)
        if form.is_valid():
            form.save()
            messages.success(request, "Profile Updated Successfully")
        else:
            messages.error(request, 'There is error in form submission')
    context = {'form': form}
    return render(request, 'accounts/customer_settings.html', context)
Example #10
0
def updateCustomer(request, pk):
    customer = Customer.objects.get(id=pk)
    form = CustomerForm(instance=customer)

    if request.method == 'POST':
        form = CustomerForm(request.POST, instance=customer)
        if form.is_valid():
            form.save()
            return redirect('/')

    context = {'form': form}
    return render(request, 'customer/customer_update.html', context)
Example #11
0
def user_account(request):
    customer = request.user.customer
    if request.method == 'POST':
        form = CustomerForm(request.POST, request.FILES, instance=customer)
        if form.is_valid():
            form.save()
        return redirect('/user')
    else:
        form = CustomerForm(instance=customer)
    context = {'form': form}

    return render(request, 'users/userAccount.html', context)
Example #12
0
def updateCustomer(request, pk):
    customer = Customer.objects.get(id=pk)
    form = CustomerForm(instance=customer)
    if request.method == 'POST':
        form = CustomerForm(request.POST, instance=customer)
        if form.is_valid():
            form.save()

            logger.info("customer info changed by admin")
            return redirect('customer', pk)
    context = {'form': form}
    return render(request, 'accounts/update_customer.html', context)
Example #13
0
def updatecustomer(request, pk):
    customer = Customer.objects.get(id=pk)
    form = CustomerForm(instance = customer)
    if request.method == 'POST':           #same save function as above
        form = CustomerForm(request.POST, instance= customer)  #again saves that specific instance instead of making a new one.
        if form.is_valid():
            form.save()
            return redirect('/')


    context = {
    'form': form,
    'customer': customer
    }

    return render(request, 'accounts/customerform.html', context)
def shipping(request):

    """
    Renders checkout shipping page with navbar and footer
    removed to fit with conventions of online shops.
    If user not logged in getting to this stage is blocked,
    and user is asked to login.
    """

    customer = None
    if request.user.is_authenticated():
        customer = Customer.objects.filter(user=request.user).first()
    else:
        messages.error(request, "Need to be logged in to do checkout")
        return redirect(reverse("login"))
    if request.method == "POST":
        form = CustomerForm(request.POST, instance=customer)
        if form.is_valid():
            customer = form.save(commit=False)
            customer.user = request.user
            customer.save()
            return redirect("checkout")
    else:
        form = CustomerForm(instance=customer)
    return render(
        request,
        "shipping.html",
        {
            "customer": customer,
            "form": form,
            "disable_header": True,
            "disable_footer": True,
        },
    )
Example #15
0
def user_profile(request):
    """
    Renders profile page for user with a form to update
    their information. When posted creates a new customer.
    """

    customer = Customer.objects.filter(user=request.user).first()
    if request.method == "POST":
        form = CustomerForm(request.POST, instance=customer)
        if form.is_valid():
            customer = form.save(commit=False)
            customer.user = request.user
            customer.save()
            messages.success(request, "You have updated your profile")
    else:
        form = CustomerForm(instance=customer)
    has_order = False
    if customer:
        has_order = Order.objects.filter(customer=customer).exists()

    return render(
        request,
        "profile.html",
        {
            "user": request.user,
            "form": form,
            "has_order": has_order
        },
    )
Example #16
0
def shipping(request):
    """
    Renders checkout shipping page with navbar and footer
    ifnot logged in getting user is prompted to login.
    """

    customer = None
    if request.user.is_authenticated():
        customer = Customer.objects.filter(user=request.user).first()
    else:
        messages.error(request, "Need to be logged in to do checkout")
        return redirect(reverse("login"))
    if request.method == "POST":
        form = CustomerForm(request.POST, instance=customer)
        if form.is_valid():
            customer = form.save(commit=False)
            customer.user = request.user
            customer.save()
            return redirect("checkout")
    else:
        form = CustomerForm(instance=customer)
    return render(
        request,
        "shipping.html",
        {
            "customer": customer,
            "form": form,
        },
    )
Example #17
0
 def update(self, request, msisdn):
     try:
         customer = Customer.objects.get(msisdn=msisdn)
     except Customer.DoesNotExist:
         return rc.NOT_FOUND
     
     form = CustomerForm(data=request.data, instance=customer)
     if not form.is_valid():
         raise FormValidationError(form)
         
     return form.save()
Example #18
0
    def update(self, request, msisdn):
        try:
            customer = Customer.objects.get(msisdn=msisdn)
        except Customer.DoesNotExist:
            return rc.NOT_FOUND

        form = CustomerForm(data=request.data, instance=customer)
        if not form.is_valid():
            raise FormValidationError(form)

        return form.save()
Example #19
0
def SignUp2(request):
    if request.method == 'POST':
        form1 = CustomerForm(request.POST)
        form2 = UserForm(request.POST)

        if all([form1.is_valid(), form2.is_valid()]):
            customer = form1.save()
            user = form2.save()
            success_url = reverse_lazy('login')
            return HttpResponseRedirect(success_url)

    else:
        form1 = CustomerForm()
        form2 = UserForm()

    return render(request, 'signup.html', {
        'customer_form': form1,
        'user_form': form2,
    })