def get_member(member_id): db = get_db() member_cur = db.execute("""SELECT id, name, email, level from members where id = ?""", (member_id,)) member = member_cur.fetchone() return_value = {'id': member['id'], 'name': member['name'], 'email': member['email'], 'level': member['level']} return jsonify({'member': return_value})
def edit_member(member_id): db = get_db() new_member_data = request.get_json() name = new_member_data['name'] email = new_member_data['email'] level = new_member_data['level'] db.execute("""UPDATE members SET name = ?, email = ?, level = ? where id = ?""", (name, email, level, member_id)) db.commit() member_curs = db.execute("""SELECT id, name, email, level from members where id = ?""", (member_id,)) update_member = member_curs.fetchone() return jsonify( {'member': {'id': update_member['id'], 'name': update_member['name'], 'email': update_member['email'], 'level': update_member['level']}})
def get_members(): db = get_db() members_curs = db.execute("""SELECT id, name, email, level from members""") all_members = members_curs.fetchall() return_values = [] for member in all_members: member_dict = dict() member_dict['id'] = member['id'] member_dict['name'] = member['name'] member_dict['email'] = member['email'] member_dict['level'] = member['level'] return_values.append(member_dict) return jsonify({'members': return_values,})
def add_member(): new_member_data = request.get_json() name = new_member_data['name'] email = new_member_data['email'] level = new_member_data['level'] db = get_db() db.execute("""INSERT INTO members (name, email, level) VALUES (?, ?, ?)""", (name, email, level)) db.commit() member_curs = db.execute("""SELECT id, name, email, level from members WHERE name = ?""", (name,)) new_member = member_curs.fetchone() return jsonify({'member': {'id': new_member['id'], 'name': new_member['name'], 'email': new_member['email'], 'level': new_member['level']}})
def delete_member(member_id): db = get_db() db.execute("""DELETE FROM members WHERE id = ?""", (member_id,)) db.commit() return jsonify({'message': 'the member has been deleted'})
def home(): database_helper.get_db() #render_template('static/client.html') return render_template('client.html')
def main(): db = database_helper.get_db() database_helper.init_db() return app.send_static_file('client.html')
def home(): database_helper.get_db()
def main(): db = database_helper.get_db() database_helper.init_db() #return render_template('static/client.html') return app.send_static_file('client.html')
def home(): database_helper.get_db() return 'This is a front page, looking beautiful'
def delete_all_tokens(): c = dh.get_db() c.execute("delete from tokens") c.commit() return json.dumps({"message": "Tokens deleted"})
def get_all_users(): c = dh.get_db() res = c.execute("select * from users") res = res.fetchall() return json.dumps({"message": "User List", "data": res})
def get_tokens(): c = dh.get_db() res = c.execute("select * from tokens") res = res.fetchall() return json.dumps({"message": "Token List", "data": res})