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

Commit fd8ef55

Browse files
committed
Update point totals for assignment before display
1 parent e19d1a7 commit fd8ef55

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

controllers/dashboard.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ def grades():
237237
assignments = db(db.assignments.course == course.id).select(db.assignments.ALL,
238238
orderby=(db.assignments.duedate, db.assignments.id))
239239

240+
# recalculate total points for each assignment in case the stored
241+
# total is out of sync.
242+
for assign in assignments:
243+
assign.points = update_total_points(assign.id)
244+
240245
students = db(
241246
(db.user_courses.course_id == auth.user.course_id) &
242247
(db.auth_user.id == db.user_courses.user_id)
@@ -337,6 +342,11 @@ def questiongrades():
337342
redirect(URL('dashboard','index'))
338343

339344
course = db(db.courses.id == auth.user.course_id).select().first()
345+
346+
# make sure points total is up to date
347+
assignment_id = request.vars.assignment_id
348+
update_total_points(assignment_id)
349+
340350
assignment = db((db.assignments.id == request.vars.assignment_id) & (db.assignments.course == course.id)).select().first()
341351
sid = request.vars.sid
342352
student = db(db.auth_user.username == sid).select(db.auth_user.first_name, db.auth_user.last_name)
@@ -353,6 +363,14 @@ def questiongrades():
353363

354364
return dict(assignment=assignment, student=student, rows=rows, total=0, course=course)
355365

366+
def update_total_points(assignment_id):
367+
sum_op = db.assignment_questions.points.sum()
368+
total = db(db.assignment_questions.assignment_id == assignment_id).select(sum_op).first()[sum_op]
369+
db(db.assignments.id == assignment_id).update(
370+
points=total
371+
)
372+
return total
373+
356374
# Note this is meant to be called from a form submission not as a bare endpoint
357375
@auth.requires_login()
358376
def exercisemetrics():

0 commit comments

Comments
 (0)