Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: copy from previous semester #340

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading