2019-02-15 12:17:08 +01:00
|
|
|
from openslides.utils.rest_api import JSONField, ModelSerializer, RelatedField
|
2015-01-24 16:35:50 +01:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
from .models import Item, ListOfSpeakers, Speaker
|
2015-01-06 00:14:49 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class SpeakerSerializer(ModelSerializer):
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
2015-01-17 14:25:05 +01:00
|
|
|
Serializer for agenda.models.Speaker objects.
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-01-06 00:14:49 +01:00
|
|
|
class Meta:
|
|
|
|
model = Speaker
|
2020-10-14 15:08:14 +02:00
|
|
|
fields = (
|
|
|
|
"id",
|
|
|
|
"user",
|
|
|
|
"begin_time",
|
|
|
|
"end_time",
|
|
|
|
"weight",
|
2021-04-22 11:25:27 +02:00
|
|
|
"note",
|
2020-10-14 15:08:14 +02:00
|
|
|
"marked",
|
|
|
|
"point_of_order",
|
2021-04-22 11:25:27 +02:00
|
|
|
"pro_speech",
|
|
|
|
)
|
|
|
|
read_only_fields = (
|
|
|
|
"id",
|
|
|
|
"user",
|
|
|
|
"begin_time",
|
|
|
|
"end_time",
|
|
|
|
"weight",
|
|
|
|
"note",
|
|
|
|
"point_of_order",
|
2020-10-14 15:08:14 +02:00
|
|
|
)
|
2015-01-06 00:14:49 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class RelatedItemRelatedField(RelatedField):
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
2015-02-04 00:08:38 +01:00
|
|
|
A custom field to use for the content_object generic relationship.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
def to_representation(self, value):
|
|
|
|
"""
|
2015-02-04 00:08:38 +01:00
|
|
|
Returns info concerning the related object extracted from the api URL
|
|
|
|
of this object.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
return {"collection": value.get_collection_string(), "id": value.get_rest_pk()}
|
2015-01-17 14:25:05 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class ItemSerializer(ModelSerializer):
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
2015-01-17 14:25:05 +01:00
|
|
|
Serializer for agenda.models.Item objects.
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
content_object = RelatedItemRelatedField(read_only=True)
|
2015-01-06 00:14:49 +01:00
|
|
|
|
2019-02-15 12:17:08 +01:00
|
|
|
title_information = JSONField(read_only=True)
|
|
|
|
|
2015-01-06 00:14:49 +01:00
|
|
|
class Meta:
|
|
|
|
model = Item
|
2015-01-24 16:35:50 +01:00
|
|
|
fields = (
|
2019-01-06 16:22:33 +01:00
|
|
|
"id",
|
|
|
|
"item_number",
|
2019-02-15 12:17:08 +01:00
|
|
|
"title_information",
|
2019-01-06 16:22:33 +01:00
|
|
|
"comment",
|
|
|
|
"closed",
|
|
|
|
"type",
|
|
|
|
"is_internal",
|
|
|
|
"is_hidden",
|
|
|
|
"duration",
|
|
|
|
"content_object",
|
|
|
|
"weight",
|
|
|
|
"parent",
|
2019-05-13 15:50:27 +02:00
|
|
|
"level",
|
2020-05-14 15:07:59 +02:00
|
|
|
"tags",
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-04-23 16:57:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ListOfSpeakersSerializer(ModelSerializer):
|
|
|
|
"""
|
|
|
|
Serializer for agenda.models.Item objects.
|
|
|
|
"""
|
|
|
|
|
|
|
|
content_object = RelatedItemRelatedField(read_only=True)
|
|
|
|
speakers = SpeakerSerializer(many=True, read_only=True)
|
|
|
|
|
|
|
|
title_information = JSONField(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ListOfSpeakers
|
|
|
|
fields = ("id", "title_information", "speakers", "closed", "content_object")
|
|
|
|
read_only_fields = ("id", "title_information", "speakers", "content_object")
|