Passed
Push — master ( b8e570...5310e7 )
by Peter
01:38
created

replace_macros()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
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='replace_macros')
17
@stringfilter
18
def replace_macros(value, user_dict):
19
    return value.replace("#FIRSTNAME#", user_dict['first_name'].strip()) \
20
                .replace("#LASTNAME#", user_dict['last_name'].strip())
21
22
23
@register.filter(name='state_label_css')
24
def state_label_css(subm):
25
    green_label = "badge label label-success"
26
    red_label = "badge label label-important"
27
    grey_label = "badge label label-info"
28
    # We expect a submission as input
29
    if subm.is_closed() and subm.grading:
30
        if subm.grading.means_passed:
31
            return green_label
32
        else:
33
            return red_label
34
    if subm.state in [subm.SUBMITTED_TESTED,
35
                      subm.SUBMITTED,
36
                      subm.TEST_FULL_PENDING,
37
                      subm.GRADED,
38
                      subm.TEST_FULL_FAILED]:
39
        return green_label
40
    if subm.state == subm.TEST_VALIDITY_FAILED:
41
        return red_label
42
    return grey_label
43
44
45
@register.assignment_tag
46
def setting(name):
47
    return getattr(settings, name, "")
48
49
50
@register.inclusion_tag('inclusion_tags/details_table.html')
51
def details_table(submission):
52
    return {'submission': submission}
53
54
55
@register.inclusion_tag('inclusion_tags/deadline.html')
56
def deadline_timeout(assignment):
57
    return {'assignment': assignment, 'show_timeout': True}
58
59
60
@register.inclusion_tag('inclusion_tags/deadline.html')
61
def deadline(assignment):
62
    return {'assignment': assignment, 'show_timeout': False}
63
64
65
@register.inclusion_tag('inclusion_tags/grading.html')
66
def grading(submission):
67
    return {'submission': submission}
68
69
70