Beispiel #1
0
 def retrieve(self, request, *args, **kwargs):
     instance = self.get_object()
     leader = ProfileSerializer(instance.leader).data
     members = ProfileSerializer(instance.members, many=True).data
     serializer = self.get_serializer(instance)
     data = serializer.data
     data['leader'] = leader
     data['members'] = members
     return Response(data)
Beispiel #2
0
class MessageSerializer(serializers.ModelSerializer):
    profile = ProfileSerializer(read_only=True)

    class Meta:
        model = Message
        fields = [
            'id', 'persian_date_added', 'profile', 'channel_event_id', 'text'
        ]
Beispiel #3
0
class MaterialRequestSignatureSerializer(serializers.ModelSerializer):
    profile = ProfileSerializer()

    class Meta:
        model = MaterialRequestSignature
        fields = [
            'id', 'profile', 'status', 'description', 'persian_date_added',
            'get_status_color'
        ]
Beispiel #4
0
class GalleryPhotoSerializer(serializers.ModelSerializer):
    profile = ProfileSerializer()

    class Meta:
        model = GalleryPhoto
        fields = [
            'id', 'image', 'profile', 'get_absolute_url', 'get_edit_url',
            'persian_date_added', 'thumbnail', 'image_description',
            'image_title', 'location'
        ]
Beispiel #5
0
    def update(self, request, *args, **kwargs):
        partial = kwargs.pop('partial', False)
        instance = self.get_object()
        serializer = self.get_serializer(instance,
                                         data=request.data,
                                         partial=partial)
        serializer.is_valid(raise_exception=True)
        self.perform_update(serializer)
        leader = ProfileSerializer(instance.leader).data
        members = ProfileSerializer(instance.members, many=True).data
        data = serializer.data
        data['leader'] = leader
        data['members'] = members

        if getattr(instance, '_prefetched_objects_cache', None):
            # If 'prefetch_related' has been applied to a queryset, we need to
            # forcibly invalidate the prefetch cache on the instance.
            instance._prefetched_objects_cache = {}

        return Response(data)
Beispiel #6
0
class MaterialRequestSerializer(serializers.ModelSerializer):
    material = MaterialSerializer()
    profile = ProfileSerializer()
    project = ProjectSerializer()

    class Meta:
        model = MaterialRequest
        fields = [
            'id', 'material', 'profile', 'project', 'get_absolute_url',
            'get_edit_url', 'get_status_tag', 'quantity', 'persian_date_added',
            'persian_date_delivered'
        ]
Beispiel #7
0
 def post(self, request, *args, **kwargs):
     data = request.data
     print(request.user)
     serializer = ProfileSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     serializer.save(user=request.user)
     return Response(serializer.data, status=status.HTTP_201_CREATED)
Beispiel #8
0
def jwt_response_payload_handler(token, user=None, request=None):
    """JWT login response with serialized Profile data."""
    return {
        'token':
        token,
        'profile':
        ProfileSerializer(
            user.profile,
            context={
                'request': request
            },
        ).data
    }
Beispiel #9
0
    def post(self, request, *args, **kwargs):

        try:
            profile_serializer = ProfileSerializer(
                data={
                    "user": self.request.user.pk,
                    "name": request.data['name'],
                    "email": request.data['email'],
                    "course": request.data['course'],
                    "user_permissions": request.data['user_permissions'],
                    "code": request.data['code']
                })
            if profile_serializer.is_valid():
                profile_serializer.save()
                return Response(profile_serializer.data,
                                status=status.HTTP_201_CREATED)
            else:
                return Response(profile_serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)

        except Exception as e:
            return Response(data={"Error creating profile.",
                                  str(e)},
                            status=400)
 def get_profile(self, obj):
     serializer = ProfileSerializer(obj.profile)
     return serializer.data
Beispiel #11
0
class DocumentSerializer(serializers.ModelSerializer):
    profile = ProfileSerializer()

    class Meta:
        model = Document
        fields = ['id', 'get_link', 'profile', 'title', 'get_download_url']
Beispiel #12
0
class EmployeeSerializer(serializers.ModelSerializer):
    profile = ProfileSerializer()

    class Meta:
        model = Employee
        fields = ['id', 'role', 'get_absolute_url', 'profile']