def create(cls, data): mysql = MySQLConnection('recipe_schema') query = ( "insert into recipes (name, description, instructions, cook_time, user_id) values (%(name)s, %(description)s, %(instructions)s, %(cook_time)s, %(user_id)s)" ) recipe = mysql.query_db(query, data) return recipe
def is_unique(cls, data): is_valid = True mysql = MySQLConnection('email_schema') query = ("select * from emails where email_address = (%(email)s)") test = mysql.query_db(query, data) if len(test) > 0: is_valid = False return is_valid
def edit(cls, data): mysql = MySQLConnection('recipe_schema') query = ( "update recipes set name = %(name)s, description = %(description)s, instructions = %(instructions)s, cook_time = %(cook_time)s where id = %(recipe_id)s;" ) recipe = mysql.query_db(query, data) return recipe
def add_user(cls, data): mysql = MySQLConnection('wall_schema') query = ( "insert into users (email_address, pass_hash, first_name, last_name, spam_ok) values (%(email)s, %(password)s, %(first_name)s, %(last_name)s, %(spam_ok)s)" ) new_email = mysql.query_db(query, data) return new_email
def login_validate(data): is_valid = True mysql = MySQLConnection('wall_schema') query = ("select * from users where email_address = %(email_address)s") user_check = mysql.query_db(query, data) if len(user_check) != 1: is_valid = False flash('Username or Password is invalid') return is_valid
def view_recipe(cls, data): mysql = MySQLConnection('recipe_schema').query_db( 'select * from recipes where recipes.id = %(id)s', data) print(mysql) recipe = Recipe(mysql[0]) return recipe
def get_all(cls, data): mysql = MySQLConnection('recipe_schema').query_db( 'select * from recipes where recipes.user_id = %(user_id)s', data) recipes = [] for item in mysql: new = Recipe(item) recipes.append(new) return recipes
def delete(cls, data): mysql = MySQLConnection('email_schema') query = ("delete from emails where id = %(id)s") mysql.query_db(query, data) return None
def get_all(cls): mysql = MySQLConnection('email_schema') query = ('select * from emails') all_emails = mysql.query_db(query) return all_emails
def add_email(cls, data): mysql = MySQLConnection('email_schema') query = ("insert into emails (email_address) values (%(email)s)") new_email = mysql.query_db(query, data) return new_email
def delete(cls, data): MySQLConnection('recipe_schema').query_db( 'delete from recipes where recipes.id = %(id)s', data)
def get_user(cls, data): mysql = MySQLConnection('wall_schema') query = ("select * from users where email_address = %(email_address)s") user = mysql.query_db(query, data) return user