Fix not allowing program times on event series (API/copy) (#5595)

* Fix not allowing program times on event series (API/copy)

* Return 400 when reading endpoint in event series

* add docs program times not available on event series

* fix isort
This commit is contained in:
Richard Schreiber
2025-11-17 15:36:53 +01:00
committed by GitHub
parent e2d9cbb41d
commit d7b6856322
6 changed files with 20 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ Resource description
-------------------- --------------------
Program times for products (items) that can be set in addition to event times, e.g. to display seperate schedules within an event. Program times for products (items) that can be set in addition to event times, e.g. to display seperate schedules within an event.
Note that ``program_times`` are not available for items inside event series.
The program times resource contains the following public fields: The program times resource contains the following public fields:
.. rst-class:: rest-resource-table .. rst-class:: rest-resource-table

View File

@@ -142,6 +142,7 @@ variations list of objects A list with o
program_times list of objects A list with one object for each program time of this item. program_times list of objects A list with one object for each program time of this item.
Can be empty. Only writable during creation, Can be empty. Only writable during creation,
use separate endpoint to modify this later. use separate endpoint to modify this later.
Not available for items in event series.
├ id integer Internal ID of the variation ├ id integer Internal ID of the variation
├ value multi-lingual string The "name" of the variation ├ value multi-lingual string The "name" of the variation
├ default_price money (string) The price set directly for this variation or ``null`` ├ default_price money (string) The price set directly for this variation or ``null``
@@ -243,6 +244,8 @@ Also note that ``variations``, ``bundles``, ``addons`` and ``program_times`` ar
bundles, add-ons and program times please use the dedicated nested endpoints. By design this endpoint does not support ``PATCH`` and ``PUT`` bundles, add-ons and program times please use the dedicated nested endpoints. By design this endpoint does not support ``PATCH`` and ``PUT``
with nested ``variations``, ``bundles``, ``addons`` and/or ``program_times``. with nested ``variations``, ``bundles``, ``addons`` and/or ``program_times``.
``program_times`` is not available to items in event series.
Endpoints Endpoints
--------- ---------

View File

@@ -241,6 +241,12 @@ class ItemProgramTimeSerializer(serializers.ModelSerializer):
if start > end: if start > end:
raise ValidationError(_("The program end must not be before the program start.")) raise ValidationError(_("The program end must not be before the program start."))
event = self.context['event']
if event.has_subevents:
raise ValidationError({
_("You cannot use program times on an event series.")
})
return data return data

View File

@@ -40,7 +40,7 @@ from django_filters.rest_framework import DjangoFilterBackend, FilterSet
from django_scopes import scopes_disabled from django_scopes import scopes_disabled
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.exceptions import PermissionDenied from rest_framework.exceptions import PermissionDenied, ValidationError
from rest_framework.response import Response from rest_framework.response import Response
from pretix.api.pagination import TotalOrderingFilter from pretix.api.pagination import TotalOrderingFilter
@@ -293,6 +293,8 @@ class ItemProgramTimeViewSet(viewsets.ModelViewSet):
return get_object_or_404(Item, pk=self.kwargs['item'], event=self.request.event) return get_object_or_404(Item, pk=self.kwargs['item'], event=self.request.event)
def get_queryset(self): def get_queryset(self):
if self.request.event.has_subevents:
raise ValidationError('You cannot use program times on an event series.')
return self.item.program_times.all() return self.item.program_times.all()
def get_serializer_context(self): def get_serializer_context(self):

View File

@@ -990,10 +990,11 @@ class Event(EventMixin, LoggedModel):
ia.bundled_variation = variation_map[ia.bundled_variation.pk] ia.bundled_variation = variation_map[ia.bundled_variation.pk]
ia.save(force_insert=True) ia.save(force_insert=True)
for ipt in ItemProgramTime.objects.filter(item__event=other).prefetch_related('item'): if not self.has_subevents and not other.has_subevents:
ipt.pk = None for ipt in ItemProgramTime.objects.filter(item__event=other).prefetch_related('item'):
ipt.item = item_map[ipt.item.pk] ipt.pk = None
ipt.save(force_insert=True) ipt.item = item_map[ipt.item.pk]
ipt.save(force_insert=True)
quota_map = {} quota_map = {}
for q in Quota.objects.filter(event=other, subevent__isnull=True).prefetch_related('items', 'variations'): for q in Quota.objects.filter(event=other, subevent__isnull=True).prefetch_related('items', 'variations'):

View File

@@ -2311,6 +2311,8 @@ class ItemProgramTime(models.Model):
end = models.DateTimeField(verbose_name=_("End")) end = models.DateTimeField(verbose_name=_("End"))
def clean(self): def clean(self):
if self.item.event.has_subevents:
raise ValidationError(_("You cannot use program times on an event series."))
self.clean_start_end(start=self.start, end=self.end) self.clean_start_end(start=self.start, end=self.end)
super().clean() super().clean()