eed5c59013
Added api for groups. Refactored serializers now using 'id' instead of 'url'. Rework of tornado autoupdate functionality. Implemented extra data in SockJS messages.
71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
from openslides.utils.rest_api import serializers
|
|
|
|
from .models import Group, User # TODO: Don't import Group from models but from core.models.
|
|
|
|
|
|
class UserShortSerializer(serializers.ModelSerializer):
|
|
"""
|
|
Serializer for users.models.User objects.
|
|
|
|
Serializes only name fields.
|
|
"""
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
'id',
|
|
'username',
|
|
'title',
|
|
'first_name',
|
|
'last_name',
|
|
'structure_level',
|
|
'groups',)
|
|
|
|
|
|
class UserFullSerializer(serializers.ModelSerializer):
|
|
"""
|
|
Serializer for users.models.User objects.
|
|
|
|
Serializes all relevant fields.
|
|
"""
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
'id',
|
|
'is_present',
|
|
'username',
|
|
'title',
|
|
'first_name',
|
|
'last_name',
|
|
'structure_level',
|
|
'about_me',
|
|
'comment',
|
|
'groups',
|
|
'default_password',
|
|
'last_login',
|
|
'is_active',)
|
|
|
|
|
|
class PermissionRelatedField(serializers.RelatedField):
|
|
"""
|
|
A custom field to use for the permission relationship.
|
|
"""
|
|
def to_representation(self, value):
|
|
"""
|
|
Returns the permission name (app_label.codename).
|
|
"""
|
|
return '.'.join((value.content_type.app_label, value.codename,))
|
|
|
|
|
|
class GroupSerializer(serializers.ModelSerializer):
|
|
"""
|
|
Serializer for django.contrib.auth.models.Group objects.
|
|
"""
|
|
permissions = PermissionRelatedField(many=True, read_only=True)
|
|
|
|
class Meta:
|
|
model = Group
|
|
fields = (
|
|
'id',
|
|
'name',
|
|
'permissions',)
|