-
-
Notifications
You must be signed in to change notification settings - Fork 501
Updates for New Timed Exams Functionality #965
Conversation
controllers/ajax.py
Outdated
| return json.dumps(res) | ||
| elif event == "timedExam": | ||
| query = "select correct, incorrect, skipped, time_taken, timestamp from timed_exam where div_id=%s and course_name=%s and sid=%s order by timestamp desc" | ||
| query = "SELECT correct, incorrect, skipped, time_taken, timestamp, reset FROM timed_exam WHERE div_id=%s AND course_name=%s AND sid=%s ORDER BY timestamp DESC" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a minor thing, but it would definitely be preferable to use the db((db.timed_exam.div_id == divId) style query rather than using executesql. The results are much more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the queries in this block of if/elif statements use the db.executesql() function. Would you like me to change them all to the web2py query style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great.
controllers/ajax.py
Outdated
| rows = db((db.fitb_answers.div_id == div_id) & (db.fitb_answers.course_name == course) & (db.fitb_answers.sid == sid)).select(db.fitb_answers.answer, db.fitb_answers.timestamp, db.fitb_answers.correct, orderby=~db.fitb_answers.timestamp) | ||
| if len(rows) == 0: | ||
| return "" # server doesn't have it so we load from local storage instead | ||
| res = {'answer': rows[0][0], 'timestamp': str(rows[0][1]), 'correct': rows[0][2]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to update the use of rows -- this is the real benefit! So this line can now be:
res = {'answer': rows.answer, 'timestamp': str(rows.timestamp), ...
Otherwise ajax.py will crash on line 889 and others.
bnmnetp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to using the dot notation, you should also use the .first() call at the end of the query when appropriate. Looks like it is in all cases as we are getting rows[0][x]
This just makes everything easier to read and maintain going forward.
|
Referenced Issue: #967 |
No description provided.