Commit 74c30c3b authored by Julia Santos's avatar Julia Santos

Merge branch 'Item' into 'master'

Item

See merge request !6
parents 66990953 2c6e3121
myenv/ myenv/
*.pyc *.pyc
db.sqlite3 db.sqlite3
__pycache__ __pycache__
\ No newline at end of file media/upload/
\ No newline at end of file
from django import forms from django import forms
import datetime
from django.core.validators import FileExtensionValidator from django.core.validators import FileExtensionValidator
class LoginForm(forms.Form): class LoginForm(forms.Form):
...@@ -10,4 +11,13 @@ class ProductTypeForm(forms.Form): ...@@ -10,4 +11,13 @@ class ProductTypeForm(forms.Form):
Product_Category = forms.CharField(max_length = 255) Product_Category = forms.CharField(max_length = 255)
Product_Description = forms.CharField(max_length = 255, required = False) Product_Description = forms.CharField(max_length = 255, required = False)
To_Buy = forms.BooleanField(initial = False, required = False) To_Buy = forms.BooleanField(initial = False, required = False)
Icon = forms.ImageField(validators=[FileExtensionValidator( ['png','jpg'] ) ]) Icon = forms.ImageField(validators=[FileExtensionValidator( ['png','jpg'] ) ])
\ No newline at end of file
class AddItemForm(forms.Form):
Item_Quantity = forms.FloatField()
Quantity_Unit = forms.CharField(max_length = 255)
Item_Description = forms.CharField(max_length = 255, required = False)
Purchase_Date = forms.DateField(initial = datetime.datetime.now().date())
Expiration_Date = forms.DateField()
#Is_Expired = forms.BooleanField(initial = False, required = False)
Is_Consumed = forms.BooleanField(initial = False, required = False)
body { body {
width: 100%; width: 100%;
height: 100%; height: 100%;
margin: 0px; margin: 0px;
} }
.listViewHeader { .listViewHeader {
...@@ -20,61 +20,248 @@ body { ...@@ -20,61 +20,248 @@ body {
width: 100vw; width: 100vw;
display: grid; display: grid;
grid-template-columns: repeat(6, 16.67vw); grid-template-columns: repeat(6, 16.67vw);
grid-template-rows: 12.5vh 87.5vh;
text-align: left; text-align: left;
background-color: rgba(196, 196, 196, 1);
} }
.sidebar { .sidebar {
height: 100%; height: 200vh;
position:fixed;
width:265px;
background-color: rgba(196, 196, 196, 1); background-color: rgba(196, 196, 196, 1);
display: grid; display: grid;
grid-template-rows: repeat(16, 6.25vh); grid-template-rows: repeat(16, 6.25vh);
grid-template-columns: repeat(2, 8.33vw);
grid-column: 1/2; grid-column: 1/2;
z-index:1; z-index:1;
left:0; left:0;
} }
.sideItem { .sideItem {
grid-template-columns: repeat(2, 12.5vw); display: grid;
text-align: center;
background-color: rgba(104, 104, 104, 1); background-color: rgba(104, 104, 104, 1);
opacity: 0.7;
transform: none;
} }
.text { .sideText {
font-family: "Roboto"; font-family: "Roboto";
font-size: 24px; font-size: 24px;
color: white; color: white;
grid-column: 2/3; grid-column: 2/3;
margin-right: 5px;
text-align: right;
} }
.icon { #fridgeIcon {
background-color: white;
clip-path: circle();
height: 15vh;
grid-row: 1/6;
grid-column: 1/2; grid-column: 1/2;
margin: 10px;
} }
.circle { #recipesIcon {
margin: 5px; background-color: white;
clip-path: circle(); clip-path: circle();
height: 15vh;
grid-row: 4/9;
grid-column: 1/2;
margin: 10px;
}
#statsIcon {
background-color: white;
clip-path: circle();
height: 15vh;
grid-row: 7/12;
grid-column: 1/2;
margin: 10px;
}
#toBuyIcon {
background-color: white; background-color: white;
clip-path: circle();
height: 15vh;
grid-row: 10/15;
grid-column: 1/2;
margin: 10px;
} }
.fridge { .fridge {
grid-row: 3/4; grid-row: 3/4;
grid-column: 1/3;
} }
.recipes { .recipes {
grid-row: 6/7; grid-row: 6/7;
grid-column: 1/3;
} }
.stats { .stats {
grid-row: 9/10; grid-row: 9/10;
grid-column: 1/3;
} }
.toBuy { .toBuy {
grid-row: 12/13; grid-row: 12/13;
grid-column: 1/3;
}
.pageSubhead {
grid-column: 2/7;
grid-row: 1/2;
background-color: white;
display: grid;
grid-template-columns: 3vw repeat(6, 15.67vw) 3vw;
}
.subheader {
font-family: "Roboto Medium";
font-size: 10vh;
grid-column: 2/3;
text-align: center;
}
.addItem {
grid-column: 3/4;
}
.addItemButton {
margin-top: 35px;
margin-left: 20px;
margin-right: 20px;
background-color: rgba(175, 175, 175, 1);
border-radius: 100px;
opacity: 0.7;
transform: none;
}
.addItemText {
font-family: "Roboto Medium";
font-size: 18px;
color: white;
text-align: center;
}
.changeView {
background-color: rgba(228, 228, 228, 1);
font-family: "Roboto Medium";
font-size: 14px;
grid-column: 5/6;
margin-top: 35px;
text-align: center;
}
.listView {
grid-column: 2/7;
grid-row: 2/3;
background-color: white;
display: grid;
grid-template-columns: 3vw repeat(3, 23vw) 3vw;
grid-template-rows: repeat(4, 20vh);
grid-column-gap: 3vw;
grid-row-gap: 3vw;
}
.listItem {
background-color: rgba(237, 237, 237, 1);
display: grid;
grid-template-columns: 10vw 15vw;
grid-template-rows: repeat(5, 5vh);
opacity: 0.7;
transform: none;
}
#listIcon {
grid-column: 1/2;
grid-row: 1/5;
text-align: center;
clip-path: circle();
background-color: rgba(196, 196, 196, 1);
margin: 5px;
}
.listText {
grid-column: 2/3;
text-align: left;
margin: 10px;
}
.daysLeft {
font-family: "Roboto Black";
font-size: 24px;
}
.product {
font-family: "Roboto Regular";
font-size: 20px;
}
.category {
font-family: "Roboto Regular";
font-size: 14px;
}
.one {
grid-column: 2/3;
grid-row: 1/2;
}
.two {
grid-column: 2/3;
grid-row: 2/3;
}
.three {
grid-column: 2/3;
grid-row: 3/4;
}
.four {
grid-column: 2/3;
grid-row: 4/5;
}
.five {
grid-column: 3/4;
grid-row: 1/2;
}
.six {
grid-column: 3/4;
grid-row: 2/3;
}
.seven {
grid-column: 3/4;
grid-row: 3/4;
}
.eight {
grid-column: 3/4;
grid-row: 4/5;
}
.nine {
grid-column: 4/5;
grid-row: 1/2;
}
.ten {
grid-column: 4/5;
grid-row: 2/3;
}
.eleven {
grid-column: 4/5;
grid-row: 3/4;
}
.twelve {
grid-column: 4/5;
grid-row: 4/5;
} }
@font-face { @font-face {
font-family: Roboto Bold; font-family: Roboto Bold;
src: url(Roboto-Bold.ttf); src: url(Roboto-Bold.ttf);
} }
@font-face { @font-face {
font-family: Roboto; font-family: Roboto Black;
src: url(Roboto-Regular.ttf); src: url(Roboto-Black.ttf);
}
@font-face {
font-family: Roboto Medium;
src: url(Roboto-Medium.ttf);
}
@font-face {
font-family: Roboto;
src: url(Roboto-Regular.ttf);
}
.sideItem:hover {
opacity: 1;
transition: opacity .5s;
}
.listItem:hover {
opacity: 1;
transition: opacity .5s;
}
.addItemButton:hover {
opacity: 1;
transition: opacity .5s;
} }
.main{ .main{
margin-left:23%; margin-left: 23%;
} }
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
{% load static %}
<link rel="stylesheet" href="{%static "sidebar.css" %}">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title> <title>Add Item</title>
</head> </head>
<body> <body>
<h3>Contact Form</h3> <div class = "listViewHeader">
<hr/> <div class = "breadcrumbsHead">
<form method="post" action="/contact-form"> BREADCRUMBS
{% if messages %} </div>
{% for msg in messages %} </div>
<p>{{msg}}</p> <div class = "lowerPage">
{% endfor %} <div class = "sidebar">
{% endif %} <div class = "sideItem text fridge">
{% csrf_token %} FRIDGE
<table border="1" cellpadding="5"> </div>
<tr> <div class = "sideItem icon fridge">
<th>Product Name</th> <div class = "circle"> :3 </div>
<td><input type="text" name="product_name" /></td> </div>
</tr>
<tr> <div class = "sideItem text recipes">
<th>Product Category</th> RECIPES
<td><input type="email" name="product_category" /></td> </div>
</tr> <div class = "sideItem icon recipes">
<tr> <div class = "circle"> :3 </div>
<th>Product Description</th> </div>
<td>
<textarea name="product_description"></textarea> <div class = "sideItem text stats">
</td> STATS
</tr> </div>
<tr> <div class = "sideItem icon stats">
<th>To Buy</th> <div class = "circle"> :3 </div>
<td> </div>
<input type="checkbox" name="to_buy">
</td> <div class = "sideItem text toBuy">
</tr> TO BUY
<tr> </div>
<th>Icon</th> <div class = "sideItem icon toBuy">
<td> <div class = "circle"> :3 </div>
<input type="file" id = "iconFile" name="icon"> </div>
</td>
</tr> </div>
<tr> </div>
<td colspan="2"><input type="submit" value="Submit" /></td> <h3>Add Item</h3>
</tr> <form method="POST" enctype="multipart/form-data" div class="main">
</table> {% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form> </form>
<a href="http://127.0.0.1:8000/fridge/list" div class="main">Back</a>
</body> </body>
</html> </html>
\ No newline at end of file
<html>
<title>Fridge</title>
{% load static %}
<link rel="stylesheet" href="{%static "sidebar.css" %}">
{% block content %}
<style>
table, th, td {
border: 1px solid black;
}
</style>
<div class = "listViewHeader">
<div class = "breadcrumbsHead">
BREADCRUMBS
</div>
</div>
<div class = "lowerPage">
<div class = "sidebar">
<div class = "sideItem text fridge">
FRIDGE
</div>
<div class = "sideItem icon fridge">
<div class = "circle"> :3 </div>
</div>
<div class = "sideItem text recipes">
RECIPES
</div>
<div class = "sideItem icon recipes">
<div class = "circle"> :3 </div>
</div>
<div class = "sideItem text stats">
STATS
</div>
<div class = "sideItem icon stats">
<div class = "circle"> :3 </div>
</div>
<div class = "sideItem text toBuy">
TO BUY
</div>
<div class = "sideItem icon toBuy">
<div class = "circle"> :3 </div>
</div>
</div>
</div>
<h2>Fridge</h2>
<table style="width:70%" div class="main">
<tr><th colspan="5"><a href="{{request.path}}add"> Add</a></th></tr>
<tr>
<th><a href="http://127.0.0.1:8000/fridge/{{object_list.Product_ID}}">Name</a></th>
<th><a href="http://127.0.0.1:8000/fridge/{{object_list.Product_ID}}">Description</a></th>
<th>Quantity</th>
<th>Expiration Date</th>
<th>Purchase Date</th>
<th>Status</th>
</tr>
{% for item in object_list %}
<tr>
<th>
{{item.Product_ID.Product_Name}}
</th>
<th>
{{item.Item_Description}}
</th>
<th>
{{item.Item_Quantity}} {{item.Quantity_Unit}}
</th>
<th>
{{item.Expiration_Date}}
</th>
<th>
{{item.Purchase_Date}}
</th>
<th>
{{item.Is_Expired}}
</th>
<th>
<a href='http://127.0.0.1:8000/fridge/{{item.Product_ID}}/{{item.Item_ID}}/delete'>Delete?</a>
</th>
</tr>
{% endfor %}
</table>
{% endblock %}
</html>
...@@ -8,47 +8,55 @@ ...@@ -8,47 +8,55 @@
border: 1px solid black; border: 1px solid black;
} }
</style> </style>
<div class = "listViewHeader"> <div class = "listViewHeader">
<div class = "breadcrumbsHead"> <div class = "breadcrumbsHead">
BREADCRUMBS BREADCRUMBS
</div> </div>
</div> </div>
<div class = "lowerPage"> <div class = "lowerPage">
<div class = "sidebar"> <div class = "sidebar">
<div class = "sideItem text fridge"> <div class = "sideItem fridge">
FRIDGE <div class = " sideText"> FRIDGE </div>
</div>
<div class = "sideItem icon fridge">
<div class = "circle"> :3 </div>
</div> </div>
<img id= "fridgeIcon" src= "" alt= "a flat icon of a refrigerator";>
<div class = "sideItem text recipes"> <div class = "sideItem recipes">
RECIPES <div class = "sideText"> RECIPES </div>
</div>
<div class = "sideItem icon recipes">
<div class = "circle"> :3 </div>
</div> </div>
<img id= "recipesIcon" src= "" alt= "a flat icon of a cook book";>
<div class = "sideItem text stats"> <div class = "sideItem stats">
STATS <div class = "sideText"> STATS </div>
</div>
<div class = "sideItem icon stats">
<div class = "circle"> :3 </div>
</div> </div>
<img id= "statsIcon" src= "" alt= "a flat icon of a graph";>
<div class = "sideItem text toBuy"> <div class = "sideItem toBuy">
TO BUY <div class = "sideText"> TO BUY </div>
</div> </div>
<div class = "sideItem icon toBuy"> <img id= "toBuyIcon" src= "" alt= "a flat icon of a shopping cart";>
<div class = "circle"> :3 </div> </div>
<div class = "pageSubhead">
<div class = "subheader"> Fridge </div>
<div class = "addItem">
<div class = "addItemButton">
<div class = "addItemText"><a href="http://127.0.0.1:8000/fridge/add/"> ADD ITEM + </a></div>
</div>
</div> </div>
<div class = "changeView"> LIST VIEW </div>
</div>
</div> </div>
</div> </div>
<h2>Fridge</h2> <h2>Fridge</h2>
<table style="width:70%" div class="main"> <table style="width:70%" div class="main">
<tr><th colspan="5"><a href="http://127.0.0.1:8000/fridge/add/"> Add Item</a></th></tr>
<tr><th></th> <tr><th></th>
<th><a href="http://127.0.0.1:8000/fridge/list/">name</a></th> <th><a href="http://127.0.0.1:8000/fridge/list/">name</a></th>
<th><a href="http://127.0.0.1:8000/fridge/list-category">category</a></th> <th><a href="http://127.0.0.1:8000/fridge/list-category">category</a></th>
...@@ -62,7 +70,8 @@ ...@@ -62,7 +70,8 @@
<img src = "{{product.Icon.url}}" width = "100" height ="100"> <img src = "{{product.Icon.url}}" width = "100" height ="100">
</th> </th>
<th> <th>
{{product.Product_Name}} <a href='http://127.0.0.1:8000/fridge/{{product.Product_ID}}'>
{{product.Product_Name}}</a>
</th> </th>
<th> <th>
{{product.Product_Category}} {{product.Product_Category}}
......
...@@ -4,16 +4,19 @@ from django.conf.urls.static import static ...@@ -4,16 +4,19 @@ from django.conf.urls.static import static
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.urls import include, path from django.urls import include, path
from Breadcrumbs import views from Breadcrumbs import views
from .views import ProductListViewName, ProductListViewCategory, add_product_type, delete_product_type #ProductTypeDeleteView from .views import ProductListViewName, ProductListViewCategory, add_product_type, delete_product_type, ItemViewPDate, add_item, delete_item
urlpatterns = [ urlpatterns = [
url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'), url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'),
url(r'^fridge/list-category', ProductListViewCategory.as_view(), name='fridgeLC'), url(r'^fridge/list-category', ProductListViewCategory.as_view(), name='fridgeLC'),
url('accounts/', include('django.contrib.auth.urls')), url('accounts/', include('django.contrib.auth.urls')),
#url('', ProductListView.as_view(), name='home'), #url('', ProductListView.as_view(), name='home'),
path('fridge/add/', add_product_type, name = 'product-type-form'), path('fridge/add/', add_product_type, name = 'product-type-form'),
#path('fridge/<pk>/delete', ProductTypeDeleteView.as_view()), #path('fridge/<pk>/delete', ProductTypeDeleteView.as_view()),
path('fridge/<id>/delete', delete_product_type, name='product-type-delete'), path('fridge/<id>/delete', delete_product_type, name='product-type-delete'),
url(r'^fridge/(?P<Product_ID>\d+)/$', ItemViewPDate.as_view(), name='item-purchase-date-view'),
path('fridge/<id>/add', add_item, name = 'add-item'),
path('fridge/<id>/<id2>/delete', delete_item, name = 'delete-item')
] ]
if settings.DEBUG: if settings.DEBUG:
......
from django.views.generic import ListView from django.views.generic import ListView
from django.db.models import Q from django.db.models import Q
from .forms import LoginForm, ProductTypeForm from .forms import LoginForm, ProductTypeForm, AddItemForm
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404#, render_to_response
from django.forms import ValidationError from django.forms import ValidationError
from django.views.generic.edit import DeleteView from django.views.generic.edit import DeleteView
...@@ -83,15 +83,57 @@ def delete_product_type(request,id): ...@@ -83,15 +83,57 @@ def delete_product_type(request,id):
obj.delete() obj.delete()
return HttpResponseRedirect("/fridge/list/") return HttpResponseRedirect("/fridge/list/")
return render(request, 'product-type-confirm-delete.html',context) return render(request, 'product-type-confirm-delete.html', context)
# class ProductTypeDeleteView(DeleteView): class ItemViewPDate(ListView):
# models = Product_Type model = Item
# template_name = 'product-type-confirm-delete.html' template_name = 'placeholder-items.html'
# success_url = 'fridge/list/' context_object_name = 'item'
# def get_object(self, queryset=None): def get_queryset(self, **kwargs):
# obj = super(ProductTypeDeleteView, self).get_object() return Item.objects.filter(User_ID=self.request.user).order_by('Purchase_Date').filter(Product_ID=self.kwargs['Product_ID'])
# if not obj.owner == self.request.user:
# raise Http404 #def get_queryset(self, **kwargs):
# return obj # return Item.objects.filter(User_ID=self.request.user).order_by('Purchase_Date').filter(Product_ID=)
\ No newline at end of file # def get_context_data(self, **kwargs):
# return Item.objects.filter(User_ID=self.request.user).get(Product_ID=kwargs['Product_ID'])
#def item_view_by_pdate(request, Product_ID):
# items = Item.objects.filter(User_ID = self.request.user).filter(Product_ID= Product_ID)
# context = items
# return render(request,'placeholder-items.html',items)
def add_item(request, id):
context = {}
obj = get_object_or_404(Product_Type,Product_ID = id)
if request.method == 'POST':
form = AddItemForm(request.POST)
if form.is_valid():
#the name in quotation marks should match the name in the form
item_qty = form.cleaned_data.get("Item_Quantity")
qty_unit = form.cleaned_data.get("Quantity_Unit")
item_description = form.cleaned_data.get("Item_Description")
purchase_date = form.cleaned_data.get("Purchase_Date")
exp_date = form.cleaned_data.get("Expiration_Date")
is_consumed = form.cleaned_data.get("Is_Consumed")
product_type = obj
user_id = request.user
#equating the variables you just declared with the object youre creating
instance = Item.objects.create(Item_Quantity = item_qty, Quantity_Unit = qty_unit, Item_Description = item_description, Purchase_Date = purchase_date, Expiration_Date = exp_date, Is_Consumed = is_consumed, Product_ID = product_type, User_ID = user_id)
instance.save()
return HttpResponseRedirect('/fridge/'+str(obj.Product_ID))
else:
form = AddItemForm()
context['form'] = form
return render(request,'add-item.html',context)
def delete_item(request,id,id2):
context = {}
item = get_object_or_404(Item,Item_ID = id2)
prod_type = item.Product_ID
if request.method=="POST":
item.delete()
return HttpResponseRedirect("/fridge/" + str(prod_type))
return render(request, 'product-type-confirm-delete.html', context)
\ No newline at end of file
...@@ -55,32 +55,32 @@ body { ...@@ -55,32 +55,32 @@ body {
} }
#fridgeIcon { #fridgeIcon {
background-color: white; background-color: white;
clip-path: circle(); clip-path: circle();
height: 100px; height: 100px;
grid-row: 2/6; grid-row: 2/6;
grid-column: 1/2; grid-column: 1/2;
margin: 10px; margin: 10px;
} }
#recipesIcon { #recipesIcon {
background-color: white; background-color: white;
clip-path: circle(); clip-path: circle();
height: 100px; height: 100px;
grid-row: 5/9; grid-row: 5/9;
grid-column: 1/2; grid-column: 1/2;
margin: 10px; margin: 10px;
} }
#statsIcon { #statsIcon {
background-color: white; background-color: white;
clip-path: circle(); clip-path: circle();
height: 100px; height: 100px;
grid-row: 8/12; grid-row: 8/12;
grid-column: 1/2; grid-column: 1/2;
margin: 10px; margin: 10px;
} }
#toBuyIcon { #toBuyIcon {
background-color: white; background-color: white;
clip-path: circle(); clip-path: circle();
height: 100px; height: 100px;
grid-row: 11/15; grid-row: 11/15;
grid-column: 1/2; grid-column: 1/2;
margin: 10px; margin: 10px;
...@@ -113,4 +113,4 @@ body { ...@@ -113,4 +113,4 @@ body {
.main{ .main{
margin-left:23%; margin-left:23%;
} }
\ No newline at end of file
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