Commit 4f6e37f0 authored by Sylvane Suminguit's avatar Sylvane Suminguit

Merge branch 'ALERTS' into 'master'

Second Iteration changes

See merge request !7
parents 74c30c3b 141ec7c1
......@@ -5,7 +5,7 @@ from django.core.validators import FileExtensionValidator
class LoginForm(forms.Form):
user = forms.CharField(label = 'username', max_length = 100)
password = forms.CharField(widget = forms.PasswordInput())
class ProductTypeForm(forms.Form):
Product_Name = forms.CharField(max_length = 255)
Product_Category = forms.CharField(max_length = 255)
......@@ -19,5 +19,4 @@ class AddItemForm(forms.Form):
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)
from django.db import models
import datetime
from django.conf import settings
#from compositekey import db #used in the Ingredients class
#class User(models.Model):
# User_ID = models.AutoField(primary_key = True)
# User_Username = models.CharField(max_length = 255)
# User_Password = models.CharField(max_length = 255)
# User_Email = models.EmailField(max_length = 254)
#
# def __str__(self):
# return str(self.User_Email)
User = settings.AUTH_USER_MODEL
class Product_Type(models.Model):
Product_ID = models.AutoField(primary_key = True)
Product_Name = models.CharField(max_length = 255)
......
<html>
<title>Publishers</title>
{% block content %}
<style>
table, th, td {
border: 1px solid black;
}
</style>
<h2>Publishers</h2>
<table style="width:100%">
<tr><th>pub id</th><th>name</th><th>city</th><th>state</th><th>country</th><th>pr info</th></tr>
{% for user in object_list %}
<tr>
<th>{{user.user_id}}</th>
</tr>
{% endfor %}
</table>
{% endblock %}
</html>
<html>
<title> Home </title>
<body>
<main>
HELLO
</main>
</body>
</html>
\ No newline at end of file
<form method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm">
</form>
......@@ -10,9 +10,7 @@ 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/<pk>/delete', ProductTypeDeleteView.as_view()),
path('fridge/add/', add_product_type, name = 'product-type-form'),
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'),
......
......@@ -2,20 +2,29 @@ from django.views.generic import ListView
from django.db.models import Q
from .forms import LoginForm, ProductTypeForm, AddItemForm
from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404#, render_to_response
from django.shortcuts import render, get_object_or_404
from django.forms import ValidationError
from django.views.generic.edit import DeleteView
from HungerBuster.settings import EMAIL_HOST_USER
from . import forms
from django.core.mail import send_mail
from .models import User, Product_Type, Item, Recipe
def login(request):
username = "not logged in"
if request.method =="POST":
MyLoginForm = LoginForm(request.POST)
#class UserListView(ListView):
# model = User
# template_name = 'placeholder-list.html'
if MyLoginForm.is_valid():
username = MyLoginForm.cleaned_data['username']
else:
MyLoginForm = Loginform()
return render(request, loggedin.html,{"username" : username})
# def get_queryset(self):
# return User.objects.all().order_by('User_ID')
#User = settings.AUTH_USER_MODEL
class ProductListViewName(ListView):
model = Product_Type
template_name = 'placeholder-list.html'
......@@ -31,23 +40,7 @@ class ProductListViewCategory(ListView):
def get_queryset(self):
return Product_Type.objects.filter(User_ID=self.request.user).order_by('Product_Category')
def login(request):
username = "not logged in"
if request.method =="POST":
MyLoginForm = LoginForm(request.POST)
if MyLoginForm.is_valid():
username = MyLoginForm.cleaned_data['username']
#return HttpResponseRedirect('/fridge/list')
else:
MyLoginForm = Loginform()
return render(request, loggedin.html,{"username" : username})
def add_product_type(request):
context = {}
if request.method == 'POST':
......@@ -93,21 +86,13 @@ class ItemViewPDate(ListView):
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")
......@@ -120,7 +105,20 @@ def add_item(request, id):
#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()
'''
#not sure if this works
print(User_ID=self.email)
if purchase_date - exp_date <= 1:
subject = 'SPOILER ALERT!'
message = 'YOUR FOOD IS GOING TO EXPIRE SOON! BETTER *MUNCH* IT FAST BEFORE I DO!'
recipient = str(User_ID=self.email)
send_mail (subject, message, EMAIL_HOST_USER, [recipient], fail_silently = False)
return render(request, 'add-item.html', {'recipient' : recipient})
'''
return HttpResponseRedirect('/fridge/'+str(obj.Product_ID))
else:
form = AddItemForm()
context['form'] = form
......
......@@ -10,6 +10,7 @@ body {
color: white;
text-align: left;
}
.breadcrumbsHead {
font-family: "Roboto Bold";
font-size: 46px;
......@@ -22,6 +23,7 @@ body {
grid-template-columns: repeat(6, 16.67vw);
text-align: left;
}
.sidebar {
height: 100%;
position: fixed;
......
......@@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'Breadcrumbs',
'accounts',
]
MIDDLEWARE = [
......@@ -104,6 +105,16 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
#Email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'antonybreadcrumbs@gmail.com'
EMAIL_HOST_PASSWORD = 'BREADCRUMBS1234'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
......
......@@ -15,8 +15,10 @@ Including another URLconf
"""
from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path
urlpatterns = [
url(r'^admin/', admin.site.urls),
path('accounts/', include('accounts.urls')),
url(r'', include('Breadcrumbs.urls') ),
]
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AccountsConfig(AppConfig):
name = 'accounts'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.urls import path
from django.views.generic.edit import CreateView
from django.contrib.auth.forms import UserCreationForm
from django.urls import reverse_lazy
from accounts import views
from .views import UserCreateForm
urlpatterns = [
path('signup/', CreateView.as_view( template_name = "registration/signup.html", form_class = UserCreateForm, success_url= reverse_lazy('login')) , name = 'signup'),
]
\ No newline at end of file
from django.shortcuts import render
from django.contrib.auth.forms import UserCreationForm, User
from django.urls import reverse_lazy
from django.views import generic
from django import forms
class UserCreateForm(UserCreationForm):
email = forms.EmailField(required = True, label ='Email',)
class Meta:
model = User
fields = ("username", "email", "password1", "password2")
def save(self, commit=True):
user = super(UserCreateForm, self).save(commit=False)
user.email = self.cleaned_data["email"]
if commit:
user.save()
return user
def clean_email(self):
if User.objects.filter(email=self.cleaned_data['email']).exists():
raise ValidationError(self.fields['email'].error_messages['exists'])
return self.cleaned_data['email']
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title> Sign Up to BreadCrumbs! </title>
<!-- I used a random css online so pls change it to what we're using -->
<link rel="stylesheet" href "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<center>
<h1 class = 'alert alert-success'> Sign Up </h1>
<h3 class = "p-3 mb-2 bg-primary text-white" style = 'font-size: 50px;'>BREADCRUMBS EMAIL </h3>
<form method="POST">
<!-- Very Important csrf Token -->
{% csrf_token %}
<div class = "form-group">
<p>
<h3> {{ form.as_p }} </h3>
</p>
<br>
<input type="submit" name="SignUp" class = 'btn btn-primary btn-lg'>
</div>
</form>
</center>
</body>
</html>
\ 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