2015-02-04 00:08:38 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
2015-01-06 00:14:49 +01:00
|
|
|
|
2015-02-04 00:08:38 +01:00
|
|
|
from openslides.utils.rest_api import get_collection_and_id_from_url, serializers
|
2015-01-24 16:35:50 +01:00
|
|
|
|
2015-01-06 00:14:49 +01:00
|
|
|
from .models import Item, Speaker
|
|
|
|
|
|
|
|
|
2015-02-04 00:08:38 +01:00
|
|
|
class SpeakerSerializer(serializers.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
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = Speaker
|
|
|
|
fields = (
|
|
|
|
'id',
|
|
|
|
'user',
|
|
|
|
'begin_time',
|
|
|
|
'end_time',
|
|
|
|
'weight')
|
|
|
|
|
|
|
|
|
2015-01-24 16:35:50 +01:00
|
|
|
class RelatedItemRelatedField(serializers.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
|
|
|
"""
|
|
|
|
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
|
|
|
"""
|
|
|
|
view_name = '%s-detail' % type(value)._meta.object_name.lower()
|
2015-02-04 00:08:38 +01:00
|
|
|
url = reverse(view_name, kwargs={'pk': value.pk})
|
|
|
|
collection, obj_id = get_collection_and_id_from_url(url)
|
|
|
|
return {'collection': collection, 'id': obj_id}
|
2015-01-17 14:25:05 +01:00
|
|
|
|
|
|
|
|
2015-02-04 00:08:38 +01:00
|
|
|
class ItemSerializer(serializers.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
|
|
|
"""
|
2015-01-24 16:35:50 +01:00
|
|
|
get_title = serializers.CharField(read_only=True)
|
|
|
|
get_title_supplement = serializers.CharField(read_only=True)
|
2015-01-17 14:25:05 +01:00
|
|
|
content_object = RelatedItemRelatedField(read_only=True)
|
2015-01-24 16:35:50 +01:00
|
|
|
item_no = serializers.CharField(read_only=True)
|
|
|
|
speaker_set = SpeakerSerializer(many=True, read_only=True)
|
2015-01-06 00:14:49 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Item
|
2015-01-24 16:35:50 +01:00
|
|
|
fields = (
|
2015-02-04 00:08:38 +01:00
|
|
|
'id',
|
2015-01-24 16:35:50 +01:00
|
|
|
'item_number',
|
|
|
|
'item_no',
|
|
|
|
'title',
|
|
|
|
'get_title',
|
|
|
|
'get_title_supplement',
|
|
|
|
'text',
|
|
|
|
'comment',
|
|
|
|
'closed',
|
|
|
|
'type',
|
|
|
|
'duration',
|
|
|
|
'speaker_set',
|
|
|
|
'speaker_list_closed',
|
|
|
|
'content_object',
|
|
|
|
'weight',
|
|
|
|
'lft',
|
|
|
|
'rght',
|
|
|
|
'tree_id',
|
|
|
|
'level',
|
|
|
|
'parent',
|
|
|
|
'tags',)
|