|
13 | 13 | import requests |
14 | 14 | import urllib |
15 | 15 |
|
16 | | -from collections import defaultdict, OrderedDict |
| 16 | +from collections import defaultdict, OrderedDict, Counter |
17 | 17 | from markupsafe import escape |
18 | 18 | from requests.status_codes import codes |
19 | 19 | from StringIO import StringIO |
@@ -244,19 +244,30 @@ def domatch(student): |
244 | 244 | if not aname: |
245 | 245 | msg += "<font color='red'>{text}</font>".format(text=_("Please enter an assignment name")) |
246 | 246 | else: |
247 | | - allgrades = get_student_grade_summary_data(request, course, get_grades=True, use_offline=use_offline) |
| 247 | + allgrades = get_student_grade_summary_data( |
| 248 | + request, |
| 249 | + course, |
| 250 | + get_grades=True, |
| 251 | + use_offline=use_offline, |
| 252 | + get_score_max=True |
| 253 | + ) |
248 | 254 | if aname not in allgrades['assignments']: |
249 | 255 | msg += "<font color='red'>{text}</font>".format( |
250 | 256 | text=_("Invalid assignment name '{name}'").format(name=aname) |
251 | 257 | ) |
252 | 258 | else: |
253 | 259 | aidx = allgrades['assignments'].index(aname) |
254 | | - datatable = {'header': [_('External email'), aname]} |
| 260 | + datatable = {'header': [_('External email'), aname, _('max_pts')]} |
255 | 261 | ddata = [] |
256 | | - for student in allgrades['students']: # do one by one in case there is a student who has only partial grades |
257 | | - try: |
258 | | - ddata.append([student.email, student.grades[aidx]]) |
259 | | - except IndexError: |
| 262 | + # do one by one in case there is a student who has only partial grades |
| 263 | + for student in allgrades['students']: |
| 264 | + if len(student.grades) >= aidx and student.grades[aidx] is not None: |
| 265 | + ddata.append( |
| 266 | + [student.email, |
| 267 | + student.grades[aidx][0], |
| 268 | + student.grades[aidx][1]] |
| 269 | + ) |
| 270 | + else: |
260 | 271 | log.debug(u'No grade for assignment %(idx)s (%(name)s) for student %(email)s', { |
261 | 272 | "idx": aidx, |
262 | 273 | "name": aname, |
@@ -736,8 +747,16 @@ def get_student_grade_summary_data( |
736 | 747 | else: |
737 | 748 | add_grade(score.section, score.earned) |
738 | 749 | else: |
| 750 | + category_cnts = Counter() |
739 | 751 | for grade_item in gradeset['section_breakdown']: |
740 | | - add_grade(grade_item['label'], grade_item['percent']) |
| 752 | + category = grade_item['category'] |
| 753 | + try: |
| 754 | + earned = gradeset['totaled_scores'][category][category_cnts[category]].earned |
| 755 | + possible = gradeset['totaled_scores'][category][category_cnts[category]].possible |
| 756 | + add_grade(grade_item['label'], earned, possible=possible) |
| 757 | + except (IndexError, KeyError): |
| 758 | + add_grade(grade_item['label'], grade_item['percent']) |
| 759 | + category_cnts[category] += 1 |
741 | 760 | student.grades = gtab.get_grade(student.id) |
742 | 761 |
|
743 | 762 | data.append(datarow) |
|
0 commit comments