From 2f7f0e008a39a7e580de72d49c7f90aa3f896f71 Mon Sep 17 00:00:00 2001 From: "Sergey L. Sundukovskiy" Date: Sun, 15 Apr 2018 23:30:56 -0700 Subject: [PATCH] Entire Assignment --- .idea/dataSources.local.xml | 10 + .idea/dataSources.xml | 16 + .idea/libraries/R_User_Library.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/project3.iml | 27 + .idea/vcs.xml | 6 + .idea/workspace.xml | 665 ++++++++++++++++++ README.md | 80 +++ db.sqlite3 | Bin 0 -> 339968 bytes orders/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 132 bytes orders/__pycache__/admin.cpython-36.pyc | Bin 0 -> 853 bytes orders/__pycache__/apps.cpython-36.pyc | Bin 0 -> 348 bytes orders/__pycache__/forms.cpython-36.pyc | Bin 0 -> 1907 bytes orders/__pycache__/models.cpython-36.pyc | Bin 0 -> 4459 bytes orders/__pycache__/urls.cpython-36.pyc | Bin 0 -> 548 bytes orders/__pycache__/views.cpython-36.pyc | Bin 0 -> 4683 bytes orders/admin.py | 23 + orders/forms.py | 36 + orders/migrations/0001_initial.py | 102 +++ orders/migrations/0002_auto_20180405_2210.py | 23 + orders/migrations/0003_auto_20180407_1105.py | 22 + orders/migrations/0004_option_description.py | 20 + orders/migrations/0005_auto_20180407_1128.py | 38 + orders/migrations/0006_auto_20180407_1252.py | 43 ++ orders/migrations/0007_order_is_paid.py | 18 + orders/migrations/0008_auto_20180410_1627.py | 29 + orders/migrations/0009_auto_20180415_1453.py | 65 ++ orders/migrations/0010_auto_20180415_1510.py | 30 + orders/migrations/0011_auto_20180415_1542.py | 18 + orders/migrations/0012_auto_20180415_1542.py | 20 + orders/migrations/0013_auto_20180415_1851.py | 38 + orders/migrations/0014_auto_20180415_1901.py | 18 + .../__pycache__/0001_initial.cpython-36.pyc | Bin 0 -> 1909 bytes .../0002_auto_20180405_2210.cpython-36.pyc | Bin 0 -> 765 bytes .../0003_auto_20180407_1105.cpython-36.pyc | Bin 0 -> 646 bytes .../0004_option_description.cpython-36.pyc | Bin 0 -> 692 bytes .../0005_auto_20180407_1128.cpython-36.pyc | Bin 0 -> 821 bytes .../0006_auto_20180407_1252.cpython-36.pyc | Bin 0 -> 1067 bytes .../0007_order_is_paid.cpython-36.pyc | Bin 0 -> 570 bytes .../0008_auto_20180410_1627.cpython-36.pyc | Bin 0 -> 805 bytes .../0009_auto_20180415_1453.cpython-36.pyc | Bin 0 -> 1433 bytes .../0010_auto_20180415_1510.cpython-36.pyc | Bin 0 -> 954 bytes .../0011_auto_20180415_1542.cpython-36.pyc | Bin 0 -> 593 bytes .../0012_auto_20180415_1542.cpython-36.pyc | Bin 0 -> 563 bytes .../0013_auto_20180415_1851.cpython-36.pyc | Bin 0 -> 795 bytes .../0014_auto_20180415_1901.cpython-36.pyc | Bin 0 -> 624 bytes .../__pycache__/__init__.cpython-36.pyc | Bin 0 -> 143 bytes orders/models.py | 92 +++ orders/templates/cart.html | 102 +++ orders/templates/index.html | 125 ++++ orders/templates/login.html | 48 ++ orders/templates/order.html | 102 +++ orders/templates/order_list.html | 82 +++ orders/templates/register.html | 46 ++ orders/templates/visitor.html | 51 ++ orders/urls.py | 15 +- orders/views.py | 242 ++++++- pizza/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 131 bytes pizza/__pycache__/settings.cpython-36.pyc | Bin 0 -> 2258 bytes pizza/__pycache__/urls.cpython-36.pyc | Bin 0 -> 951 bytes pizza/__pycache__/wsgi.cpython-36.pyc | Bin 0 -> 530 bytes 62 files changed, 2265 insertions(+), 5 deletions(-) create mode 100644 .idea/dataSources.local.xml create mode 100644 .idea/dataSources.xml create mode 100644 .idea/libraries/R_User_Library.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/project3.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 orders/__pycache__/__init__.cpython-36.pyc create mode 100644 orders/__pycache__/admin.cpython-36.pyc create mode 100644 orders/__pycache__/apps.cpython-36.pyc create mode 100644 orders/__pycache__/forms.cpython-36.pyc create mode 100644 orders/__pycache__/models.cpython-36.pyc create mode 100644 orders/__pycache__/urls.cpython-36.pyc create mode 100644 orders/__pycache__/views.cpython-36.pyc create mode 100644 orders/forms.py create mode 100644 orders/migrations/0001_initial.py create mode 100644 orders/migrations/0002_auto_20180405_2210.py create mode 100644 orders/migrations/0003_auto_20180407_1105.py create mode 100644 orders/migrations/0004_option_description.py create mode 100644 orders/migrations/0005_auto_20180407_1128.py create mode 100644 orders/migrations/0006_auto_20180407_1252.py create mode 100644 orders/migrations/0007_order_is_paid.py create mode 100644 orders/migrations/0008_auto_20180410_1627.py create mode 100644 orders/migrations/0009_auto_20180415_1453.py create mode 100644 orders/migrations/0010_auto_20180415_1510.py create mode 100644 orders/migrations/0011_auto_20180415_1542.py create mode 100644 orders/migrations/0012_auto_20180415_1542.py create mode 100644 orders/migrations/0013_auto_20180415_1851.py create mode 100644 orders/migrations/0014_auto_20180415_1901.py create mode 100644 orders/migrations/__pycache__/0001_initial.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0002_auto_20180405_2210.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0003_auto_20180407_1105.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0004_option_description.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0005_auto_20180407_1128.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0006_auto_20180407_1252.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0007_order_is_paid.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0008_auto_20180410_1627.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0009_auto_20180415_1453.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0010_auto_20180415_1510.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0011_auto_20180415_1542.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0012_auto_20180415_1542.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0013_auto_20180415_1851.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/0014_auto_20180415_1901.cpython-36.pyc create mode 100644 orders/migrations/__pycache__/__init__.cpython-36.pyc create mode 100644 orders/templates/cart.html create mode 100644 orders/templates/index.html create mode 100644 orders/templates/login.html create mode 100644 orders/templates/order.html create mode 100644 orders/templates/order_list.html create mode 100644 orders/templates/register.html create mode 100644 orders/templates/visitor.html create mode 100644 pizza/__pycache__/__init__.cpython-36.pyc create mode 100644 pizza/__pycache__/settings.cpython-36.pyc create mode 100644 pizza/__pycache__/urls.cpython-36.pyc create mode 100644 pizza/__pycache__/wsgi.cpython-36.pyc diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml new file mode 100644 index 0000000..2c7a435 --- /dev/null +++ b/.idea/dataSources.local.xml @@ -0,0 +1,10 @@ + + + + + + false + true + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..40072a6 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,16 @@ + + + + + sqlite.xerial + true + true + $PROJECT_DIR$/pizza/settings.py + org.sqlite.JDBC + jdbc:sqlite:C:\Harvard\CSCI E-33A\project3\db.sqlite3 + + + + + + \ No newline at end of file diff --git a/.idea/libraries/R_User_Library.xml b/.idea/libraries/R_User_Library.xml new file mode 100644 index 0000000..71f5ff7 --- /dev/null +++ b/.idea/libraries/R_User_Library.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..65531ca --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7fe81e3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project3.iml b/.idea/project3.iml new file mode 100644 index 0000000..4908703 --- /dev/null +++ b/.idea/project3.iml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..91b2230 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,665 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ topping }} + + {% endfor %} + + {% else %} +

No Toppings to Select

+ {% endif %} +
+
+ +
+
+ + + + + {% endif %} + + +{% endblock %} \ No newline at end of file diff --git a/orders/templates/index.html b/orders/templates/index.html new file mode 100644 index 0000000..29b0f78 --- /dev/null +++ b/orders/templates/index.html @@ -0,0 +1,125 @@ +{% extends 'visitor.html' %} +{% block menu_active %}active{% endblock %} + +{% block body %} +
+
+
+
+
+ {% for type in types %} +

{{ type.description }}

+ + + + {% for size in sizes %} + + {% endfor %} + + + {% for option in options %} + + + {% for pizza in pizzas %} + {% if pizza.option.description == option.description and pizza.type.description == type.description%} + + {% endif %} + {% endfor %} + + {% endfor %} + +
+ {{ size.description}} +
+ {{ option.description}} + {{pizza.price}}
+ {% endfor %} +
+
+
+
+
+
+

Toppings

+
    + {% for topping in toppings %} +
  • {{ topping.description }}
  • + {% endfor %} +
+
+
+
+
+
+
+
+
+

Pasta

+ + + {% for pasta in pastas %} + + + + + {% endfor %} + +
{{pasta.description}}{{pasta.price}}
+
+
+
+
+
+
+
+
+

Salads

+ + + {% for salad in salads %} + + + + + {% endfor %} + +
{{salad.description}}{{salad.price}}
+
+
+
+
+
+
+
+
+

Dinner Plates

+ + + + {% for size in sizes %} + + {% endfor %} + + + {% for plate in plates %} + + + {% for item in items %} + {% if item.type.description == plate.description %} + + {% endif %} + {% endfor %} + + {% endfor %} + +
+ {{ size.description}} +
+ {{ plate.description}} + {{item.price}}
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/orders/templates/login.html b/orders/templates/login.html new file mode 100644 index 0000000..50639ca --- /dev/null +++ b/orders/templates/login.html @@ -0,0 +1,48 @@ +{% extends 'visitor.html' %} +{% block title %}Log In{% endblock %} +{% block login_active %}active{% endblock %} + +{% block body %} +
+
+
+
+
+

Log In

+ {% if messages %} +
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} +
+ {% csrf_token %} + + {% for field in form %} + + + + + + + {% endfor %} +
+ + + {{ field }} +
+
+
+ +
+
+
+
+
+
+
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/orders/templates/order.html b/orders/templates/order.html new file mode 100644 index 0000000..30d75e9 --- /dev/null +++ b/orders/templates/order.html @@ -0,0 +1,102 @@ +{% extends 'visitor.html' %} +{% block title %}Cart{% endblock %} +{% block cart_active %}active{% endblock %} + +{% block body %} +
+ {% if order %} +
+
+
+
+
+ {% csrf_token %} +

Please Review Your Order

+
    +
  • Order ID: {{ order.id }}
  • +
  • Total: {{ order.total }}
  • +
+
+
+ +
+
+
+
+
+
+ {% endif %} +
+
+
+ {% if error %} +

{{ error }}

+ {% endif %} + {% if order %} + {% for pizza_assembly in order.pizzas_assemblies.all %} +
+
+
+ Card image +

{{ pizza_assembly.pizza.type.description }}

+

Size: {{ pizza_assembly.pizza.size.description }}

+

Price: {{ pizza_assembly.pizza.price }}

+ {% for topping in pizza_assembly.toppings.all %} +

{{ topping.description}}

+ {% endfor %} +
+
+
+ {% endfor %} + {% for salad in order.salads.all %} +
+
+
+ Card image +

{{ salad.description }}

+

Price: {{ salad.price }}

+
+
+
+ {% endfor %} + {% for pasta in order.pastas.all %} +
+
+
+ Card image +

{{ pasta.description }}

+

Price: {{ pasta.price }}

+
+
+
+ {% endfor %} + {% for plate in order.dinner_plates.all %} +
+
+
+ Card image +

{{ plate.type.description }}

+

Price: {{ plate.size.price }}

+

Price: {{ plate.price }}

+
+
+
+ {% endfor %} +
+ {% csrf_token %} +
+
+ +
+
+
+ {% endif %} +
+ +
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/orders/templates/order_list.html b/orders/templates/order_list.html new file mode 100644 index 0000000..7387c40 --- /dev/null +++ b/orders/templates/order_list.html @@ -0,0 +1,82 @@ +{% extends 'visitor.html' %} +{% block title %}Orders{% endblock %} +{% block order_active %}active{% endblock %} + +{% block body %} +
+
+
+
+ {% if error %} +

{{ error }}

+ {% endif %} + {% if orders %} + + + + + + + + + + + {% for order in orders%} + + + + + {% if order.is_complete == True %} + + {% else %} + + {% endif %} + + {% endfor %} + +
Order NumberOrder TotalOrder ItemsOrder Status
{{ order.id }}${{ order.total }} +
    + {% for pizza_assembly in order.pizzas_assemblies.all %} +
  1. + {{ pizza_assembly.pizza.type.description}}, + {{ pizza_assembly.pizza.size.description}}, + {{ pizza_assembly.pizza.option.description}},
    + {% for topping in pizza_assembly.toppings.all %} +
      +
    • {{ topping.description}}
    • +
    + {% endfor %} + {% if pizza_assembly.toppings.all|length == 0 %} +
      +
    • No Toppings
    • +
    + {% endif %} +
  2. + {% endfor %} + {% for salad in order.salads.all %} +
  3. + {{ salad.description}} +
  4. + {% endfor %} + {% for pasta in order.pastas.all %} +
  5. + {{ pasta.description}} +
  6. + {% endfor %} + {% for plate in order.dinner_plates.all %} +
  7. + {{ plate.type.description}}, + {{ plate.size.description}} +
  8. + {% endfor %} +
+
DeliveredIn Progress
+ {% endif %} +
+ +
+
+
+{% endblock %} \ No newline at end of file diff --git a/orders/templates/register.html b/orders/templates/register.html new file mode 100644 index 0000000..28ebd58 --- /dev/null +++ b/orders/templates/register.html @@ -0,0 +1,46 @@ +{% extends 'visitor.html' %} +{% block title %}Register{% endblock %} +{% block register_active %}active{% endblock %} + +{% block body %} +
+
+
+
+
+

Register Account

+ {% if messages %} +
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} +
+ {% csrf_token %} + + {% for field in form %} + + + + + + + {% endfor %} +
+ + + {{ field }} +
+
+
+ +
+
+
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/orders/templates/visitor.html b/orders/templates/visitor.html new file mode 100644 index 0000000..41eb675 --- /dev/null +++ b/orders/templates/visitor.html @@ -0,0 +1,51 @@ + + + + + Pizza App + + + + + + + +{% block body %} +{% endblock %} + + \ No newline at end of file diff --git a/orders/urls.py b/orders/urls.py index 2d9cdc0..2719386 100644 --- a/orders/urls.py +++ b/orders/urls.py @@ -2,6 +2,17 @@ from . import views +app_name = 'orders' + urlpatterns = [ - path("", views.index, name="index") -] + path("", views.index, name="index"), + path("register", views.register, name='register'), + path("enter", views.enter, name='enter'), + path("exit", views.exit, name='exit'), + path("pizza//", views.process_order, name='process_order'), + path("cart/", views.process_cart, name='process_cart'), + path("display_orders", views.display_orders, name='display_orders'), + path("clear_cart", views.clear_cart, name='clear_cart') + + +] \ No newline at end of file diff --git a/orders/views.py b/orders/views.py index c2bb9aa..98bee52 100644 --- a/orders/views.py +++ b/orders/views.py @@ -1,6 +1,242 @@ -from django.http import HttpResponse +from django.contrib.auth import authenticate, login, logout +from .forms import RegisterForm, LoginForm, ToppingsForm +from .models import Topping, Pizza_Assembly, Pizza_Type, Pizza, Order, Size, Option, Salad, Pasta, Item, Dinner_Plate_Type from django.shortcuts import render +from django.shortcuts import redirect +from decimal import Decimal +from django.contrib import messages -# Create your views here. def index(request): - return HttpResponse("Project 3: TODO") + + + # Get all collections needed to display menu + pizzas = Pizza.objects.all() + toppings = Topping.objects.all() + sizes = Size.objects.all() + types = Pizza_Type.objects.all() + options = Option.objects.all() + salads = Salad.objects.all() + pastas = Pasta.objects.all() + items = Item.objects.all() + plates = Dinner_Plate_Type.objects.all() + + # Pass all collections to the index page + return render(request, 'index.html', {'pizzas': pizzas, 'toppings': toppings, 'sizes': sizes, 'types': types, + 'options': options, 'salads': salads, 'pastas': pastas, 'items': items, + 'plates': plates }) + +def exit(request): + + # Logout current user and redirect to the menu + logout(request) + return redirect("/") + +def enter(request): + + # Create form from the request + form = LoginForm(request.POST or None) + + # If form is valid extract data + if form.is_valid(): + username = form.cleaned_data['username'] + password = form.cleaned_data['password'] + + # Try to authenticate the user + user = authenticate(username=username, password=password) + + # If user exists but not in the active state return an error + # If user does not exist return and error + # Otherwise login the user + if user is not None: + if user.is_active: + login(request, user) + return redirect("/") + else: + messages.error(request, "User is not active !!!") + else: + messages.error(request, "Incorrect user login !!!") + + return render(request, 'login.html', {'form': form}) + + +def register(request): + + # Create form from the request + form = RegisterForm(request.POST or None) + + # If form is valid extract data and save the user in the database + if form.is_valid(): + user = form.save(commit=False) + username = form.cleaned_data['username'] + password = form.cleaned_data['password'] + user.set_password(password) + user.save() + user = authenticate(username=username, password=password) + + # If user is not found return all the error encountered during registration + if user is not None: + login(request, user) + return redirect("/") + else: + messages.error(request, form.errors) + else: + messages.error(request, form.errors) + + return render(request, 'register.html', {'form': form}) + +def process_order(request, id, item): + + # If user is not authenticated redirect them to the login page + if not request.user.is_authenticated: + return render(request, 'login.html') + else: + if request.method == "POST": + + # Retrieve and order from the data base that has not been completed. It is impossible to have more than + # one uncompleted order for the same user + order = Order.objects.filter(customer=request.user.id, is_paid=False).first() + + # If order does not exist it must be new order + if order is None: + order = Order() + order.customer = request.user + order.is_complete = False + order.is_paid = False + order.save() + + # Check to see what is being ordered + if item == "pizza": + + pizza = Pizza.objects.get(pk=id) + toppings = Topping.objects.filter(description__in=request.POST.getlist('toppings')) + + if pizza.option.number_of_topings != len(request.POST.getlist('toppings')): + form = ToppingsForm() + return render(request, 'cart.html', {'error': 'Number of selected topics does not match choice of Pizza', + 'pizza': pizza, 'form': form }) + + # Looks like user is ordering pizza + pizza_assembly = Pizza_Assembly() + pizza_assembly.pizza = pizza + pizza_assembly.save() + pizza_assembly.toppings.add(*list(toppings)) + pizza_assembly.save() + + + order.pizzas_assemblies.add(pizza_assembly) + order.total = Decimal(order.total) + pizza.price + order.save() + + elif item == "salad": + + # Looks like user is ordering salad + salad = Salad.objects.get(pk=id) + order.salads.add(salad) + order.total = Decimal(order.total) + salad.price + order.save() + + elif item == "pasta": + + # Looks like user is ordering pasta + pasta = Pasta.objects.get(pk=id) + order.pastas.add(pasta) + order.total = Decimal(order.total) + pasta.price + order.save() + + elif item == "plate": + + # Looks like user is ordering dinner plate + plate = Item.objects.get(pk=id) + order.dinner_plates.add(plate) + order.total = Decimal(order.total) + plate.price + order.save() + + return render(request, 'order.html', {'order': order}) + + elif request.method == "GET": + + # if user is ordering pizza display toppings sellection form + if item == "pizza": + form = ToppingsForm() + pizza = Pizza.objects.get(pk=id) + + return render(request, 'cart.html', {'pizza': pizza, 'form': form}) + + elif item == "salad": + salad = Salad.objects.get(pk=id) + + return render(request, 'cart.html', {'salad': salad }) + + elif item == "pasta": + pasta = Pasta.objects.get(pk=id) + + return render(request, 'cart.html', {'pasta': pasta }) + + elif item == "plate": + plate = Item.objects.get(pk=id) + + return render(request, 'cart.html', {'plate': plate }) + + else: + return redirect("/") + +def process_cart(request, order_id): + + # If user is not authenticated redirect them to the login page + if not request.user.is_authenticated: + return render(request, 'login.html') + else: + if request.method == "POST": + + # Looks like user is trying to pay for the order + order = Order.objects.get(pk=order_id) + order.is_paid = True + order.save() + + return redirect("/") + + elif request.method == "GET": + + # Looks like user is trying to see what's in the cart + if order_id is not '0': + # If order id is passed fetch it, otherwise get first order for the user that has not been paid + order = Order.objects.get(pk=order_id) + else: + order = Order.objects.filter(customer=request.user.id, is_paid=False).first() + + if order is None: + return render(request, 'order.html', {'error': 'There are currently no active orders in the cart !!!'}) + else: + return render(request, 'order.html', {'order': order}) + +def clear_cart(request): + + # If user is not authenticated redirect them to the login page + if not request.user.is_authenticated: + return render(request, 'login.html') + else: + if request.method == "POST": + + # Looks like user is trying to start over. Let's delete first incomplete order + order = Order.objects.filter(customer=request.user.id, is_paid=False).first() + if order is not None: + order.delete() + + return redirect("/") + + +def display_orders(request): + + # If user is not authenticated redirect them to the login page + if not request.user.is_authenticated: + return render(request, 'login.html') + else: + + # Fetch all the paid orders for a given user + orders = Order.objects.filter(customer=request.user.id, is_paid=True).all() + + if len(orders) == 0: + return render(request, 'order_list.html', + {'error': 'You have no orders !!!'}) + else: + return render(request, 'order_list.html', {'orders': orders}) diff --git a/pizza/__pycache__/__init__.cpython-36.pyc b/pizza/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cbc2c5f519e4741a1a5aaacb57a92c932f32d944 GIT binary patch literal 131 zcmXr!<>m5~rFvc#g4 z80TPTPX$+9V`Imdf};Ga)Z`N5n1alzs>GQ1_{_Y_lK6PNg34PQHo5sJr8%i~Ad`xL Gm;nGJKpkxW literal 0 HcmV?d00001 diff --git a/pizza/__pycache__/settings.cpython-36.pyc b/pizza/__pycache__/settings.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9594f143a07b0ed3deac0d8689c5a5a8ab3f7be9 GIT binary patch literal 2258 zcmb7FSy$Ue6!s!);{e%6LX)&nTf)*7nI%n1PLoEl6>#H)gXGZYaH=D8$M%30qZx&w z*Zhq<_N70g@BIaO?Nk3ko_ZzQ;A3)5smB^$-Q~M??lRt(o-Y3U_D}uysZ{Fk)X1lR z^b360U${X^PeB?oc3Mx9^kL>OJF*L8;(a<^dJeLB9t6G6N$Ha?0XfJ+0VbgcS2}sU z2vaZ(GjJ8I!F9NSoGWlspMu#=3Iw(@YpFHuv3uaf=iWS^($j-X$Mhx!dz&~IWav-sS?=Qb?rcOavtmY2+> zbShP>9GY&&6B*&0x*aCAJzwn6Ff_%U?;R40OU2?Aafxqo0^-4`xCn{GiU|&NMaE5^ z4>T9WfFXuBfLxbW(e@SMIi62M>LRpba_YGvetDOoGisCX&^IY|Iq$Kjr4o1+llmTp z{w>cb5x0bJCGPd8#Y)3qOMQ6WC1N|UZPBKTi(dQuFs2LWh)`dAXW9W_|Hqe4+9Qts z!SbgX;W}MipvMbjGuZ4tUV3CadD!FYY;(E&%$h%9-m{~5YyRX#n{KYJeb1h)9k2ch zS~%zVKzt^dy&jXA30?NwHtmG7{gXD~AF9l6OJ&^NP;xS&`eZB?6H_-Dhm7x-HEJb&IAS<{h+(2e zjqCm7jaWVY#35{I9UYq15l({i%PZe>NV69=JsYtrCKDzFzRkkY0D}{!XXB7b2WU)O z7>zVC z0y)ldxG|=DmcdUL3}wqglz%CgUn`A@E>xSlZ~*5%mKZeiE>I~tJ+W^p&{25KaV3FZjXhXbWG1= z>;$LQz-xm-;!bKY;>$c9(|{9|I@C7fiFni3@ci)kWs&OCrB2|~h}+@abNinzYu_J` zok5J}052{J&wN?8&=IG_~7oYDR0fR&F+4MU$FR->J!(qDI&D)U9f)U#pho zxJx48(4%fNS&=n4cCJQqa!cDbc4SrEYwlKzH*&3t!X~!ZbWLt-wd5_uC^st#!dB~w zp*OKD3M~w~y7oh(Pu12|8&NLiX*!-nLr>*6nmY}mef0q3O_m?1U7ko1wojGn~*7F@8^ZAkP&j3^!dsO=X55W b%L@JX%#b^i6Y?=VTg+wSRV*Mvf93uK%ToCi literal 0 HcmV?d00001 diff --git a/pizza/__pycache__/urls.cpython-36.pyc b/pizza/__pycache__/urls.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6972e661454a472f5c7b9f0115f31e32c7f93070 GIT binary patch literal 951 zcma)5(Q4Z;6qOyP$((lEC+N*Fq;}W5nQg3umS&7StlPs(z*Q_Iaj+yK$=#aQe9b;% zzv0(C?HBemNpZjo1~ph*#JTsLbMDpj?96}v^=Ep~1K=0ve4dWq>0g=ygA`x~yQM?j z)OAeUD|^&SJ=#zE4j_H(5fAtG&feAW330b4+ri#lyXg=Q?m#$1%mtt-b~^;WeEI-q zoUMv=Es!cW^Zm~o0`F^4R!Au#n7oH&Ar%z7Rz#Wv2^EJA1^Ff;c*6yxTo72W6&KW& zfK^G5Bv2BP_)vcvr7D@kG3L39@D{N(uLR$cTtzvjF=6p#bP+3F6}gNJIM(fD>|cLJ zRM(P;e^ayEusgK1MPEhm3S)>EENI1rN+4VbP9c5FP*t^;9sFgBx01DhjzXQP#cswy zFllvdI3*Lv5G8K{69=I`E0L7vODzm{s{W4!R~sS>k;oc#q;solS@ut4WAG7@nJF?3 z|6w#|d0FFvt+ffZpOKd9VIKXNTVtT6qQ_&fWE{d(Yh`k<>oAVU7=9$#Vkg#=C$n9a zd>v~8kDUT@Ve1BA=>OJ>3qq&qBTNexy3L@)HJ-7)0lN_wmJ7?2PE)f ub~l^D>+|XKYSFIdbYWk}!qkYW$7cANa$J|>?F*eNhx+iGQ|D#x)cFhhq$Y|0 literal 0 HcmV?d00001 diff --git a/pizza/__pycache__/wsgi.cpython-36.pyc b/pizza/__pycache__/wsgi.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b0ac9fc8f3ca046d9f6e87ed0d732606d709da75 GIT binary patch literal 530 zcmYjN!A|2a5OthFtFWLwtT_8x2@6Rk490EccMM}N#GGN&0F&=)?!k=EGB*fz)oua&fc`^aEQZ-uct8+y;E4qRaa z{}1}d=^3rvm{{76`y(#B AEC2ui literal 0 HcmV?d00001