Example #1
0
 def post(self, request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         logger.info(f"User {serializer.data.get('username')} is created")
         return Response(serializer.data)
     logger.error(f"User creation failed: {serializer.errors}")
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Example #2
0
class TaskDocumentSerializer(serializers.ModelSerializer):
    creator = UserSerializer(read_only=True)
    task = TaskSerializer(read_only=True)

    class Meta:
        model = TaskDocument
        fields = '__all__'
Example #3
0
class TaskSerializer(serializers.ModelSerializer):
    creator = UserSerializer(read_only=True)
    block = BlockListSerializer(read_only=True)

    class Meta:
        model = Task
        fields = '__all__'
Example #4
0
class ProjectDetailedSerializer(ProjectListSerializer):
    creator = UserSerializer()

    class Meta:
        model = Project
        fields = ('id', 'name', 'description', 'status_name',
                  'project_type_name', 'creator')
Example #5
0
class TaskCreateSerializer(serializers.ModelSerializer):
    priority = serializers.IntegerField()
    creator = UserSerializer(read_only=True)
    block = BlockListSerializer(read_only=True)

    class Meta:
        model = Task
        fields = '__all__'

    def validate_priority(self, value):
        if value > 10 or value < 1:
            raise serializers.ValidationError('Task priority can be between 1 and 10')
        return value
Example #6
0
class ProjectCreateSerializer(serializers.ModelSerializer):
    status = serializers.IntegerField()
    project_type = serializers.IntegerField()
    creator = UserSerializer(read_only=True)

    class Meta:
        model = Project
        fields = '__all__'

    def validate_status(self, value):
        if value > 3 or value < 1:
            raise serializers.ValidationError('Status options: [1, 2, 3]')
        return value

    def validate_project_type(self, value):
        if value > 2 or value < 1:
            raise serializers.ValidationError('Project type options: [1, 2]')
        return value
Example #7
0
 def post(self, request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class ProjectDetailedSerializer(serializers.ModelSerializer):
    creator = UserSerializer()

    class Meta:
        model = Project
        fields = '__all__'
Example #9
0
 def list(self, request, *args, **kwargs):
     user = self.request.user
     serializer = UserSerializer(user)
     return Response(serializer.data)
class TaskDocumentSerializer(serializers.Serializer):
    creator = UserSerializer(read_only=True)
    task = TaskSerializer(read_only=True)
    document = serializers.FileField()