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

Merge branch 'Item' into 'master'

Item

See merge request !6
parents 66990953 2c6e3121
myenv/
*.pyc
db.sqlite3
__pycache__
\ No newline at end of file
__pycache__
media/upload/
\ No newline at end of file
from django import forms
import datetime
from django.core.validators import FileExtensionValidator
class LoginForm(forms.Form):
......@@ -10,4 +11,13 @@ class ProductTypeForm(forms.Form):
Product_Category = forms.CharField(max_length = 255)
Product_Description = forms.CharField(max_length = 255, required = False)
To_Buy = forms.BooleanField(initial = False, required = False)
Icon = forms.ImageField(validators=[FileExtensionValidator( ['png','jpg'] ) ])
\ No newline at end of file
Icon = forms.ImageField(validators=[FileExtensionValidator( ['png','jpg'] ) ])
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 {
width: 100%;
height: 100%;
margin: 0px;
width: 100%;
height: 100%;
margin: 0px;
}
.listViewHeader {
......@@ -20,61 +20,248 @@ body {
width: 100vw;
display: grid;
grid-template-columns: repeat(6, 16.67vw);
grid-template-rows: 12.5vh 87.5vh;
text-align: left;
background-color: rgba(196, 196, 196, 1);
}
.sidebar {
height: 100%;
position:fixed;
width:265px;
height: 200vh;
background-color: rgba(196, 196, 196, 1);
display: grid;
grid-template-rows: repeat(16, 6.25vh);
grid-template-columns: repeat(2, 8.33vw);
grid-column: 1/2;
z-index:1;
left:0;
}
.sideItem {
grid-template-columns: repeat(2, 12.5vw);
text-align: center;
display: grid;
background-color: rgba(104, 104, 104, 1);
opacity: 0.7;
transform: none;
}
.text {
.sideText {
font-family: "Roboto";
font-size: 24px;
color: white;
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;
margin: 10px;
}
.circle {
margin: 5px;
#recipesIcon {
background-color: white;
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;
clip-path: circle();
height: 15vh;
grid-row: 10/15;
grid-column: 1/2;
margin: 10px;
}
.fridge {
grid-row: 3/4;
grid-column: 1/3;
}
.recipes {
grid-row: 6/7;
grid-column: 1/3;
}
.stats {
grid-row: 9/10;
grid-column: 1/3;
}
.toBuy {
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-family: Roboto Bold;
src: url(Roboto-Bold.ttf);
font-family: Roboto Bold;
src: url(Roboto-Bold.ttf);
}
@font-face {
font-family: Roboto;
src: url(Roboto-Regular.ttf);
font-family: Roboto Black;
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{
margin-left:23%;
}
\ No newline at end of file
margin-left: 23%;
}
<!DOCTYPE html>
<html lang="en">
{% load static %}
<link rel="stylesheet" href="{%static "sidebar.css" %}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
<title>Add Item</title>
</head>
<body>
<h3>Contact Form</h3>
<hr/>
<form method="post" action="/contact-form">
{% if messages %}
{% for msg in messages %}
<p>{{msg}}</p>
{% endfor %}
{% endif %}
{% csrf_token %}
<table border="1" cellpadding="5">
<tr>
<th>Product Name</th>
<td><input type="text" name="product_name" /></td>
</tr>
<tr>
<th>Product Category</th>
<td><input type="email" name="product_category" /></td>
</tr>
<tr>
<th>Product Description</th>
<td>
<textarea name="product_description"></textarea>
</td>
</tr>
<tr>
<th>To Buy</th>
<td>
<input type="checkbox" name="to_buy">
</td>
</tr>
<tr>
<th>Icon</th>
<td>
<input type="file" id = "iconFile" name="icon">
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
<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>
<h3>Add Item</h3>
<form method="POST" enctype="multipart/form-data" div class="main">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
<a href="http://127.0.0.1:8000/fridge/list" div class="main">Back</a>
</body>
</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 @@
border: 1px solid black;
}
</style>
<div class = "listViewHeader">
<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 class = "sideItem fridge">
<div class = " sideText"> FRIDGE </div>
</div>
<img id= "fridgeIcon" src= "" alt= "a flat icon of a refrigerator";>
<div class = "sideItem text recipes">
RECIPES
</div>
<div class = "sideItem icon recipes">
<div class = "circle"> :3 </div>
<div class = "sideItem recipes">
<div class = "sideText"> RECIPES </div>
</div>
<img id= "recipesIcon" src= "" alt= "a flat icon of a cook book";>
<div class = "sideItem text stats">
STATS
</div>
<div class = "sideItem icon stats">
<div class = "circle"> :3 </div>
<div class = "sideItem stats">
<div class = "sideText"> STATS </div>
</div>
<img id= "statsIcon" src= "" alt= "a flat icon of a graph";>
<div class = "sideItem text toBuy">
TO BUY
<div class = "sideItem toBuy">
<div class = "sideText"> TO BUY </div>
</div>
<div class = "sideItem icon toBuy">
<div class = "circle"> :3 </div>
<img id= "toBuyIcon" src= "" alt= "a flat icon of a shopping cart";>
</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 class = "changeView"> LIST VIEW </div>
</div>
</div>
</div>
<h2>Fridge</h2>
<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>
<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>
......@@ -62,7 +70,8 @@
<img src = "{{product.Icon.url}}" width = "100" height ="100">
</th>
<th>
{{product.Product_Name}}
<a href='http://127.0.0.1:8000/fridge/{{product.Product_ID}}'>
{{product.Product_Name}}</a>
</th>
<th>
{{product.Product_Category}}
......
......@@ -4,16 +4,19 @@ from django.conf.urls.static import static
from django.views.generic import TemplateView
from django.urls import include, path
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 = [
url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'),
url(r'^fridge/list-category', ProductListViewCategory.as_view(), name='fridgeLC'),
url('accounts/', include('django.contrib.auth.urls')),
#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/<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:
......
from django.views.generic import ListView
from django.db.models import Q
from .forms import LoginForm, ProductTypeForm
from .forms import LoginForm, ProductTypeForm, AddItemForm
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.views.generic.edit import DeleteView
......@@ -83,15 +83,57 @@ def delete_product_type(request,id):
obj.delete()
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):
# models = Product_Type
# template_name = 'product-type-confirm-delete.html'
# success_url = 'fridge/list/'
class ItemViewPDate(ListView):
model = Item
template_name = 'placeholder-items.html'
context_object_name = 'item'
# def get_object(self, queryset=None):
# obj = super(ProductTypeDeleteView, self).get_object()
# if not obj.owner == self.request.user:
# raise Http404
# return obj
\ No newline at end of file
def get_queryset(self, **kwargs):
return Item.objects.filter(User_ID=self.request.user).order_by('Purchase_Date').filter(Product_ID=self.kwargs['Product_ID'])
#def get_queryset(self, **kwargs):
# return Item.objects.filter(User_ID=self.request.user).order_by('Purchase_Date').filter(Product_ID=)
# 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 {
}
#fridgeIcon {
background-color: white;
clip-path: circle();
height: 100px;
clip-path: circle();
height: 100px;
grid-row: 2/6;
grid-column: 1/2;
margin: 10px;
}
#recipesIcon {
background-color: white;
clip-path: circle();
height: 100px;
clip-path: circle();
height: 100px;
grid-row: 5/9;
grid-column: 1/2;
margin: 10px;
}
#statsIcon {
background-color: white;
clip-path: circle();
height: 100px;
clip-path: circle();
height: 100px;
grid-row: 8/12;
grid-column: 1/2;
margin: 10px;
}
#toBuyIcon {
background-color: white;
clip-path: circle();
height: 100px;
clip-path: circle();
height: 100px;
grid-row: 11/15;
grid-column: 1/2;
margin: 10px;
......@@ -113,4 +113,4 @@ body {
.main{
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