| # | +Product | +Status | +Controls | +
|---|---|---|---|
| {{ order.id }} | +{{ order.product_name }} | +{{ order.status }} | +Cancel + +1 | +
{{ order.shipping.status }}
+{{ order.shipping.address }}
+{{ product.desc }}
++ Order now +
+{% endblock %} \ No newline at end of file diff --git a/products/templates/products/product_form.html b/products/templates/products/product_form.html new file mode 100644 index 0000000..d183e13 --- /dev/null +++ b/products/templates/products/product_form.html @@ -0,0 +1,7 @@ +{% extends "products/base.html" %} +{% block content %} + +{% endblock %} \ No newline at end of file diff --git a/products/tests.py b/products/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/products/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/products/utils.py b/products/utils.py new file mode 100644 index 0000000..f8df90e --- /dev/null +++ b/products/utils.py @@ -0,0 +1,34 @@ +import random +import string + +from AdvancedDevelopment.firebase import FirebaseClient + + +def gen_ran(size=16): + """e.g. mqPssj5bbYDOSoy5""" + return ''.join([random.choice(string.ascii_letters + string.digits) for n in range(size)]) + + +def generate_id(client: FirebaseClient): + """Generate ID using gen_ran and rotate it until it's unique in the client""" + id_gen = gen_ran() + while client.get_by_id(id_gen) is not False: # if id is taken, find another until one is free + id_gen = gen_ran() + + return id_gen + + +def read_login_session(request): + try: + return request.session["login"] + except KeyError: + return "" + + +def logged_in(session_ref): + login = False + if session_ref: + get_user = FirebaseClient("users").get_by_id(session_ref) + if get_user: # if user is logged in + login = True + return login diff --git a/products/views.py b/products/views.py new file mode 100644 index 0000000..f0c8fa3 --- /dev/null +++ b/products/views.py @@ -0,0 +1,154 @@ +from django.contrib import messages +from django.http import HttpResponseNotFound +from django.shortcuts import render, redirect +from django.views.generic import CreateView + +import users.views +from AdvancedDevelopment.firebase import FirebaseClient +from products.models import Product +from .utils import generate_id, read_login_session, logged_in + +client_products = FirebaseClient("products") + +ORDER_STATUS_TEXT = [ + ("1", "Order pending"), + ("2", "Order confirmed, awaiting dispatch"), + ("3", "Dispatched, awaiting courier"), + ("4", "With courier, awaiting delivery"), + ("5", "Out for delivery"), + ("6", "Order delivered and fulfilled") +] + + +def home(request): + """Renders homepage. Context: all products (obj) and if user logged-in (bool)""" + # session = request.session["login"] + session = read_login_session(request) + auth = logged_in(session) + + all_products = client_products.all() + return render(request, "products/home.html", {"products": all_products, + "logged_in": auth}) + + +class ProductCreateView(CreateView): + model = Product + fields = ["name", "desc"] + + +def product_detail_view(request, pk): + product_doc = client_products.get_by_id(pk) + + if product_doc is not False: + return render(request, "products/product_detail.html", {"product": product_doc}) + else: + return HttpResponseNotFound('{{ user.email }}
+{{ ban.get_ban_type_display|capfirst }} ban + issued {{ ban.issued_when|date:"jS F, Y" }}{% if ban.expires is None %}.{% else %},{% endif %} + {% if ban.expires %} + expires {{ ban.expires|date:"jS F, Y" }} at {{ ban.expires|date:"g:i a" }} + {% endif %} +
+ {% if ban.issued_message %} ++ + {{ ban.issued_message }} + +
+ {% endif %} +