Example #1
0
def load_data(test=False):
    with open("StoreMasterAssignment.csv") as f:
        datalist = [{k: str(v)
                     for k, v in row.items()}
                    for row in csv.DictReader(f, skipinitialspace=True)]

    if test is True:
        datalist = datalist[:5]

    for d in datalist:
        d["store_id"] = d.pop("StoreID")
        d["store_name"] = d.pop("StoreName")
        d["area_code"] = d.pop("AreaCode")
        Store.add_record(**d)
    print("store created", len(datalist))
Example #2
0
	def category_exist(self,name):
		user_id = session['user_id']
		categories = Store().get_user_categories(user_id)
		for category in categories:
			if (category['name'] == name):
				return True
		return False
Example #3
0
	def recipe_exist(self,name):
		user_id = session['user_id']
		recipes = Store().get_user_recipes(user_id)
		for recipe in recipes:
			if (recipe['name'] == name):
				return True
		return False
Example #4
0
	def is_exist(self,id):
		user_id = session['user_id']
		categories = Store().get_user_categories(user_id)
		for category in categories:
			if (category['id'] == id):
				return True
		return False
Example #5
0
	def update(self, name,category_id):
		user_id = session['user_id']
		categories = Store().get_user_categories(user_id)
		for category in categories:
			if self.is_exist(category_id):
				self.category_id = category_id
				self.name = name
				self.owner_id = category['owner_id']
				self.created = category['created_at']
				data = {
					'id': self.category_id,
					'owner_id': self.owner_id,
					'name': name,
					'created_at': self.created,
				}
				if (Store().update_category(data)):
					return True
				else:
					return False
			return True
Example #6
0
	def exist(self,email,password):
		users = Store().get_users()
		for user in users:
			# print(check_password_hash(user['password'], password))
			if (user['email'] == email and check_password_hash(user['password'], password)):
				self.user_id = user['id']
				self.name = user['name']
				self.email = user['email']
				self.password = user['password']
				return True
		return False
		
Example #7
0
	def update(self, name,description,category_id,id):
		user_id = session['user_id']
		recipes = Store().get_user_recipes(user_id)
		for recipe in recipes:
			if self.is_exist(id):
				self.category_id = category_id
				self.name = name
				self.owner_id = recipe['owner_id']
				self.created = recipe['created_at']
				data = {
					'id': id,
					'category_id': self.category_id,
					'owner_id': self.owner_id,
					'name': name,
					'description': description,
					'created_at': self.created,
				}
				if (Store().update_recipe(data)):
					return True
				else:
					return False
			return True
Example #8
0
	def save(self, name,owner_id,created,category_id=None):
		self.name = name
		self.category_id = uuid.uuid4().hex
		self.created = created
		self.owner_id = owner_id
		data = {
			'id': self.category_id,
			'owner_id': owner_id,
			'name': self.name,
			'created_at': self.created,
		}
		if (self.category_exist(self.name)):
			return False
		Store().add_category(data)
		return True
Example #9
0
def recipes():
    categories = Category().user_categories()
    categories_list = []
    for category in categories:
        cat = (category['id'], category['name'])
        categories_list.append(cat)
    form = RecipeForm.editRecipe(categories_list)  #Edit Recipe form
    addCategory = CategoryForm.AddForm()  #Addcategory  form
    categories = Store().get_user_categories(session['user_id'])
    recipes = Recipe().user_recipes()
    return render_template("recipes.html",
                           form=form,
                           categoryForm=addCategory,
                           categories=categories,
                           recipes=recipes)
Example #10
0
	def save(self, name,description,category_id):
		self.id = uuid.uuid4().hex
		self.name = name
		self.category_id = category_id
		self.description = description
		self.created = datetime.now()
		self.owner_id = session['user_id']
		data = {
			'id': self.id,
			'name': self.name,
			'category_id': self.category_id,
			'description': self.description,
			'owner_id': self.owner_id,
			'created_at': self.created
		}
		Store().save_recipe(data)
		return True
Example #11
0
	def save(self, name, email, password, created, user_id=None):
		self.name = name
		self.email = email
		self.password = password
		self.user_id = uuid.uuid4().hex if user_id is None else user_id
		self.created = created
		data = {
			'id': self.user_id,
			'name': self.name,
			'email': self.email,
			'password': self.password,
			'created_at': self.created,
			'categories': list(),
		}
		if (self.email_exist(self.email)):
			return False
		Store().add_user(data)
		return True
Example #12
0
from flask import render_template, session, redirect, flash, request, url_for, abort
from functools import wraps
from werkzeug.security import generate_password_hash
from datetime import datetime
from app import app
from app.forms import RegisterForm, LoginForm, RecipeForm, CategoryForm
from app.models.store import Store
from app.models.user import User
from app.models.category import Category
from app.models.recipe import Recipe

store = Store()
""" 
	Only logged in user Middleware function
"""


def auth(n):
    @wraps(n)
    def wrap(*args, **kwargs):
        if 'logged_in' in session and session[
                'logged_in'] == True and 'user_id' in session and session[
                    'logged_in'] and User().exist_id(session['user_id']):
            return n(*args, **kwargs)
        else:
            session.clear()
            return redirect(url_for('login'))

    return wrap

Example #13
0
	def exist_twice(self,name):
		user_id = session['user_id']
		recipes = Store().get_user_recipes(user_id)
		if (len(recipes) > 1):
			return True
		return False
Example #14
0
	def delete(self, category_id):
		if (Store().delete_category(category_id)):
			return True
		else:
			return False
Example #15
0
	def user_recipes(self):
		user_id = session['user_id']
		recipes = Store().get_user_recipes(user_id)
		for recipe in recipes:
			recipe['category'] = Category().category_name(recipe['category_id'])
		return recipes
Example #16
0
	def exist_categories(self):
		user_id = session['user_id']
		categories = Store().get_user_categories(user_id)
		if (len(categories) > 0):
			return True
		return False
Example #17
0
	def exist_id(self,id):
		users = Store().get_users()
		for user in users:
			if (user['id'] == id):
				return True
		return False
 def test_to_dict(self):
     row = Store.find_all()[0]
     data = row.to_dict()
     self.assertTrue(dict, type(row))
Example #19
0
	def user_categories(self):
		user_id = session['user_id']
		categories = Store().get_user_categories(user_id)
		return categories
 def test_find_one_returns_none(self):
     store_id = "XYZ"
     row = Store.find_one(store_id=store_id)
     self.assertEqual(None, row)
 def test_find_one(self):
     store_id = "S00339198"
     row = Store.find_one(store_id=store_id)
     self.assertTrue(isinstance(row, Store))
     self.assertEqual(store_id, row.store_id)
 def test_find_all_returns_empty(self):
     rows = Store.find_all(store_id="")
     self.assertTrue(list, type(rows))
     self.assertEqual(0, len(rows))
 def test_find_all(self):
     rows = Store.find_all()
     self.assertTrue(list, type(rows))
     self.assertEqual(5, len(rows))
Example #24
0
	def exist_twice(self,name):
		user_id = session['user_id']
		categories = Store().get_user_categories(user_id)
		if (len(categories) > 1):
			return True
		return False
Example #25
0
	def email_exist(self,email):
		users = Store().get_users()
		for user in users:
			if (user['email'] == email):
				return True
		return False
Example #26
0
	def delete(self, recipe_id):
		if (Store().delete_recipe(recipe_id)):
			return True
		else:
			return False
 def test_add_record(self):
     data = {"store_id": "XYZ123", "store_name": "XYZ", "area_code": "123"}
     Store.add_record(**data)
     row = Store.find_one(store_id="XYZ123")
     self.assertNotEqual(None, row)
Example #28
0
	def category_name(self,id):
		user_id = session['user_id']
		categories = Store().get_user_categories(user_id)
		for category in categories:
			if (category['id'] == id):
				return category['name']