Skip to content

Commit

Permalink
Add a flag for vitamins answered
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyhsyu committed Feb 3, 2019
1 parent adc0478 commit 9d6ec3c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
21 changes: 15 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,26 +813,35 @@ def edit_resource(course_ok_id, lecture_url_name, video_index, resource_index, o
return jsonify(success=False, message="Only instructors can create vitamins"), 403
return jsonify(success=False, message="Can only create a vitamin on Hermes for an OK course you are a part of"), 403

@app.route('/course/<course_ok_id>/lecture/<lecture_url_name>/video/<int:video_index>/edit')
@app.route('/course/<course_ok_id>/lecture/<lecture_url_name>/video/<int:video_index>/edit', methods=["GET"])
@validate_and_pass_on_ok_id
def edit_video(course_ok_id, lecture_url_name, video_index, ok_id=None):
"""Gets all vitamins on a video"""
user_courses = get_updated_user_courses()
int_course_ok_id = int(course_ok_id)
for course in user_courses:
if course['course_id'] == int_course_ok_id:
user_email = get_user_data()["email"]
rows = sql_client.get_answered_vitamins(user_email, course_ok_id, lecture_url_name, video_index)
indices = []
for vitamin in rows:
indices.append(vitamin['vitamin_index'])
vitamins = db[Vitamin.collection].find({
'course_ok_id': course_ok_id,
'lecture_url_name': lecture_url_name,
'video_index': video_index
}).sort("seconds", 1)
flagged_vitamins = []
for vitamin in vitamins:
if vitamin['vitamin_index'] in indices:
vitamin["answered"] = True
else:
vitamin["answered"] = False
# Iterating through vitamins destroys the vitamin object
flagged_vitamins.append(vitamin)

return bson_dump({
"vitamins": db[Vitamin.collection].find({
'course_ok_id': course_ok_id,
'lecture_url_name': lecture_url_name,
'video_index': video_index
}).sort("seconds", 1),
"vitamins": flagged_vitamins,
"resources": db[Resource.collection].find({
'course_ok_id': course_ok_id,
'lecture_url_name': lecture_url_name,
Expand Down
5 changes: 4 additions & 1 deletion utils/schemas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ PREPARE answer_vitamin as
INSERT INTO vitamin_answers VALUES ($1, $2, localtimestamp, $3, $4, $5, $6);

PREPARE watch_video as
INSERT INTO videos_watched VALUES ($1, $2, localtimestamp, $3, $4)
INSERT INTO videos_watched VALUES ($1, $2, localtimestamp, $3, $4);

PREPARE get_answered_vitamins AS
SELECT * FROM vitamin_answers WHERE user_email = ($1) AND course_ok_id = ($2) AND lecture_url_name = ($3) AND video_index = ($4);
11 changes: 11 additions & 0 deletions utils/sql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ def get_lecture_attendence(self, user_email, course_ok_id, lecture_url_name):
cur.execute(
'EXECUTE lecture_attendence(%s, %s,%s,%s)'
)

def get_answered_vitamins(self, user_email, course_ok_id, lecture_url_name, video_index):
cur = self.conn.cursor(cursor_factory=extras.DictCursor)
cur.execute(
'EXECUTE get_answered_vitamins(%s, %s, %s, %s)',
(user_email, course_ok_id, lecture_url_name, video_index)
)
self.conn.commit()
rows = cur.fetchall()
cur.close()
return rows

0 comments on commit 9d6ec3c

Please sign in to comment.