Пример #1
0
def create_ratingitem(project):
    with context(project, 'write') as cntx:
        item = request.json
        dbid = cntx.db.insert("""INSERT INTO ratingitem (id, name, description, category, creation_author, creation_time, project_id) 
                                 VALUES (NULL, %s, %s, %s, %s, NOW(), %s)""",
                              [escape(item['name']), escape(item['description']), escape(item['category']), cntx.userid, cntx.pid])
        return redirect("/api/" +project+ "/ratingitem/" + str(dbid), 201);
Пример #2
0
def create_ratingitem(project):
    with context(project, 'write') as cntx:
        item = request.json
        dbid = cntx.db.insert("""INSERT INTO ratingitem (id, name, description, category, creation_author, creation_time, project_id) 
                                 VALUES (NULL, %s, %s, %s, %s, NOW(), %s)""",
                              [escape(item['name']), escape(item['description']), escape(item['category']), cntx.userid, cntx.pid])
        return redirect("/api/" +project+ "/ratingitem/" + str(dbid), 201);
Пример #3
0
def update_ratingitem(project, no):
    with context(project, 'write') as cntx:
        item = request.json            
        dbid = cntx.db.execute("""UPDATE ratingitem SET 
                                  name=%s, description=%s, category=%s, creation_author=%s, creation_time="""+cntx.db.time_now()+"""
                                  WHERE id = %s AND project_id = %s""",
                               [escape(item['name']), escape(item['description']), escape(item['category']), cntx.userid, no, cntx.pid])
        return '{"status": "ok"}'
Пример #4
0
def update_ratingitem(project, no):
    with context(project, 'write') as cntx:
        item = request.json            
        dbid = cntx.db.execute("""UPDATE ratingitem SET 
                                  name=%s, description=%s, category=%s, creation_author=%s, creation_time="""+cntx.db.time_now()+"""
                                  WHERE id = %s AND project_id = %s""",
                               [escape(item['name']), escape(item['description']), escape(item['category']), cntx.userid, no, cntx.pid])
        return '{"status": "ok"}'
Пример #5
0
def insert_note(db, wo_id: int):
    cursor = db.cursor()
    os.system('clear')
    goal = h.escape(input('Goal of the workout:\n'))
    print()
    refl = h.escape(input('Reflections/Thoughts:\n'))
    cursor.execute("INSERT INTO ExerciseNote (WorkoutID, Goal, Reflection)" +
                   "VALUES ({}, '{}', '{}');".format(wo_id, goal, refl))
    db.commit()
Пример #6
0
def create_advice(project):
    with context(project, 'write') as cntx:
        advice = request.json
            
        dbid = cntx.db.execute("""DELETE FROM advice WHERE user_id = %s and ratingitem_id = %s AND project_id = %s""",
                               [cntx.userid, advice['ratingitem_id'], cntx.pid]);

        dbid = cntx.db.execute("""INSERT INTO advice (user_id, ratingitem_id, advice, creation_time, project_id)
                               VALUES (%s, %s, %s, NOW(), %s)""",
                               [cntx.userid, escape(str(advice['ratingitem_id'])), escape(advice['advice']), cntx.pid]);
        return redirect("/api/"+project+"/advice/" + str(cntx.userid) + "/"+ str(advice['ratingitem_id']), 201);
Пример #7
0
def create_advice(project):
    with context(project, 'write') as cntx:
        advice = request.json
            
        dbid = cntx.db.execute("""DELETE FROM advice WHERE user_id = %s and ratingitem_id = %s AND project_id = %s""",
                               [cntx.userid, advice['ratingitem_id'], cntx.pid]);

        dbid = cntx.db.execute("""INSERT INTO advice (user_id, ratingitem_id, advice, creation_time, project_id)
                               VALUES (%s, %s, %s, NOW(), %s)""",
                               [cntx.userid, escape(str(advice['ratingitem_id'])), escape(advice['advice']), cntx.pid]);
        return redirect("/api/"+project+"/advice/" + str(cntx.userid) + "/"+ str(advice['ratingitem_id']), 201);
Пример #8
0
def insert_exercise_in_group(db):
    cursor = db.cursor()
    cursor.execute("SELECT * FROM ExerciseGroup;")
    rows = cursor.fetchall()
    sel_group_id = 0
    groups = {}
    os.system('clear')
    if (len(rows) > 0):
        print('Groups:')
        for (group_id, group_name) in rows:
            groups[group_name] = group_id
            print('ID: {}, Name: {}'.format(group_id, group_name))

        sel_group_id = h.int_parse(
            input('Select an ID, or 0 to create a new group: '), 0)

    if (sel_group_id == 0):
        group_name = h.escape(input('Name of the group: '))
        if (group_name in groups.keys()):
            print('The group {} already exists, '.format(group_name) +
                  'your exercise will be added to the existing group')
            sel_group_id = groups[group_name]
        else:
            cursor = db.cursor()
            cursor.execute("INSERT INTO ExerciseGroup (GroupName) " +
                           "VALUES ('{}')".format(group_name))
            sel_group_id = cursor.lastrowid
            db.commit()

    cursor = db.cursor()
    cursor.execute("SELECT * FROM Exercise " + "WHERE ExerciseID " +
                   "NOT IN (SELECT ExerciseID " + "FROM ExerciseInGroup " +
                   "WHERE GroupID = {})".format(sel_group_id))
    rows = cursor.fetchall()

    # Keep track off all the exercices listed
    exs = {}
    print("Exercises:")
    for (ex_id, ex_name) in rows:
        exs[ex_id] = ex_name
        print("ID {}: {}".format(ex_id, ex_name))

    ex_id = h.int_parse(
        input("Which exercise would you " +
              "like add to the group {} ?: ".format(group_name)), 0)

    # Add the exercise to the group if a valid ex_id is chosen
    if (ex_id in exs.keys()):
        cursor.execute("INSERT INTO ExerciseInGroup (GroupID, ExerciseID) " +
                       "VALUES ({}, {})".format(sel_group_id, ex_id))
        print('Inserted exercise {} into the group {}'.format(
            exs[ex_id], group_name))

    db.commit()
Пример #9
0
def insert_exercise_free(db, ex_id: int):
    desc = h.escape(input('Description: '))
    cursor = db.cursor()
    cursor.execute("INSERT INTO ExerciseFree(ExerciseID, Description) " +
                   "VALUES ({},'{}');".format(ex_id, desc))
    db.commit()