from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import *


def orders_list(request):
    return render(request, 'orders/orders-list.html')


def order_create(request):
    if request.user.is_authenticated:
        if request.method == 'POST':
            form = BaseOrderCreationForm(request.POST)
            if form.is_valid():
                return HttpResponseRedirect('/account')
        else:
            form = BaseOrderCreationForm()
    else:
        if request.method == 'POST':
            form = UnregisteredUserOrderCreationForm(request.POST)
            if form.is_valid():
                return HttpResponseRedirect('/account')
        else:
            form = UnregisteredUserOrderCreationForm()

    return render(request, 'orders/order-create.html', {'form': form})
