OpenSlides/openslides/agenda/serializers.py
FinnStutzenstein 9f12763f8b Split AgendaItem and ListOfSpeakers
Server:
- ListOfSpeakers (LOS) is now a speprate model, containing of an id,
speakers, closed and a content_object.
- Moved all speaker related views from ItemViewSet to the new
ListOfSpeakersViewSet.
- Make Mixins for content objects of items and lists of speakers.
- Migrations: Move the lists of speakers from items to the LOS model.

Client:
- Removed the speaker repo and moved functionality to the new
ListOfSpeakersRepositoryService.
- Splitted base classes for agenda item content objects to items and
LOS.
- CurrentAgendaItemService -> CurrentListOfSpeakersSerivce
- Cleaned up the list of speakers component.
2019-05-24 08:21:59 +02:00

71 lines
1.8 KiB
Python

from openslides.utils.rest_api import JSONField, ModelSerializer, RelatedField
from .models import Item, ListOfSpeakers, Speaker
class SpeakerSerializer(ModelSerializer):
"""
Serializer for agenda.models.Speaker objects.
"""
class Meta:
model = Speaker
fields = ("id", "user", "begin_time", "end_time", "weight", "marked")
class RelatedItemRelatedField(RelatedField):
"""
A custom field to use for the content_object generic relationship.
"""
def to_representation(self, value):
"""
Returns info concerning the related object extracted from the api URL
of this object.
"""
return {"collection": value.get_collection_string(), "id": value.get_rest_pk()}
class ItemSerializer(ModelSerializer):
"""
Serializer for agenda.models.Item objects.
"""
content_object = RelatedItemRelatedField(read_only=True)
title_information = JSONField(read_only=True)
class Meta:
model = Item
fields = (
"id",
"item_number",
"title_information",
"comment",
"closed",
"type",
"is_internal",
"is_hidden",
"duration",
"content_object",
"weight",
"parent",
"level",
)
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")