Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
__pycache__/
*.py[cod]
.vs
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
*.py[cod]
Empty file.
Empty file.
43 changes: 11 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,21 @@
- Gangzhaorige Li - Git Master / Back End Developer

## Live Project Link
[http://fridgeapp9000.com/](http://fridgeapp9000.com/)
[http://ec2-34-224-23-175.compute-1.amazonaws.com](http://ec2-34-224-23-175.compute-1.amazonaws.com)

### Test Server Link
[http://ec2-3-91-133-192.compute-1.amazonaws.com](http://ec2-3-91-133-192.compute-1.amazonaws.com)

## Branch Description
All branches other than Master, Dev_Main, and Documentation are dedicated to development of specific features of the application. Within those features are sub features that are also developed within the parent's feature's branch.

1. Master
- Current deployment of application and full documentation.
2. Dev_Main
- Finished features are pushed here for testing with other features.
3. Auth
- Development of the main landing page, authorization features, and user handling.
4. Fridge
- Fridge Landing
- Tracked Item Editing
- "Hamburger" Sidebar Functionality
5. Grocery
- Grocery landing page
- Manual Item Addition
- Tracked Item display
6. Capture
- Functionality of receipt capture
- Display of receipt contents "receipt review"
7. Recipe
- View saved recipes
- Search recipes
8. Profile
- View friended and owned fridges
- Edit personal notes
- Logout of app
9. Documentation
- This branch used for updating documentation of the application: ReadMe, Milestones, Etc.
- No other commits will be done here except for documentation.
- Should always be a derivative of branch Master.
## Instructor's ReadMe
-------------
Please when ready add your teams application URL or IP to the repository description. This will help with grading. Teams are expected to keep this value up to date.

Please do the following steps before completing Milestone 0.
1. Change the name of the repository. All that needs to change is the NN to your respective team number. Team numbers whose value is less than 10, please pad with a 0. Ex team 1 is Team01 team 11 is Team11. Please make sure to also remove the username from the repository as well. Teams with incorrectly name repository will have points deducted from their milestone 0 grades.
- Please follow the naming convention assigned by your instructor.

1. PLEASE REMOVE THE USERNAME FROM THE REPOSITORY NAME!!!

2. Add ALL members of your team to this repository. For it to count, they must ACCEPT the invite.

NO code needs to be stored in the root of your repository. You may rename the application folder if you like to your team's application name. But all source code related to your team's application should be stored inside the application folder.
36 changes: 10 additions & 26 deletions application/Django_refrigerator_project/Fridge_9000/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

PROD = False

ALLOWED_HOSTS = ['*']


Expand All @@ -40,7 +38,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'refrigerator_app',
'users',
'users.apps.UsersConfig',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -78,28 +76,16 @@
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases


if(PROD):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ref_updated_10_31',
'USER': 'admin',
'PASSWORD': 'password',
'HOST': 'refrigerator-db.c4p7z07xl4sc.us-east-1.rds.amazonaws.com',
'PORT': '3306',
}
}
else:
DATABASES = {
'default': {
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ref_db',
'USER': 'root',
'NAME': 'ref_updated_10_31',
'USER': 'admin',
'PASSWORD': 'password',
'HOST': 'mysql-db',
'HOST': 'refrigerator-db.c4p7z07xl4sc.us-east-1.rds.amazonaws.com',
'PORT': '3306',
}
}
}


# Password validation
Expand All @@ -126,13 +112,13 @@

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Los_Angeles'
TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = False
USE_TZ = True


# Static files (CSS, JavaScript, Images)
Expand All @@ -146,8 +132,6 @@
'/Django_refrigerator_project/static',
)

MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'

LOGIN_REDIRECT_URL = 'fridge_init' #need this to redirect to home from login
LOGIN_REDIRECT_URL = 'fridge' #need this to redirect to home from login
LOGIN_URL = 'login' #need this for login
27 changes: 10 additions & 17 deletions application/Django_refrigerator_project/Fridge_9000/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,19 @@
from django.conf.urls import include
from refrigerator_app import views
from recipes import views as recipe_views
from django.contrib.auth import views as auth_views
from users import views as user_views
from refrigerator_app import fridge as fridge_manager

from django.contrib.auth import views as auth_views #view from django, we will use for our login and logout
from users import views as user_views #view from our users apps
urlpatterns = [
path('', views.home, name='home'),
path('fridge/check/', fridge_manager.initialCurrentFridge, name='fridge_init'),
path('fridge/', views.fridge, name='fridge'),
path('add/', views.add_button, name='add_button'),
path('fridge/', views.fridge, name='fridge'),
path('groceries/', views.groceries, name='groceries'),
path('recipes/', recipe_views.recipe_landing, name='recipes'),
path('recipes/search/', recipe_views.recipe_search, name='recipe_search'),
path('recipes/search', recipe_views.recipe_search_results,
name='recipe_search_results'),
path('profile/', views.profile, name='profile'),
# path('upload/', views.receipt_upload, name='upload'),
path('auth/register/', user_views.register, name='register'),
path('recipes/', recipe_views.recipe_landing, name='recipes'),
path('recipes/search/', recipe_views.recipe_search, name='recipe_search'),
path('profile/', views.profile, name='profile'),
path('upload/', views.simple_upload, name='upload'),
path('auth/register/', user_views.register, name='register'), #the login and logout views are from Django, not in our views
path('auth/login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('auth/logout/', auth_views.LogoutView.as_view(
template_name='users/logout.html'), name='logout'),
path('auth/logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('admin/', admin.site.urls),
path('search/', views.search, name='search')
path('search/', views.search, name='search'),
]
17 changes: 1 addition & 16 deletions application/Django_refrigerator_project/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: '2'

services:
web:
Expand All @@ -8,18 +8,3 @@ services:
- .:/code
ports:
- "8000:8000"
depends_on:
- mysql-db
mysql-db:
container_name: mysql-db
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'ref_db'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
171 changes: 6 additions & 165 deletions application/Django_refrigerator_project/recipes/views.py
Original file line number Diff line number Diff line change
@@ -1,175 +1,16 @@
import json
import requests
import refrigerator_app.fridge as fridge_import

from django.shortcuts import render
from django.http import HttpResponse
from django.conf import settings
from django.contrib.auth.decorators import login_required
from refrigerator_app.models import Item, Fridge, FridgeContent, Recipe
from users.models import User
from django.db.models import Q
from refrigerator_app import views as fridge_views
from django.shortcuts import redirect

from datetime import datetime
from datetime import timedelta
from django.contrib.auth.decorators import login_required #for using @login_required decorator on top of a function
from refrigerator_app.models import Items

# Create your views here.

@login_required
def recipe_landing(request):
# Variables
fridge_manager = fridge_import.fridge_manager(request)
context = None

# Delete Saved Recipes
if request.method == 'POST' and request.POST.get('delete_recipe'):
try:
Recipe.objects.filter(
id=request.POST.get('delete_recipe')).delete()
return redirect('/recipes/')
except:
pass

# Get Fridge data and saved recipe data
try:
current_fridge = fridge_manager.getCurrentFridge()
saved_recipes = Recipe.objects.filter(fridge_id=current_fridge.id)
context = {'current_fridge': current_fridge,
'saved_recipes': saved_recipes}
except:
pass
return render(request, 'recipes/recipe_landing.html', context)

return render(request, 'recipes/recipe_landing.html')

@login_required
def recipe_search(request):
# Variables
fridge_manager = fridge_import.fridge_manager(request)
current_fridge = fridge_manager.getCurrentFridge()
current_time = datetime.now()

# Return all items if user has no fridge
try:
inventory_items = fridge_manager.getCurrentFridgeContent()
except:
inventory_items = fridge_manager.getAllItems()

context = {'current_fridge': current_fridge,
'inventory_items': inventory_items,
'current_date': current_time}
return render(request, 'recipes/recipe_search.html', context)


@login_required
def recipe_search_results(request):
# Variables
fridge_manager = fridge_import.fridge_manager(request)
current_fridge = None
recipe_data = None
context = None

# Get refrigerator data
try:
current_fridge = fridge_manager.getCurrentFridge()
context = {'current_fridge': current_fridge}
except:
print('RECIPE_RESULTS VIEW: No Fridge found.')

# Get recipe results
if request.method == 'GET':
try:
list = request.GET.getlist('ingredient', default=None)
ingredients = ""
for i in list:
ingredients = i + "," + ingredients
#recipe_data = food2fork_call(ingredients)
recipe_data = recipe_puppy(ingredients)
# context = {'current_fridge': current_fridge,
# 'recipes': recipe_data['recipes']}
context = {'current_fridge': current_fridge,
'recipes': recipe_data}
except:
print('RECIPE_RESULTS VIEW: Error getting food API data.')

# Save recipes
if request.method == 'POST' and request.POST.get('saved_recipe'):
try:
title, href = request.POST.get(
"saved_recipe").split(",")

recipe_save = Recipe(
eff_bgn_ts=datetime.now(),
eff_end_ts=datetime(9999, 12, 31),
user_id=request.session['current_user_id'],
fridge_id=request.session['current_fridge_id'],
title=title,
sourceurl=href,
imageurl=""
)
recipe_save.save()
return redirect('/recipes/')

except:
print('RECIPE_RESULTS VIEW: Error saving recipe.')
return render(request, 'recipes/recipe_search_results.html', context)


def recipe_puppy(list):

url = "http://www.recipepuppy.com/api/"

querystring = {"i":list,"p":"30","format":"json"}


response = requests.request("GET", url, params=querystring)

x = response.text
x=json.loads(x)

# x : data to be retunred
# to the calling function

x = x["results"]

#debugging purposes -- tbd ASAP
for item in x:
z = item["title"]
z = z.replace(' ', '')
z = z.replace('\n', '')
print(z,'\n',item["href"])

return(x)



def food2fork_call(list):
# Key 1 Attempt
key = '6e81eadfd535b092815e395bcc38be11'
paramsPost = {
'key': key,
'q': list,
'sort': 'r',
'page': '0'
}
responsePost = requests.post(
'https://www.food2fork.com/api/search', paramsPost)

# Key 2 Attempt
if responsePost.text == '{"error": "limit"}':
key = '57604ca61ce33d68532bb9af7f0472f9'
paramsPost = {
'key': key,
'q': list,
'sort': 'r',
'page': '0'
}
responsePost = requests.post(
'https://www.food2fork.com/api/search', paramsPost)

if responsePost.status_code == 202:
print('FOOD2FORK: Data received.')

# fakePost = '{"count": 30, "recipes": [{"publisher": "Simply Recipes", "f2f_url": "http://food2fork.com/view/36482", "title": "How to Make Fruit Leather", "source_url": "http://www.simplyrecipes.com/recipes/how_to_make_fruit_leather/", "recipe_id": "36482", "image_url": "http://static.food2fork.com/fruitleather300x2001f9f84c4.jpg", "social_rank": 99.99999999999989, "publisher_url": "http://simplyrecipes.com"}, {"publisher": "Simply Recipes", "f2f_url": "http://food2fork.com/view/37128", "title": "Waldorf Salad", "source_url": "http://www.simplyrecipes.com/recipes/waldorf_salad/", "recipe_id": "37128", "image_url": "http://static.food2fork.com/waldorfsalad300x20000f287fd.jpg", "social_rank": 99.9999667957302, "publisher_url": "http://simplyrecipes.com"}, {"publisher": "All Recipes", "f2f_url": "http://food2fork.com/view/15768", "title": "Groovy Green Smoothie", "source_url": "http://allrecipes.com/Recipe/Groovy-Green-Smoothie/Detail.aspx", "recipe_id": "15768", "image_url": "http://static.food2fork.com/4511209622.jpg", "social_rank": 99.97384730336904, "publisher_url": "http://allrecipes.com"}]}'
return json.loads(responsePost.text)
# return json.loads(fakePost)
inventory_items = Items.objects.all()
return render(request, 'recipes/recipe_search.html', context={'inventory_items':inventory_items})
Loading