Created new forms and views accordingly for functioning order and inventory views

parent fb8ba6c0
{% extends 'blizzardblast\templates\base.html' %}
{% load static %}
{% block title %}Add Customer{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form action="/addBaseFlavor" method="POST" style="text-align:center">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'blizzardblast\templates\base.html' %}
{% load static %}
{% block title %}Add Customer{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form action="/addcustomer" method="POST" style="text-align:center">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'blizzardblast\templates\base.html' %}
{% load static %}
{% block title %}Add order{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form action="/addingredient" method="POST" style="text-align:center">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'blizzardblast\templates\base.html' %}
{% load static %}
{% block title %}Add Ingredient in Inventory{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form action="/addinventory" method="post" style="text-align:center">
{% csrf_token %}
{{inventory_form.as_p}}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'blizzardblast\templates\base.html' %}
{% load static %}
{% block title %}Add item{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form action="/additem" method="POST" style="text-align:center">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'blizzardblast\templates\base.html' %}
{% load static %}
{% block title %}Add order{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form action="/addorder" method="POST" style="text-align:center">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
from django import forms from django import forms
from django.forms import (ModelForm, from django.forms import (ModelForm,
TextInput, Textarea, widgets) TextInput, Textarea, widgets)
from .models import Customer, Orders, Item from .models import *
class AddOrderForm(forms.ModelForm): class AddOrderForm(forms.ModelForm):
class Meta: class Meta:
model = Orders model = Orders
fields = '__all__' fields = '__all__'
# customer_no = forms.IntegerField(label='Customer no')
# customer_name = forms.CharField(label='Customer Name', max_length=50) class AddItemForm(forms.ModelForm):
# date = forms.DateField(label='Date') class Meta:
# base_recipe = forms.CharField(label='Base Recipe') model = Item
# add_on_qty = forms.IntegerField(label='Add-on Qty') fields = '__all__'
# add_on_name = forms.CharField(label='Add-on')
class AddCustomerForm(forms.ModelForm):
class Meta:
model = Customer
fields = '__all__'
class AddIngredient(forms.ModelForm):
class Meta:
model = Ingredient
fields = '__all__'
class AddBaseFlavor(forms.ModelForm):
class Meta:
model = BaseFlavor
fields = '__all__'
INGREDIENT_CATEGORIES = ( INGREDIENT_CATEGORIES = (
(1,'nuts'), (1,'nuts'),
......
...@@ -4,7 +4,7 @@ from .views import * ...@@ -4,7 +4,7 @@ from .views import *
urlpatterns = [ urlpatterns = [
# main views # main views
path('', homepage, name='homepage'), path('', homepage, name='homepage'),
# order view # order view
path('order', order, name='order'), path('order', order, name='order'),
path('receipt', receipt, name='receipt'), path('receipt', receipt, name='receipt'),
path('inventory', inventory, name='inventory'), path('inventory', inventory, name='inventory'),
...@@ -14,6 +14,10 @@ urlpatterns = [ ...@@ -14,6 +14,10 @@ urlpatterns = [
#forms #forms
path('addorder', addorder, name='addorder'), path('addorder', addorder, name='addorder'),
path('additem', additem, name='additem'),
path('addcustomer', addcustomer, name='addcustomer'),
path('addingredient', addingredient, name='addingredient'),
path('addBaseFlavor', addbaseflavor, name='addBaseFlavor'),
path('addinventory', addinventory, name='addinventory'), path('addinventory', addinventory, name='addinventory'),
#queries #queries
......
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from .forms import AddInventoryForm, AddOrderForm from .forms import *
from .models import * from .models import *
# ========================== MAIN VIEWS ==========================
def homepage(request): def homepage(request):
return render(request, "blizzardblast/templates/index.html") return render(request, "blizzardblast/templates/index.html")
def order(request): def order(request):
orders_context = Orders.objects.all() orders_context = Orders.objects.all()
return render(request, "blizzardblast/templates/order.html", {'orders': orders_context}) return render(request, "blizzardblast/templates/order.html", {'orders': orders_context})
def receipt(request): def receipt(request):
return render(request, "blizzardblast/templates/receipt.html") return render(request, "blizzardblast/templates/receipt.html")
def inventory(request): def inventory(request):
return render(request, "blizzardblast/templates/inventory.html") ingredients_context = Ingredient.objects.all()
base_flavor_context = BaseFlavor.objects.all()
contexts = {
'baseflavor' : base_flavor_context,
'inventory' : ingredients_context
}
return render(request, "blizzardblast/templates/inventory.html", contexts)
def schedule(request): def schedule(request):
all_values = EmployeeRole.objects.all() all_values = EmployeeRole.objects.all()
return render(request,
# 5: FILTER EMPLOYEES AND ROLES BY DATE IN ORDER - xx "blizzardblast/templates/schedule.html",
date_order_query = EmployeeRole.objects.all().order_by('role_date') {'all_values': all_values}
return render(request, "blizzardblast/templates/schedule.html", {
'all_values': all_values
}
) )
def report(request):
return render(request, "blizzardblast/templates/report.html")
# ========================== SCHEDULE QUERIES ==========================
# 1: FILTER EMPLOYEES BY MANAGER FOR THE DAY - mate # 1: FILTER EMPLOYEES BY MANAGER FOR THE DAY - mate
def manager_query(request): def manager_query(request):
ismanager_query = EmployeeRole.objects.all().filter(is_manager='Y') ismanager_query = EmployeeRole.objects.all().filter(is_manager='Y')
...@@ -64,27 +65,21 @@ def role_query(request): ...@@ -64,27 +65,21 @@ def role_query(request):
# 2: FILTER EMPLOYEES IN ALPHABETICAL ORDER - felizia # 2: FILTER EMPLOYEES IN ALPHABETICAL ORDER - felizia
def alphabetical_query(request): def alphabetical_query(request):
alphabetical_query = EmployeeRole.objects.order_by( alphabetical_query = EmployeeRole.objects.order_by(
'employee__employee_name') 'employee__employee_name')
for i in alphabetical_query: for i in alphabetical_query:
print(i) print(i)
return render(request, "blizzardblast/templates/queries/alphabetical_query.html", { return render(request, "blizzardblast/templates/queries/alphabetical_query.html", {
'alphabetical': alphabetical_query 'alphabetical': alphabetical_query
}) })
def report(request):
return render(request, "blizzardblast/templates/report.html")
# FORMS # ========================== FORMS ==========================
def addorder(request): def addorder(request):
form = AddOrderForm() form = AddOrderForm()
context = {'form': form }
context = {
'form': form
}
if request.method == 'POST': if request.method == 'POST':
#print("Printing post: ", request.POST) #print("Printing post: ", request.POST)
...@@ -93,9 +88,48 @@ def addorder(request): ...@@ -93,9 +88,48 @@ def addorder(request):
form.save() form.save()
return redirect('/order') return redirect('/order')
return render(request, "blizzardblast/templates/addorder.html", context) return render(request, "blizzardblast/templates/forms/addorder.html", context)
def additem(request):
form = AddItemForm()
context = {'form':form}
if request.method == 'POST':
form = AddItemForm(request.POST)
if form.is_valid():
form.save()
return redirect('/order')
return render(request, "blizzardblast/templates/forms/additem.html", context)
def addcustomer(request):
form = AddCustomerForm()
context = {'form':form}
if request.method == 'POST':
form = AddCustomerForm(request.POST)
if form.is_valid():
form.save()
return redirect('/order')
return render(request, "blizzardblast/templates/forms/addcustomer.html", context)
def addingredient(request):
form = AddIngredient()
context = {'form':form}
if request.method == 'POST':
form = AddIngredient(request.POST)
if form.is_valid():
form.save()
return redirect('/inventory')
return render(request, "blizzardblast/templates/forms/addingredient.html", context)
def addbaseflavor(request):
form = AddBaseFlavor()
context = {'form':form}
if request.method == 'POST':
form = AddBaseFlavor(request.POST)
if form.is_valid():
form.save()
return redirect('/inventory')
return render(request, "blizzardblast/templates/forms/addBaseFlavor.html", context)
def addinventory(request): def addinventory(request):
form = AddInventoryForm() form = AddInventoryForm()
return render(request, "blizzardblast/templates/addinventory.html", {'form':form}) return render(request, "blizzardblast/templates/forms/addinventory.html", {'form':form})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment