Commit a514ed45 authored by Julia Santos's avatar Julia Santos

Merge branch 'master' into 'To-Buy'

# Conflicts:
#   Breadcrumbs/views.py
parents 94f0d60c b7eb640e
......@@ -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)
if MyLoginForm.is_valid():
username = MyLoginForm.cleaned_data['username']
#class UserListView(ListView):
# model = User
# template_name = 'placeholder-list.html'
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'
......@@ -101,21 +110,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")
......@@ -128,7 +129,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
from django.core.exceptions import ValidationError
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
#I THINK what this does is raise an exception if the email already exists so I took it out for now since it's kinda out of our scope and gets in the way of me testing
"""
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