From 26f8dd1015473ffe46eb74df83ecd1f3728c4a0e Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Tue, 1 Aug 2023 19:19:52 -0400 Subject: [PATCH] fix: remove remaining references to show and note in Timeslot --- conftest.py | 10 +++++----- program/models.py | 3 +-- program/serializers.py | 17 +---------------- program/services.py | 2 +- program/tests/__init__.py | 1 - program/views.py | 4 ++-- 6 files changed, 10 insertions(+), 27 deletions(-) diff --git a/conftest.py b/conftest.py index d97fe16a..43700e35 100644 --- a/conftest.py +++ b/conftest.py @@ -5,17 +5,17 @@ from rest_framework.test import APIClient from django.contrib.auth.models import User from django.core.files.uploadedfile import SimpleUploadedFile -from program.models import FundingCategory, Host, RRule, Schedule, Show, TimeSlot, Type, Image +from program.models import FundingCategory, Host, Image, RRule, Schedule, Show, TimeSlot, Type from program.tests.factories import ( CommonUserFactory, FundingCategoryFactory, HostFactory, + ImageFactory, RRuleFactory, ScheduleFactory, ShowFactory, TimeslotFactory, TypeFactory, - ImageFactory, ) @@ -119,14 +119,14 @@ def owned_show_once_timeslot(common_user1, show, once_schedule) -> TimeSlot: show.owners.set([common_user1]) show.save() - timeslot = TimeslotFactory(show=show, schedule=once_schedule) + timeslot = TimeslotFactory(schedule=once_schedule) return timeslot @pytest.fixture -def once_timeslot(show, once_schedule) -> TimeSlot: - return TimeslotFactory(show=show, schedule=once_schedule) +def once_timeslot(once_schedule) -> TimeSlot: + return TimeslotFactory(schedule=once_schedule) @pytest.fixture diff --git a/program/models.py b/program/models.py index c59a7d5d..31abd0af 100644 --- a/program/models.py +++ b/program/models.py @@ -357,11 +357,10 @@ class Schedule(models.Model): class TimeSlotManager(models.Manager): @staticmethod - def instantiate(start, end, schedule, show): + def instantiate(start, end, schedule): return TimeSlot( start=parse_datetime(start), end=parse_datetime(end), - show=show, schedule=schedule, ) diff --git a/program/serializers.py b/program/serializers.py index 88560cfb..6add3d5e 100644 --- a/program/serializers.py +++ b/program/serializers.py @@ -735,7 +735,7 @@ class TimeSlotSerializer(serializers.ModelSerializer): @staticmethod def get_note_id(obj): - return obj.note.id + return obj.note.id if hasattr(obj, "note") else None def update(self, instance, validated_data): """Update and return an existing Show instance, given the validated data.""" @@ -857,19 +857,4 @@ class NoteSerializer(serializers.ModelSerializer): instance.save() - # Remove existing note connections from timeslots - timeslots = TimeSlot.objects.filter(note_id=instance.id) - for ts in timeslots: - ts.note_id = None - ts.save(update_fields=["note_id"]) - - # Assign note to timeslot - if instance.timeslot.id is not None: - try: - timeslot = TimeSlot.objects.get(pk=instance.timeslot.id) - timeslot.note_id = instance.id - timeslot.save(update_fields=["note_id"]) - except ObjectDoesNotExist: - pass - return instance diff --git a/program/services.py b/program/services.py index eb56f740..0827568e 100644 --- a/program/services.py +++ b/program/services.py @@ -148,7 +148,7 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s if "solution_choices" not in timeslot or len(timeslot["collisions"]) == 0: to_create.append( TimeSlot.objects.instantiate( - timeslot["start"], timeslot["end"], new_schedule, show + timeslot["start"], timeslot["end"], new_schedule ), ) continue diff --git a/program/tests/__init__.py b/program/tests/__init__.py index d8d33cba..5df9849a 100644 --- a/program/tests/__init__.py +++ b/program/tests/__init__.py @@ -67,7 +67,6 @@ class TimeSlotMixin: def _create_timeslot(self, schedule: Schedule, **kwargs): _start = kwargs.get("start", now()) kwargs.setdefault("schedule", schedule) - kwargs.setdefault("show", schedule.show) kwargs.setdefault("start", _start) kwargs.setdefault("end", _start + datetime.timedelta(hours=1)) return TimeSlot.objects.create(**kwargs) diff --git a/program/views.py b/program/views.py index b16a762e..230a72e6 100644 --- a/program/views.py +++ b/program/views.py @@ -865,7 +865,7 @@ class APINoteViewSet( # If the request is not by an admin, # check that the timeslot is owned by the current user. if not self.request.user.is_superuser: - qs = qs.filter(timeslot__show__owners=self.request.user) + qs = qs.filter(timeslot__schedule__show__owners=self.request.user) return qs def _get_timeslot(self): @@ -878,7 +878,7 @@ class APINoteViewSet( raise ValidationError({"timeslot_id": [_("This field is required.")]}, code="required") qs = TimeSlot.objects.all() if not self.request.user.is_superuser: - qs = qs.filter(show__owners=self.request.user) + qs = qs.filter(schedule__show__owners=self.request.user) try: return qs.get(pk=timeslot_pk) except TimeSlot.DoesNotExist: -- GitLab