Skip to content

Commit e820641

Browse files
committed
feat: add always_allow_students to Group model and update UI in sport comples view
1 parent 26d9ff9 commit e820641

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

adminpage/sport/admin/groupAdmin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class GroupAdmin(DefaultFilterMixIn):
9393
'trainers',
9494
'allowed_students',
9595
'banned_students',
96+
'always_allow_students',
9697
)
9798

9899
list_filter = (
@@ -131,6 +132,7 @@ class GroupAdmin(DefaultFilterMixIn):
131132
"allowed_education_level",
132133
"allowed_medical_groups",
133134
"allowed_gender",
135+
"always_allow_students",
134136
"allowed_students",
135137
"banned_students",
136138
)

adminpage/sport/models/group.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Group(models.Model):
1414
trainer = models.ForeignKey('Trainer', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='teacher')
1515
trainers = models.ManyToManyField('Trainer', related_name='m2m', blank=True, verbose_name='teachers')
1616
accredited = models.BooleanField(default=True, null=False)
17-
1817
# minimum_medical_group = models.ForeignKey('MedicalGroup', on_delete=models.DO_NOTHING, null=True, blank=True)
1918
allowed_education_level = models.IntegerField(
2019
choices=EducationLevelChoice.choices,
@@ -48,6 +47,12 @@ class Group(models.Model):
4847
blank=True,
4948
help_text='List of students that can not attend classes. The students will not see the training, and the teacher will not be able to set hours for these students.'
5049
)
50+
always_allow_students = models.ManyToManyField(
51+
'Student',
52+
related_name='always_allow_groups',
53+
blank=True,
54+
help_text='List of students that are always allowed to attend classes.'
55+
)
5156

5257
class Meta:
5358
db_table = "group"

adminpage/sport/templates/sport_complex.html

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,29 @@ <h2>{{ training.formatted_timerange }}:</h2>
3434
<span>({{ training.location }})</span>
3535
</div>
3636
<div class="checkins">
37-
{% for formatted_trainer in training.trainers %}
38-
<p>Тренер: {{ formatted_trainer }}</p>
39-
{% endfor %}
37+
{% if training.trainers|length == 1 %}
38+
<p><strong>Тренер:</strong> <span style="color: #2e7d32;">✔ {{ training.trainers.0 }}</span></p>
39+
{% elif training.trainers|length > 1 %}
40+
<p><strong>Тренеры:</strong></p>
41+
{% for formatted_trainer in training.trainers %}
42+
<p style="color: #2e7d32; margin-left: 10px;">✔ {{ formatted_trainer }}</p>
43+
{% endfor %}
44+
{% endif %}
45+
46+
<hr>
47+
48+
{% if training.always_allow %}
49+
<p><strong>Всегда пропускать (основная команда):</strong></p>
50+
{% for person in training.always_allow %}
51+
<p style="color: #2e7d32;">✔ {{ person }}</p>
52+
{% endfor %}
53+
{% endif %}
54+
55+
<p><strong>Отметились на занятие:</strong></p>
4056
{% for formatted_student in training.checkins %}
41-
<p>{{ formatted_student }}</p>
57+
<p style="color: #2e7d32;">✔ {{ formatted_student }}</p>
58+
{% empty %}
59+
<p style="color: #999; font-style: italic;">Пока никто не отметился</p>
4260
{% endfor %}
4361
</div>
4462
</div>

adminpage/sport/views/sport_complex.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ def sport_complex_view(request, **kwargs):
2020
end__gte=now, # And not finished yet
2121
)
2222
.order_by("start")
23-
.select_related("group", "group__sport", "training_class")
24-
.prefetch_related("group__trainers__user", "checkins__student__user")
23+
.select_related(
24+
"group",
25+
"group__sport",
26+
"training_class",
27+
)
28+
.prefetch_related(
29+
"group__trainers__user",
30+
"checkins__student__user",
31+
"group__always_allow_students__user",
32+
)
2533
)
2634

2735
today_schedule_with_checkins = [
@@ -33,6 +41,10 @@ def sport_complex_view(request, **kwargs):
3341
"trainers": sorted([
3442
f"{trainer.user.get_full_name()} ({trainer.user.email})" for trainer in training.group.trainers.all()
3543
]),
44+
"always_allow": sorted([
45+
f"{student.user.get_full_name()} ({student.user.email})" for student in
46+
training.group.always_allow_students.all()
47+
]),
3648
"checkins": sorted([
3749
f"{checkin.student.user.get_full_name()} ({checkin.student.user.email})" for checkin in training.checkins.all()
3850
]),

0 commit comments

Comments
 (0)