def to_representation(self, value):
     if value.is_main_group_chat:
         if value.group.image_file is None:
             return None
         else:
             return file_serializers.FileServSerializer(
                 value.group.image_file).data
     elif not value.is_group_chat:
         return file_serializers.FileServSerializer(
             value.user_member_list.exclude(
                 id=self.context['request_user_id']).get().image_file).data
     else:
         return None
class UserServSerializer(serializers.ModelSerializer):
    image_file = file_serializers.FileServSerializer(read_only=True)
    date_joined = string_date_from_datetime_field.StringDateFromDateTimeField()

    class Meta:
        model = user.User
        fields = ['id', 'email', 'last_name', 'first_name', 'image_file', 'color', 'is_geo_transmitting_permitted',
                  'is_notifying_permitted', 'date_joined']
class ChatMessageServSerializer(serializers.ModelSerializer):
    file = file_serializers.FileServSerializer(read_only=True)
    user_sender = user_serializers.UserServMiniSerializer(read_only=True)
    send_datetime = string_datetime_field.StringDatetimeField(read_only=True)

    class Meta:
        model = chat_message.ChatMessage
        fields = ['id', 'is_text', 'text', 'file', 'user_sender', 'send_datetime', 'is_read']
class GroupServMiniSerializer(serializers.ModelSerializer):
    image_file = file_serializers.FileServSerializer(read_only=True)
    invite_link = InviteLinkField(source='invite_id')

    class Meta:
        model = group.Group
        fields = [
            'id', 'name', 'image_file', 'invite_link', 'image_file_thumb'
        ]
class SubtaskServSerializer(serializers.ModelSerializer):
    file_list = file_serializers.FileServSerializer(many=True, read_only=True)
    deadline_datetime = string_datetime_field.StringDatetimeField(read_only=True)
    user_responsible_list = user_serializers.UserServMiniSerializer(many=True, read_only=True)
    user_creator = user_serializers.UserServMiniSerializer(read_only=True)

    class Meta:
        model = subtask.Subtask
        fields = ['name', 'description', 'file_list', 'deadline_datetime', 'user_responsible_list', 'status',
                  'create_date', 'user_creator']
Ejemplo n.º 6
0
class MapPointServSerializer(serializers.ModelSerializer):
    image_file = file_serializers.FileServSerializer(read_only=True)
    event_list = event_serializers.EventServMiniSerializer(many=True,
                                                           read_only=True)
    user_creator = user_serializers.UserServMiniSerializer(read_only=True)

    class Meta:
        model = map_point.MapPoint
        fields = [
            'id', 'name', 'description', 'image_file', 'latitude', 'longitude',
            'event_list', 'create_date', 'user_creator'
        ]
class GroupServSerializer(serializers.ModelSerializer):
    image_file = file_serializers.FileServSerializer(read_only=True)
    user_member_list = user_serializers.UserServMiniSerializer(many=True,
                                                               read_only=True)
    user_creator = user_serializers.UserServMiniSerializer(read_only=True)
    invite_link = InviteLinkField(source='invite_id')

    class Meta:
        model = group.Group
        fields = [
            'id', 'name', 'image_file', 'user_member_list', 'create_date',
            'user_creator', 'invite_link'
        ]
class EventServSerializer(serializers.ModelSerializer):
    event_datetime = string_datetime_field.StringDatetimeField()
    file_list = file_serializers.FileServSerializer(many=True, read_only=True)
    map_point = map_point_serializers.MapPointServMiniSerializer(
        read_only=True)
    notify_datetime = string_datetime_field.StringDatetimeField()
    user_creator = user_serializers.UserServMiniSerializer()

    class Meta:
        model = event.Event
        fields = [
            'id', 'event_datetime', 'name', 'description', 'file_list',
            'map_point', 'notify_datetime', 'create_date', 'user_creator'
        ]
    def handle_get(self):
        if 'group_id' in self.request.GET.keys():
            if self.request.GET['group_id'] is None:
                return self.error('No "group_id" value is granted')
            else:
                if not self.get_model_by_id(group.Group, self.request.GET['group_id']) or \
                        not self.user_belong_to_group():
                    return
        else:
            self.dict['group'] = None

        if self.dict['group'] is not None:
            file_list = file.File.objects.filter(group=self.dict['group'])
        else:
            file_list = file.File.objects.filter(
                group=None, user_uploader=self.request.user)

        self.response_dict['file_list'] = file_serializers.FileServSerializer(
            file_list, many=True).data
        return self
Ejemplo n.º 10
0
    def handle_get(self):
        if 'group_id' in self.request.GET.keys():
            if self.request.GET['group_id'] is None:
                return self.error('No "group_id" value is granted')
            else:
                if not self.get_model_by_id(group.Group, self.request.GET['group_id']) or \
                        not self.user_belong_to_group():
                    return
        else:
            self.dict['group'] = None

        if self.dict['file'].group != self.dict['group'] or (
                self.dict['group'] is None
                and self.dict['file'].user_uploader != self.request.user):
            return self.error(
                f'File with id "{self.request.GET["file_id"]}" does not exist',
                404)

        self.response_dict['file_data'] = file_serializers.FileServSerializer(
            self.dict['file']).data
        return self
Ejemplo n.º 11
0
 def handle_get(self) -> Optional[base_view.BaseView]:
     self.response_dict['chat_file_list'] = \
         file_serializers.FileServSerializer(file.File.objects.filter(
             id__in=self.dict['chat'].chat_message_list.filter(is_text=False).values_list('file', flat=True)),
                                             many=True).data
     return self