Skip to content

Commit 80153ab

Browse files
murhum1ihalaij1
authored andcommitted
Improve clarity of deadlines extension badges
In both "Your points" page and table of contents: - Show extension details in badge if all exercises in module have the same updated DL - Otherwise, show a generic message and hide details in a tooltip Fixes #1494
1 parent ec185a1 commit 80153ab

3 files changed

Lines changed: 66 additions & 6 deletions

File tree

course/templatetags/course.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,33 @@ def deadline_extended_exercises_open(entry):
8787
)
8888

8989

90+
# List exercises in a module by deadline extension, to display in tooltip details
91+
@register.filter
92+
def deadline_extended_exercises_by_deadline(entry):
93+
deadlines_map = {}
94+
for e in entry.flatted:
95+
if isinstance(e, ExercisePoints) and e.personal_deadline is not None:
96+
if e.personal_deadline not in deadlines_map:
97+
deadlines_map[e.personal_deadline] = []
98+
deadlines_map[e.personal_deadline].append(e)
99+
return list(deadlines_map.items())
100+
101+
102+
# Get the personal deadline if all exercises in a module have the same personal deadline
103+
@register.filter
104+
def deadline_extended_exercises_same_deadline(entry):
105+
deadlines = [
106+
e.personal_deadline
107+
for e in entry.flatted
108+
if isinstance(e, ExercisePoints)
109+
]
110+
if not deadlines:
111+
return None
112+
if len(set(deadlines)) == 1:
113+
return deadlines[0]
114+
return None
115+
116+
90117
@register.filter
91118
def exercises_submittable(entry, now):
92119
if entry.late_allowed:

exercise/templates/exercise/_user_results.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,26 @@
5959
</span>
6060
{% endif %}
6161
{% if module|deadline_extended_exercises_open %}
62-
<span class="badge text-primary bg-white float-end text-wrap">
63-
{% translate "ASSIGNMENTS_WITH_PERSONAL_DEADLINE_DEVIATION" %}
64-
</span>
62+
<!-- If all exercises of a module have the same deadline, display it directly.
63+
Otherwise display a generic message that has a tooltip with details -->
64+
{% if module|deadline_extended_exercises_same_deadline %}
65+
<span class="badge text-primary bg-white float-end text-wrap">
66+
{% translate "PERSONAL_EXTENDED_DEADLINE" %} {{ module|deadline_extended_exercises_same_deadline }}
67+
</span>
68+
{% else %}
69+
<span class="badge text-primary bg-white float-end text-wrap" data-bs-toggle="tooltip" data-bs-html="true" title="
70+
{% for deadline, exercises in module|deadline_extended_exercises_by_deadline %}
71+
{{ deadline }}:<br/>
72+
{% for exercise in exercises %}
73+
{{ exercise.name|parse_localization }}{% if not forloop.last %}<br/>{% endif %}
74+
{% endfor %}
75+
{% if not forloop.last %}<hr/>{% endif %}
76+
{% endfor %}"
77+
>
78+
{% translate "ASSIGNMENTS_WITH_PERSONAL_DEADLINE_DEVIATION" %}
79+
</span>
80+
{% endif %}
81+
6582
{% endif %}
6683
{% if not accessible %}
6784
<span class="badge text-primary bg-white float-end text-wrap">

exercise/templates/exercise/_user_toc.html

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,25 @@
1212
<h3>
1313
<a href="{{ module.link }}" class="{% if module.is_in_maintenance %}maintenance{% endif %}">{{ module.name|parse_localization }}</a>
1414
{% if module|deadline_extended_exercises_open %}
15-
<span class="badge text-bg-secondary">
16-
{% translate "ASSIGNMENTS_WITH_PERSONAL_DEADLINE_DEVIATION" %}
17-
</span>
15+
<!-- If all exercises of a module have the same deadline, display it directly.
16+
Otherwise display a generic message that has a tooltip with details -->
17+
{% if module|deadline_extended_exercises_same_deadline %}
18+
<span class="badge text-bg-secondary">
19+
{% translate "PERSONAL_EXTENDED_DEADLINE" %} {{ module|deadline_extended_exercises_same_deadline }}
20+
</span>
21+
{% else %}
22+
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" data-bs-html="true" title="
23+
{% for deadline, exercises in module|deadline_extended_exercises_by_deadline %}
24+
{{ deadline }}:<br/>
25+
{% for exercise in exercises %}
26+
{{ exercise.name|parse_localization }}{% if not forloop.last %}<br/>{% endif %}
27+
{% endfor %}
28+
{% if not forloop.last %}<hr/>{% endif %}
29+
{% endfor %}
30+
">
31+
{% translate "ASSIGNMENTS_WITH_PERSONAL_DEADLINE_DEVIATION" %}
32+
</span>
33+
{% endif %}
1834
{% endif %}
1935
</h3>
2036
<h4>

0 commit comments

Comments
 (0)