Skip to content

Commit

Permalink
fix: copy from previous semester
Browse files Browse the repository at this point in the history
  • Loading branch information
fivan999 authored and ArtemSBulgakov committed Jan 27, 2025
1 parent 5763982 commit 414a464
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions adminpage/adminpage/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def compose_base_url(schema, hostname, port) -> str:
EXTRA_EVENTS_GROUP_NAME = "Extra sport events"
MEDICAL_LEAVE_GROUP_NAME = "Medical leave"
OTHER_SPORT_NAME = "Other"
# Groups that should not be duplicated when copying all sport groups from previous semester
NOT_COPYABLE_GROUPS = [SELF_TRAINING_GROUP_NAME, EXTRA_EVENTS_GROUP_NAME, MEDICAL_LEAVE_GROUP_NAME]

TRAINING_EDITABLE_INTERVAL = timedelta(
days=3
Expand Down
5 changes: 4 additions & 1 deletion adminpage/sport/admin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from api.crud import get_ongoing_semester
from sport.models import Schedule, Semester, Group
from adminpage.settings import NOT_COPYABLE_GROUPS


class DurationWidget(forms.TimeInput):
Expand Down Expand Up @@ -258,11 +259,13 @@ def queryset(self, request, queryset):


def copy_sport_groups_and_schedule_from_previous_semester(semester: Semester) -> None:
Semester.objects.bulk_create([semester])
semester.save()
prev_semester = Semester.objects.filter(start__lt=semester.start).order_by('-start').first()
sport_groups = Group.objects.filter(semester__pk=prev_semester.pk).prefetch_related('trainers', 'allowed_medical_groups', 'schedule').select_related('trainer').order_by('pk')
new_sport_groups = []
for group in sport_groups:
if group.name in NOT_COPYABLE_GROUPS:
continue
new_group = Group(
semester=semester,
sport=group.sport,
Expand Down

0 comments on commit 414a464

Please # to comment.