forked from CGM_Public/pretix_original
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from django.utils.translation import ugettext as _
|
|
from rest_framework import serializers
|
|
from rest_framework.exceptions import ValidationError
|
|
|
|
from pretix.api.serializers.i18n import I18nAwareModelSerializer
|
|
from pretix.base.models import CheckinList
|
|
|
|
|
|
class CheckinListSerializer(I18nAwareModelSerializer):
|
|
checkin_count = serializers.IntegerField(read_only=True)
|
|
position_count = serializers.IntegerField(read_only=True)
|
|
|
|
class Meta:
|
|
model = CheckinList
|
|
fields = ('id', 'name', 'all_products', 'limit_products', 'subevent', 'checkin_count', 'position_count',
|
|
'include_pending')
|
|
|
|
def validate(self, data):
|
|
data = super().validate(data)
|
|
event = self.context['event']
|
|
|
|
full_data = self.to_internal_value(self.to_representation(self.instance)) if self.instance else {}
|
|
full_data.update(data)
|
|
|
|
for item in full_data.get('limit_products'):
|
|
if event != item.event:
|
|
raise ValidationError(_('One or more items do not belong to this event.'))
|
|
|
|
if event.has_subevents:
|
|
if not full_data.get('subevent'):
|
|
raise ValidationError(_('Subevent cannot be null for event series.'))
|
|
if event != full_data.get('subevent').event:
|
|
raise ValidationError(_('The subevent does not belong to this event.'))
|
|
else:
|
|
if full_data.get('subevent'):
|
|
raise ValidationError(_('The subevent does not belong to this event.'))
|
|
|
|
return data
|