be3a905d4d5efd2b9c3b1fe42e8cbe779b624a7e
[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     toret = str(final_mark) if isinstance(final_mark, int) else '-'
19     examiners = submissionSet.examiners_by_exercise.get(exercise_id, [])
20     marks_by_examiner = submission.get_exercise_marks_by_examiner(exercise_id)
21     for examiner in examiners:
22         mark = marks_by_examiner.get(str(examiner.id), None)
23         toret += ','
24         if mark is None:
25             toret += '-'
26         else:
27             toret += str(mark)
28     return toret