ecommerce/addresses/views.py
2018-09-10 23:16:35 +03:00

46 lines
1.6 KiB
Python

from django.shortcuts import redirect
from .forms import AddressForm
from billing.models import BillingProfile
from .models import Address
def checkout_address_create(request):
form = AddressForm(request.POST or None)
if form.is_valid():
inst = form.save(commit=False)
billing_profile, billing_profile_created = BillingProfile.objects.new_or_get(request)
if billing_profile is not None:
inst.billing_profile = billing_profile
inst.address_type = "shipping"
inst.save()
request.session["address_id"] = inst.id
else:
print("error")
return redirect("carts:checkout")
def checkout_address_use(request):
if request.user.is_authenticated():
context = {}
if request.method == "POST":
print(request.POST)
address = request.POST.get("address", None)
billing_profile, billing_profile_created = BillingProfile.objects.new_or_get(request)
if address is not None:
qs = Address.objects.filter(billing_profile=billing_profile, id=address)
if qs.exists():
request.session["address_id"] = address
return redirect("carts:checkout")
"""
def guest_login_page(request):
form = GuestForm(request.POST or None)
# context = {"form": form}
# TODO: next stuff
if form.is_valid():
print('form is valid')
email = form.cleaned_data.get("email")
new_guest_email = GuestEmail.objects.create(email=email)
request.session['guest_email_id'] = new_guest_email.id
return redirect("carts:checkout")
"""