590767cd6eaa28da572ead789037b76249b6b7ac
[edumed.git] / wtem / templatetags / wtem_csv.py
1 from django import template
2
3 register = template.Library()
4
5
6 @register.simple_tag
7 def csv_header(exercise_id, submissionSet):
8     examiners = submissionSet.examiners_by_exercise.get(exercise_id, [])
9     examiners_string = ','.join(['zad %s - %s' % (exercise_id, user.username) for user in examiners])
10     toret = ',zad %s' % exercise_id
11     if examiners_string:
12         toret += ',' + examiners_string
13     return toret
14
15 @register.simple_tag
16 def csv_row_fragment(exercise_id, submission, submissionSet):
17     final_mark = submission.get_final_exercise_mark(exercise_id)
18     if final_mark is not None:
19         final_mark = ('%.2f' % final_mark).rstrip('0').rstrip('.')
20     toret = final_mark if final_mark else '-'
21     examiners = submissionSet.examiners_by_exercise.get(exercise_id, [])
22     marks_by_examiner = submission.get_exercise_marks_by_examiner(exercise_id)
23     for examiner in examiners:
24         mark = marks_by_examiner.get(str(examiner.id), None)
25         toret += ','
26         if mark is None:
27             toret += '-'
28         else:
29             toret += str(mark)
30     return toret