def getRequests(userId): cursor = tasks.getDBCursor() cursor.execute( "SELECT userlevel FROM pms.Freebie_Users where username = %(username)s", {"username": userId}) user = cursor.fetchone() level = user[0] if level == 0: cursor.execute( """select * from pms.Freebie_Requests a left join pms.Freebie_Agents b on a.agent_name = b.agent where b.team_lead = %(username)s""", {"username": userId}) if level == 1: cursor.execute( """select * from pms.Freebie_Requests a left join pms.Freebie_Agents b on a.agent_name = b.agent where b.team_lead = %(username)s""", {"username": userId}) if level == 2: cursor.execute( """select * from pms.Freebie_Requests a left join pms.Freebie_Agents b on a.agent_name = b.agent where b.manager = %(username)s""", {"username": userId}) if level == 3: cursor.execute("select * from pms.Freebie_Requests a") result = cursor.fetchall() cursor.close() json_result = methods.convertToJSON(result) json_result = methods.getActions(level, json_result) return json_result
def getAgents(): cursor = tasks.getDBCursor() cursor.execute("SELECT agent FROM pms.Freebie_Agents") agents = cursor.fetchall() cursor.close() agent_list = [i[0] for i in agents] return agent_list
def updateRequest(requestId, status, comment, user): cursor = tasks.getDBCursor() cursor.execute( "UPDATE pms.Freebie_Requests SET status = %(status)s, comment = %(comment)s, updated_by = %(updated_by)s WHERE id = %(id)s", { "status": status, "comment": comment, "updated_by": user, "id": requestId }) cursor.close()
def authenticate(user, password): cursor = tasks.getDBCursor() cursor.execute( "SELECT * FROM pms.Freebie_Users WHERE username = %(username)s OR email = %(username)s", {"username": user}) result = cursor.fetchone() cursor.close() if result: if result[1] == password: return True return False
def verify(user, token): cursor = tasks.getDBCursor() cursor.execute( "SELECT * FROM pms.Freebie_Sessions where username = %(username)s", {"username": user}) result = cursor.fetchone() cursor.close() if result: if result[0] == token: return True return False
def addRequest(requestData): cursor = tasks.getDBCursor() timestamp = str(datetime.now()) requestParam = {} for key in requestData: requestParam[key] = requestData[key] requestParam["created_at"] = str(datetime.now()) if float(requestData["discount_percent"]) <= 10: query = """INSERT INTO pms.Freebie_Requests (created_at,agent_name,category,user_id,account_phone,sales_date,activation_date, sales_amount,prev_sales,discount_amount,discount_percent,alternate_number,discussion_details,status, updated_by) VALUES (%(created_at)s,%(agent_name)s,%(category)s,%(user_id)s,%(account_phone)s,%(sales_date)s,%(activation_date)s, %(sales_amount)s,%(prev_sales)s,%(discount_amount)s,%(discount_percent)s,%(alternate_number)s, %(discussion_details)s,'Approved','AutoApproval')""" else: query = """INSERT INTO pms.Freebie_Requests (created_at,agent_name,category,user_id,account_phone,sales_date,activation_date, sales_amount,prev_sales,discount_amount,discount_percent,alternate_number,discussion_details,status) VALUES (%(created_at)s,%(agent_name)s,%(category)s,%(user_id)s,%(account_phone)s,%(sales_date)s,%(activation_date)s, %(sales_amount)s,%(prev_sales)s,%(discount_amount)s,%(discount_percent)s,%(alternate_number)s,%(discussion_details)s, %(status)s)""" cursor.execute(query, requestParam) cursor.close()