Source code for memopolis.api.serializers

from rest_framework import serializers

from .. import models


[docs] class UserSerializer(serializers.ModelSerializer): active_team_name = serializers.SerializerMethodField()
[docs] def get_active_team_name(self, obj): return obj.active_team.name if obj.active_team else ""
organization_name = serializers.SerializerMethodField()
[docs] def get_organization_name(self, obj): return obj.organization.name if obj.organization else ""
class Meta: model = models.User fields = ('id', 'username', 'first_name', 'last_name', 'email', 'language', 'organization', 'organization_name', 'is_staff', 'is_superuser', 'json', 'admin_teams', 'admin_organizations', 'teams', 'active_team', 'active_team_name') depth = 1
[docs] class ContentSerializer(serializers.ModelSerializer): class Meta: model = models.Content fields = ('id', 'team', 'image') image = serializers.SerializerMethodField()
[docs] def get_image(self, obj): request = self.context.get('request') return request.build_absolute_uri(obj.image.url) # https
[docs] class WorldObjectSerializer(serializers.ModelSerializer): class Meta: model = models.WorldObject fields = ('id', 'content', 'position_x', 'position_y', 'map') depth = 0
[docs] class TeamSerializer(serializers.ModelSerializer): users = UserSerializer(many=True, read_only=True) admins = UserSerializer(many=True, read_only=True) organization_name = serializers.SerializerMethodField()
[docs] def get_organization_name(self, obj): return obj.organization.name if obj.organization else ""
class Meta: model = models.Team fields = ('id', 'name', 'organization', 'users', 'admins', 'organization_name') depth = 0
[docs] def perform_create(self, serializer): serializer.save(owner=self.request.user)
[docs] class BasicUserSerializer(serializers.ModelSerializer): class Meta: model = models.User
[docs] class FeedbackTicketSerializer(serializers.ModelSerializer): user = serializers.PrimaryKeyRelatedField( queryset=models.User.objects.all(), write_only=True, required=False, ) class Meta: model = models.FeedbackTicket fields = ( "id", "uuid", "text", "emotion", "category", "timestamp", "git_hash", "os", "screenshot", "user" ) depth = 1