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