OpenSlides/openslides/topics/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

63 lines
2.3 KiB
Python

from openslides.utils.autoupdate import inform_changed_data
from openslides.utils.rest_api import CharField, IntegerField, ModelSerializer
from openslides.utils.validate import validate_html
from .models import Topic
class TopicSerializer(ModelSerializer):
"""
Serializer for core.models.Topic objects.
"""
agenda_type = IntegerField(
write_only=True, required=False, min_value=1, max_value=3, allow_null=True
)
agenda_parent_id = IntegerField(write_only=True, required=False, min_value=1)
agenda_comment = CharField(write_only=True, required=False, allow_blank=True)
agenda_duration = IntegerField(write_only=True, required=False, min_value=1)
agenda_weight = IntegerField(write_only=True, required=False, min_value=1)
class Meta:
model = Topic
fields = (
"id",
"title",
"text",
"attachments",
"agenda_item_id",
"list_of_speakers_id",
"agenda_type",
"agenda_parent_id",
"agenda_comment",
"agenda_duration",
"agenda_weight",
)
def validate(self, data):
if "text" in data:
data["text"] = validate_html(data["text"])
return data
def create(self, validated_data):
"""
Customized create method. Set information about related agenda item
into agenda_item_update_information container.
"""
agenda_type = validated_data.pop("agenda_type", None)
agenda_parent_id = validated_data.pop("agenda_parent_id", None)
agenda_comment = validated_data.pop("agenda_comment", None)
agenda_duration = validated_data.pop("agenda_duration", None)
agenda_weight = validated_data.pop("agenda_weight", None)
attachments = validated_data.pop("attachments", [])
topic = Topic(**validated_data)
topic.agenda_item_update_information["type"] = agenda_type
topic.agenda_item_update_information["parent_id"] = agenda_parent_id
topic.agenda_item_update_information["comment"] = agenda_comment
topic.agenda_item_update_information["duration"] = agenda_duration
topic.agenda_item_update_information["weight"] = agenda_weight
topic.save(skip_autoupdate=True)
topic.attachments.add(*attachments)
inform_changed_data(topic)
return topic