|
1
|
|
|
from django import template |
|
2
|
|
|
from django.conf import settings |
|
3
|
|
|
from django.template.defaultfilters import stringfilter |
|
4
|
|
|
import os |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
register = template.Library() |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
@register.filter(name='basename') |
|
11
|
|
|
@stringfilter |
|
12
|
|
|
def basename(value): |
|
13
|
|
|
return os.path.basename(value) |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
@register.filter(name='state_label_css') |
|
17
|
|
|
def state_label_css(subm): |
|
18
|
|
|
green_label = "badge label label-success" |
|
19
|
|
|
red_label = "badge label label-important" |
|
20
|
|
|
grey_label = "badge label label-info" |
|
21
|
|
|
# We expect a submission as input |
|
22
|
|
|
if subm.is_closed() and subm.grading: |
|
23
|
|
|
if subm.grading.means_passed: |
|
24
|
|
|
return green_label |
|
25
|
|
|
else: |
|
26
|
|
|
return red_label |
|
27
|
|
|
if subm.state in [subm.SUBMITTED_TESTED, |
|
28
|
|
|
subm.SUBMITTED, |
|
29
|
|
|
subm.TEST_FULL_PENDING, |
|
30
|
|
|
subm.GRADED, |
|
31
|
|
|
subm.TEST_FULL_FAILED]: |
|
32
|
|
|
return green_label |
|
33
|
|
|
if subm.state == subm.TEST_VALIDITY_FAILED: |
|
34
|
|
|
return red_label |
|
35
|
|
|
return grey_label |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
@register.assignment_tag |
|
39
|
|
|
def setting(name): |
|
40
|
|
|
return getattr(settings, name, "") |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
@register.inclusion_tag('inclusion_tags/details_table.html') |
|
44
|
|
|
def details_table(submission): |
|
45
|
|
|
return {'submission': submission} |
|
46
|
|
|
|
|
47
|
|
|
@register.inclusion_tag('inclusion_tags/deadline.html') |
|
48
|
|
|
def deadline_timeout(assignment): |
|
49
|
|
|
return {'assignment': assignment, 'show_timeout': True} |
|
50
|
|
|
|
|
51
|
|
|
@register.inclusion_tag('inclusion_tags/deadline.html') |
|
52
|
|
|
def deadline(assignment): |
|
53
|
|
|
return {'assignment': assignment, 'show_timeout': False} |
|
54
|
|
|
|
|
55
|
|
|
@register.inclusion_tag('inclusion_tags/grading.html') |
|
56
|
|
|
def grading(submission): |
|
57
|
|
|
return {'submission': submission} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|