OpenSlides/openslides/agenda/serializers.py
Emanuel Schuetze 23503eb4ba Several template fixes and clean up
- Use ng-cloak for hide template parts while loading.
- Set html lang attribute dynamically (Fixes #1546)
- Clean up: Rename 'dashboard' to 'home'.
- Show duration of speech in minutes. (Fixes #1882)
- Save agenda specific stuff for customslides. (Fixes #1887)
- Remove title from QuickEdit from.
- Checkbox for item.closed is now visible for manager only.
- Agenda list view: Show list of speakers link also for normal users.
- Improve slide templates: Show agenda item number and subtitle.
- Fixed agenda title for motions and assignments.
  (Don't load motions and assignmetn in agenda app.)
- Added missing seach template.
2016-01-27 12:10:40 +01:00

67 lines
1.7 KiB
Python

from django.core.urlresolvers import reverse
from openslides.utils.rest_api import (
ModelSerializer,
RelatedField,
get_collection_and_id_from_url,
)
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',
'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.
"""
view_name = '%s-detail' % type(value)._meta.object_name.lower()
url = reverse(view_name, kwargs={'pk': value.pk})
collection, obj_id = get_collection_and_id_from_url(url)
return {'collection': collection, 'id': obj_id}
class ItemSerializer(ModelSerializer):
"""
Serializer for agenda.models.Item objects.
"""
content_object = RelatedItemRelatedField(read_only=True)
speakers = SpeakerSerializer(many=True, read_only=True)
class Meta:
model = Item
fields = (
'id',
'item_number',
'title',
'list_view_title',
'comment',
'closed',
'type',
'is_hidden',
'duration',
'speakers',
'speaker_list_closed',
'content_object',
'weight',
'parent',)