diff --git a/conftest.py b/conftest.py index d97fe16afb2b1cbc0e41e294958b4ed9fc016a09..43700e350b983091d5414c83cafc39006b93a666 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 c59a7d5d38cd68499cc6bbb20a055e4e501cef1e..31abd0af7433f3f1dd822073c33c9b9fb5d5456d 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 88560cfb1d45755809069bb7f529c5694f99973c..6add3d5e38ff94093c4b68b25cb6fa447d204283 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 eb56f7402075cd40b338ba676c9dc68f91c8438c..0827568ee0b31f6ffe131b085d25fd81e92b5dd9 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 d8d33cba9cb969c5f43dc59d3d25212ca300a16a..5df9849a92abc85449f8ee23f26cb9b15ca6c24d 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 b16a762ef404b0f8ad340bf204c5c85a0c134550..230a72e63b5b1152b3ac3a055ddf2be7a33dd900 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: