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})
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})
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)
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})
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)
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)
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)
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)
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)
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)
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)
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)
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, }, )
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 }, )
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, }, )
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()
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, })