Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Conversation

@conzty01
Copy link
Contributor

No description provided.

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"
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great.

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]}
Copy link
Member

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.

Copy link
Member

@bnmnetp bnmnetp left a 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.

@conzty01
Copy link
Contributor Author

Referenced Issue: #967

@bnmnetp bnmnetp merged commit 43b3c80 into RunestoneInteractive:master Jul 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants