Skip to content

Commit a5b0e4b

Browse files
authored
Make global evaluation progress feature generic (#2621)
Close #2617
1 parent 83a3442 commit a5b0e4b

File tree

6 files changed

+89
-39
lines changed

6 files changed

+89
-39
lines changed

evap/development/localsettings.template.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,23 @@
4242
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
4343

4444
### Evaluation progress rewards
45-
GLOBAL_EVALUATION_PROGRESS_REWARDS: list[tuple[Fraction, str]] = [
46-
(Fraction("0"), "0€"),
47-
(Fraction("0.25"), "1.000€"),
48-
(Fraction("0.6"), "3.000€"),
49-
(Fraction("0.7"), "7.000€"),
50-
(Fraction("0.9"), "10.000€"),
45+
GLOBAL_EVALUATION_PROGRESS_REWARDS: list[tuple[Fraction, dict[str, str]]] = [
46+
(Fraction("0"), {"de": "0 €", "en": "0€"}),
47+
(Fraction("0.25"), {"de": "1.000 €", "en": "1,000€"}),
48+
(Fraction("0.6"), {"de": "3.000 €", "en": "3,000€"}),
49+
(Fraction("0.7"), {"de": "7.000 €", "en": "7,000€"}),
50+
(Fraction("0.9"), {"de": "10.000 €", "en": "10,000€"}),
5151
]
5252
GLOBAL_EVALUATION_PROGRESS_EXCLUDED_COURSE_TYPE_IDS: list[int] = []
5353
GLOBAL_EVALUATION_PROGRESS_EXCLUDED_EVALUATION_IDS: list[int] = []
54-
GLOBAL_EVALUATION_PROGRESS_INFO_TEXT = {
55-
"de": mark_safe("Deine Teilnahme am Evaluationsprojekt wird helfen. Evaluiere also <b>jetzt</b>!"),
56-
"en": mark_safe("Your participation in the evaluation helps, so evaluate <b>now</b>!"),
54+
GLOBAL_EVALUATION_PROGRESS_CAMPAIGN: dict[str, str] = {
55+
"title_de": "Spendenaktion",
56+
"title_en": "Fundraising",
57+
"info_title_de": "Jede Stimme zählt! Erfahre mehr über unser Spendenziel.",
58+
"info_title_en": "Every vote counts! Read more about our fundraising goal.",
59+
"info_text_de": mark_safe("Deine Teilnahme am Evaluationsprojekt wird helfen. Evaluiere also <b>jetzt</b>!"),
60+
"info_text_en": mark_safe("Your participation in the evaluation helps, so evaluate <b>now</b>!"),
5761
}
62+
5863
# Questionnaires automatically added to exam evaluations
5964
EXAM_QUESTIONNAIRE_IDS = [111]

evap/settings.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,18 @@ class ManifestStaticFilesStorageWithJsReplacement(ManifestStaticFilesStorage):
390390

391391
### Evaluation progress rewards
392392
GLOBAL_EVALUATION_PROGRESS_REWARDS: list[
393-
tuple[Fraction, str]
393+
tuple[Fraction, dict[str, str]]
394394
] = [] # (required_voter_ratio between 0 and 1, reward_text)
395395
GLOBAL_EVALUATION_PROGRESS_EXCLUDED_COURSE_TYPE_IDS: list[int] = []
396396
GLOBAL_EVALUATION_PROGRESS_EXCLUDED_EVALUATION_IDS: list[int] = []
397-
GLOBAL_EVALUATION_PROGRESS_INFO_TEXT: dict[str, str] = {"de": "", "en": ""}
397+
GLOBAL_EVALUATION_PROGRESS_CAMPAIGN: dict[str, str] = {
398+
"title_de": "",
399+
"title_en": "",
400+
"info_title_de": "",
401+
"info_title_en": "",
402+
"info_text_de": "",
403+
"info_text_en": "",
404+
}
398405

399406
### Slogans
400407
SLOGANS_DE = [

evap/student/templates/student_global_reward.html renamed to evap/student/templates/student_global_evaluation_progress.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{% load evaluation_filters %}
22

3-
{% if global_rewards %}
3+
{% if global_evaluation_progress %}
44
<div class="card mb-3">
55
<div class="card-header d-flex">
6-
{% translate "Fundraising" %}
7-
{% if global_rewards.last_vote_datetime %}
6+
{{ global_evaluation_progress.campaign.title }}
7+
{% if global_evaluation_progress.last_vote_datetime %}
88
<div class="ms-auto fw-normal fst-italic">
9-
{% blocktranslate trimmed with time_interval=global_rewards.last_vote_datetime|timesince %}
9+
{% blocktranslate trimmed with time_interval=global_evaluation_progress.last_vote_datetime|timesince %}
1010
Last evaluation: {{ time_interval }} ago
1111
{% endblocktranslate %}
1212
</div>
@@ -16,17 +16,17 @@
1616
<div class="global-rewards-progress-bar pt-2 px-4">
1717
<span class="progress-container">
1818
<span class="progress m-0 bg-info">
19-
<span class="progress-bar bg-primary width-percent-{% widthratio global_rewards.bar_width_votes global_rewards.max_reward_votes 100 %}"></span>
19+
<span class="progress-bar bg-primary width-percent-{% widthratio global_evaluation_progress.bar_width_votes global_evaluation_progress.max_reward_votes 100 %}"></span>
2020
<span class="progress-bartext">
21-
{% blocktranslate trimmed count votes=global_rewards.vote_count with percent=global_rewards.vote_count|percentage_zero_on_error:global_rewards.participation_count %}
21+
{% blocktranslate trimmed count votes=global_evaluation_progress.vote_count with percent=global_evaluation_progress.vote_count|percentage_zero_on_error:global_evaluation_progress.participation_count %}
2222
{{ votes }} submitted evaluation ({{ percent }})
2323
{% plural %}
2424
{{ votes }} submitted evaluations ({{ percent }})
2525
{% endblocktranslate %}
2626
</span>
2727
</span>
2828
</span>
29-
{% for reward in global_rewards.rewards_with_progress %}
29+
{% for reward in global_evaluation_progress.rewards_with_progress %}
3030
<div class="position-relative progress-step left-percent-{% widthratio reward.progress 1 100 %}">
3131
<div class="mx-auto seperator"></div>
3232
<div class="small text-center">
@@ -39,12 +39,12 @@
3939
<div class="card card-outline-light collapsible mt-2">
4040
<div class="card-header d-flex">
4141
<a class="collapse-toggle collapse-toggle-light collapsed" data-bs-toggle="collapse" href="#goal-info-text" aria-controls="goal-info-text">
42-
{% translate "Every vote counts! Read more about our fundraising goal." %}
42+
{{ global_evaluation_progress.campaign.info_title }}
4343
</a>
4444
</div>
4545
<div class="collapse" id="goal-info-text">
4646
<div class="card-body">
47-
{{ global_rewards.info_text }}
47+
{{ global_evaluation_progress.campaign.info_text }}
4848
</div>
4949
</div>
5050
</div>

evap/student/templates/student_index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818
{% endif %}
1919

20-
{% include 'student_global_reward.html' with global_rewards=global_rewards %}
20+
{% include 'student_global_evaluation_progress.html' with global_evaluation_progress=global_evaluation_progress %}
2121

2222
{% if unfinished_evaluations %}
2323
<div class="card card-outline-primary mb-3">

evap/student/tests/test_views.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,22 @@ def test_num_queries_is_constant(self):
5858
self.app.get(self.url, user=self.user)
5959

6060
@override_settings(
61-
GLOBAL_EVALUATION_PROGRESS_REWARDS=[(Fraction(1, 10), "a dog"), (Fraction(5, 10), "a quokka")],
62-
GLOBAL_EVALUATION_PROGRESS_INFO_TEXT={"de": "info_text_str", "en": "info_text_str"},
61+
GLOBAL_EVALUATION_PROGRESS_REWARDS=[
62+
(Fraction(1, 10), {"de": "a dog", "en": "a dog"}),
63+
(Fraction(5, 10), {"de": "a quokka", "en": "a quokka"}),
64+
],
65+
GLOBAL_EVALUATION_PROGRESS_CAMPAIGN={
66+
"title_de": "global_evaluation_progress_title_str",
67+
"title_en": "global_evaluation_progress_title_str",
68+
"info_title_de": "global_evaluation_progress_info_title_str",
69+
"info_title_en": "global_evaluation_progress_info_title_str",
70+
"info_text_de": "global_evaluation_progress_info_text_str",
71+
"info_text_en": "global_evaluation_progress_info_text_str",
72+
},
6373
GLOBAL_EVALUATION_PROGRESS_EXCLUDED_COURSE_TYPE_IDS=[1042],
6474
GLOBAL_EVALUATION_PROGRESS_EXCLUDED_EVALUATION_IDS=[1043],
6575
)
66-
def test_global_reward_progress(self):
76+
def test_global_evaluation_progress(self):
6777
excluded_states = [state for state in Evaluation.State if state < Evaluation.State.APPROVED]
6878
included_states = [state for state in Evaluation.State if state >= Evaluation.State.APPROVED]
6979

@@ -97,17 +107,18 @@ def test_global_reward_progress(self):
97107
expected_voter_percent = 100 * expected_voters // expected_participants
98108

99109
page = self.app.get(self.url, user=self.user)
100-
self.assertIn("Fundraising", page)
101-
self.assertIn("info_text_str", page)
110+
self.assertIn("global_evaluation_progress_title_str", page)
111+
self.assertIn("global_evaluation_progress_info_title_str", page)
112+
self.assertIn("global_evaluation_progress_info_text_str", page)
102113
self.assertIn("Last evaluation:", page)
103114
self.assertIn(f"{expected_voters} submitted evaluations ({expected_voter_percent}%)", page)
104115
self.assertIn("a quokka", page)
105116
self.assertIn("10%", page)
106117
self.assertIn("a dog", page)
107118
self.assertIn("50%", page)
108119

109-
@override_settings(GLOBAL_EVALUATION_PROGRESS_REWARDS=[(Fraction("0.07"), "a dog")])
110-
def test_global_reward_progress_edge_cases(self):
120+
@override_settings(GLOBAL_EVALUATION_PROGRESS_REWARDS=[(Fraction("0.07"), {"de": "a dog", "en": "a dog"})])
121+
def test_global_evaluation_progress_edge_cases(self):
111122
# no active semester
112123
Semester.objects.update(is_active=False)
113124
page = self.app.get(self.url, user=self.user)
@@ -138,12 +149,20 @@ def test_global_reward_progress_edge_cases(self):
138149

139150
@override_settings(
140151
GLOBAL_EVALUATION_PROGRESS_REWARDS=[],
141-
GLOBAL_EVALUATION_PROGRESS_INFO_TEXT={"de": "info_text_str", "en": "info_text_str"},
152+
GLOBAL_EVALUATION_PROGRESS_CAMPAIGN={
153+
"title_de": "global_evaluation_progress_title_str",
154+
"title_en": "global_evaluation_progress_title_str",
155+
"info_title_de": "global_evaluation_progress_info_title_str",
156+
"info_title_en": "global_evaluation_progress_info_title_str",
157+
"info_text_de": "global_evaluation_progress_info_text_str",
158+
"info_text_en": "global_evaluation_progress_info_text_str",
159+
},
142160
)
143-
def test_global_reward_progress_hidden(self):
161+
def test_global_evaluation_progress_hidden(self):
144162
page = self.app.get(self.url, user=self.user)
145-
self.assertNotIn("Fundraising", page)
146-
self.assertNotIn("info_text_str", page)
163+
self.assertNotIn("global_evaluation_progress_title_str", page)
164+
self.assertNotIn("global_evaluation_progress_info_title_str", page)
165+
self.assertNotIn("global_evaluation_progress_info_text_str", page)
147166

148167

149168
@override_settings(INSTITUTION_EMAIL_DOMAINS=["example.com"])

evap/student/views.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
TextAnswer,
2929
VoteTimestamp,
3030
)
31+
from evap.evaluation.tools import translate
3132
from evap.results.tools import (
3233
annotate_distributions_and_grades,
3334
get_evaluations_with_course_result_attributes,
@@ -41,29 +42,45 @@
4142

4243

4344
@dataclass
44-
class GlobalRewards:
45+
class GlobalEvaluationProgress:
4546
@dataclass
4647
class RewardProgress:
4748
progress: Fraction # progress towards this reward, relative to max reward, between 0 and 1
4849
vote_ratio: Fraction
4950
text: str
5051

52+
@dataclass
53+
class Campaign:
54+
title_de: str
55+
title_en: str
56+
title = translate(en="title_en", de="title_de")
57+
58+
info_title_de: str
59+
info_title_en: str
60+
info_title = translate(en="info_title_en", de="info_title_de")
61+
62+
info_text_de: str
63+
info_text_en: str
64+
info_text = translate(en="info_text_en", de="info_text_de")
65+
5166
vote_count: int
5267
participation_count: int
5368
max_reward_votes: int
5469
bar_width_votes: int
5570
last_vote_datetime: datetime.datetime
5671
rewards_with_progress: list[RewardProgress]
57-
info_text: str
72+
campaign: Campaign
5873

5974
@staticmethod
60-
def from_settings() -> "GlobalRewards | None":
75+
def from_settings() -> "GlobalEvaluationProgress | None":
6176
if not settings.GLOBAL_EVALUATION_PROGRESS_REWARDS:
6277
return None
6378

6479
if not Semester.active_semester():
6580
return None
6681

82+
language = get_language()
83+
6784
evaluations = (
6885
Semester.active_semester()
6986
.evaluations.exclude(state__lt=Evaluation.State.APPROVED)
@@ -83,22 +100,24 @@ def from_settings() -> "GlobalRewards | None":
83100
max_reward_votes = math.ceil(max_reward_vote_ratio * participation_count)
84101

85102
rewards_with_progress = [
86-
GlobalRewards.RewardProgress(progress=vote_ratio / max_reward_vote_ratio, vote_ratio=vote_ratio, text=text)
103+
GlobalEvaluationProgress.RewardProgress(
104+
progress=vote_ratio / max_reward_vote_ratio, vote_ratio=vote_ratio, text=text[language]
105+
)
87106
for vote_ratio, text in settings.GLOBAL_EVALUATION_PROGRESS_REWARDS
88107
]
89108

90109
last_vote_datetime = VoteTimestamp.objects.filter(evaluation__in=evaluations).aggregate(Max("timestamp"))[
91110
"timestamp__max"
92111
]
93112

94-
return GlobalRewards(
113+
return GlobalEvaluationProgress(
95114
vote_count=vote_count,
96115
participation_count=participation_count,
97116
max_reward_votes=max_reward_votes,
98117
bar_width_votes=min(vote_count, max_reward_votes),
99118
last_vote_datetime=last_vote_datetime,
100119
rewards_with_progress=rewards_with_progress,
101-
info_text=settings.GLOBAL_EVALUATION_PROGRESS_INFO_TEXT[get_language()],
120+
campaign=GlobalEvaluationProgress.Campaign(**settings.GLOBAL_EVALUATION_PROGRESS_CAMPAIGN),
102121
)
103122

104123

@@ -189,7 +208,7 @@ def sorter(evaluation):
189208
"can_download_grades": request.user.can_download_grades,
190209
"unfinished_evaluations": unfinished_evaluations,
191210
"evaluation_end_warning_period": settings.EVALUATION_END_WARNING_PERIOD,
192-
"global_rewards": GlobalRewards.from_settings(),
211+
"global_evaluation_progress": GlobalEvaluationProgress.from_settings(),
193212
}
194213

195214
return render(request, "student_index.html", template_data)

0 commit comments

Comments
 (0)