2015-01-17 14:25:05 +01:00
|
|
|
from openslides.utils import rest_api
|
2015-01-17 14:25:05 +01:00
|
|
|
from rest_framework.reverse import reverse
|
2015-01-06 00:14:49 +01:00
|
|
|
|
|
|
|
from .models import Item, Speaker
|
|
|
|
|
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
class SpeakerSerializer(rest_api.serializers.HyperlinkedModelSerializer):
|
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-17 14:25:05 +01:00
|
|
|
class RelatedItemRelatedField(rest_api.serializers.RelatedField):
|
|
|
|
"""
|
|
|
|
A custom field to use for the `content_object` generic relationship.
|
|
|
|
"""
|
|
|
|
def to_representation(self, value):
|
|
|
|
"""
|
|
|
|
Returns the url to the related object.
|
|
|
|
"""
|
|
|
|
request = self.context.get('request', None)
|
|
|
|
assert request is not None, (
|
|
|
|
"`%s` requires the request in the serializer"
|
|
|
|
" context. Add `context={'request': request}` when instantiating "
|
|
|
|
"the serializer." % self.__class__.__name__)
|
|
|
|
view_name = '%s-detail' % type(value)._meta.object_name.lower()
|
|
|
|
return reverse(view_name, kwargs={'pk': value.pk}, request=request)
|
|
|
|
|
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
class ItemSerializer(rest_api.serializers.HyperlinkedModelSerializer):
|
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-17 14:25:05 +01:00
|
|
|
get_title = rest_api.serializers.CharField(read_only=True)
|
|
|
|
get_title_supplement = rest_api.serializers.CharField(read_only=True)
|
|
|
|
item_no = rest_api.serializers.CharField(read_only=True)
|
2015-01-06 00:14:49 +01:00
|
|
|
speaker_set = SpeakerSerializer(many=True, read_only=True)
|
2015-01-17 14:25:05 +01:00
|
|
|
tags = rest_api.serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='tag-detail')
|
2015-01-17 14:25:05 +01:00
|
|
|
content_object = RelatedItemRelatedField(read_only=True)
|
2015-01-06 00:14:49 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Item
|
|
|
|
exclude = ('content_type', 'object_id')
|