10c329da8d
Assigns the weight in the preorder traversal of the tree. Now one without every object (e.g. missing motions/items) still have the correct sorting. Intorduces the level attribute of items giving the amount of parents in the agenda. This allows to reduce complexits in the client.
66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
from openslides.utils.rest_api import JSONField, ModelSerializer, RelatedField
|
|
|
|
from .models import Item, Speaker
|
|
|
|
|
|
class SpeakerSerializer(ModelSerializer):
|
|
"""
|
|
Serializer for agenda.models.Speaker objects.
|
|
"""
|
|
|
|
class Meta:
|
|
model = Speaker
|
|
fields = (
|
|
"id",
|
|
"user",
|
|
"begin_time",
|
|
"end_time",
|
|
"weight",
|
|
"marked",
|
|
"item", # js-data needs the item-id in the nested object to define relations.
|
|
)
|
|
|
|
|
|
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)
|
|
speakers = SpeakerSerializer(many=True, 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",
|
|
"speakers",
|
|
"speaker_list_closed",
|
|
"content_object",
|
|
"weight",
|
|
"parent",
|
|
"level",
|
|
)
|