2024-02-07 01:26:49 +00:00
|
|
|
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
2020-02-07 16:02:07 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2024-08-01 12:49:52 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-02-07 16:02:07 +00:00
|
|
|
from rest_framework import serializers
|
2024-08-01 12:49:52 +00:00
|
|
|
from rest_framework.validators import UniqueTogetherValidator
|
2020-02-07 16:02:07 +00:00
|
|
|
|
2024-08-01 12:49:52 +00:00
|
|
|
from ..models import Activity, ActivityType, Entry, Guest, GuestTransaction, Opener
|
2020-02-18 20:14:29 +00:00
|
|
|
|
2020-02-18 11:31:15 +00:00
|
|
|
|
2020-02-07 19:47:49 +00:00
|
|
|
class ActivityTypeSerializer(serializers.ModelSerializer):
|
2020-02-07 16:02:07 +00:00
|
|
|
"""
|
|
|
|
REST API Serializer for Activity types.
|
|
|
|
The djangorestframework plugin will analyse the model `ActivityType` and parse all fields in the API.
|
|
|
|
"""
|
2020-03-07 21:28:59 +00:00
|
|
|
|
2020-02-07 16:02:07 +00:00
|
|
|
class Meta:
|
|
|
|
model = ActivityType
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
|
2020-02-07 19:47:49 +00:00
|
|
|
class ActivitySerializer(serializers.ModelSerializer):
|
2020-02-07 16:02:07 +00:00
|
|
|
"""
|
|
|
|
REST API Serializer for Activities.
|
|
|
|
The djangorestframework plugin will analyse the model `Activity` and parse all fields in the API.
|
|
|
|
"""
|
2020-03-07 21:28:59 +00:00
|
|
|
|
2020-02-07 16:02:07 +00:00
|
|
|
class Meta:
|
|
|
|
model = Activity
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
|
2020-02-07 19:47:49 +00:00
|
|
|
class GuestSerializer(serializers.ModelSerializer):
|
2020-02-07 16:02:07 +00:00
|
|
|
"""
|
|
|
|
REST API Serializer for Guests.
|
|
|
|
The djangorestframework plugin will analyse the model `Guest` and parse all fields in the API.
|
|
|
|
"""
|
2020-03-07 21:28:59 +00:00
|
|
|
|
2020-02-07 16:02:07 +00:00
|
|
|
class Meta:
|
|
|
|
model = Guest
|
|
|
|
fields = '__all__'
|
2020-03-28 12:38:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EntrySerializer(serializers.ModelSerializer):
|
|
|
|
"""
|
|
|
|
REST API Serializer for Entries.
|
|
|
|
The djangorestframework plugin will analyse the model `Entry` and parse all fields in the API.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Entry
|
|
|
|
fields = '__all__'
|
2020-03-28 15:52:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GuestTransactionSerializer(serializers.ModelSerializer):
|
|
|
|
"""
|
|
|
|
REST API Serializer for Special transactions.
|
|
|
|
The djangorestframework plugin will analyse the model `GuestTransaction` and parse all fields in the API.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = GuestTransaction
|
|
|
|
fields = '__all__'
|
2024-08-01 12:49:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OpenerSerializer(serializers.ModelSerializer):
|
|
|
|
"""
|
|
|
|
REST API Serializer for Openers.
|
|
|
|
The djangorestframework plugin will analyse the model `Opener` and parse all fields in the API.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Opener
|
|
|
|
fields = '__all__'
|
|
|
|
validators = [UniqueTogetherValidator(
|
|
|
|
queryset=Opener.objects.all(), fields=("opener", "activity"),
|
|
|
|
message=_("This opener already exists"))]
|