Ejemplo n.º 1
0
	class Meta:
		model = UserModel
		exists = True
		fields = ('author_pk',)
		validators = [
			RequiredValidator(fields=('author_pk',))
		]
Ejemplo n.º 2
0
 class Meta:
     model = ImageModel
     fields = ('id', 'image', 'artwork')
     read_only_fields = ('id', )
     extra_kwargs = {
         'image': {
             'write_only': True
         },
         'artwork': {
             'write_only': True
         }
     }
     validators = [RequiredValidator(fields=('image', 'artwork'))]
Ejemplo n.º 3
0
 class Meta:
     model = UserModel
     fields = ('id', 'username', 'email', 'password', 'first_name',
               'last_name', 'avatar', 'is_superuser', 'rating')
     read_only_fields = ('id', 'first_name', 'last_name', 'avatar',
                         'rating', 'is_superuser')
     extra_kwargs = {
         'password': {
             'write_only': True
         },
     }
     validators = [
         RequiredValidator(fields=('username', 'email', 'password')),
         UsernameValidator(),
         PasswordValidator()
     ]
Ejemplo n.º 4
0
 class Meta:
     model = CommentModel
     fields = ('id', 'text', 'author', 'author_details', 'artwork')
     read_only_fields = ('id', 'author_details')
     extra_kwargs = {
         'text': {
             'write_only': True
         },
         'author': {
             'write_only': True
         },
         'artwork': {
             'write_only': True
         }
     }
     validators = [RequiredValidator(fields=('text', 'author', 'artwork'))]
Ejemplo n.º 5
0
class EditSelfPasswordAPIView(APIView, UpdateUserModelMixin,
                              APIViewValidationMixin):
    validators = (RequiredValidator(fields=('old_password', 'new_password')),
                  PasswordValidator(password_key='new_password'))

    def put(self, request, *args, **kwargs):
        validated_data = self.validate_data(request)
        if isinstance(validated_data, exceptions.ValidationError):
            return Response({'detail': validated_data.detail},
                            status=validated_data.status_code)

        user = self.get_object()
        if not user.check_password(validated_data['old_password']):
            raise exceptions.ValidationError('Current password is incorrect.')

        user.set_password(validated_data['new_password'])
        user.save()
        return Response(status=200)
Ejemplo n.º 6
0
 class Meta:
     model = ArtworkModel
     fields = ('id', 'description', 'tags', 'author')
     read_only_fields = ('id', )
     extra_kwargs = {
         'description': {
             'write_only': True
         },
         'tags': {
             'write_only': True
         },
         'author': {
             'write_only': True
         }
     }
     validators = [
         RequiredValidator(fields=('description', 'tags', 'author'))
     ]
Ejemplo n.º 7
0
class DeactivateSelfAPIView(APIView, UpdateUserModelMixin,
                            APIViewValidationMixin):
    validators = (RequiredValidator(fields=('password', )), )

    def put(self, request, *args, **kwargs):
        result = self.validate_data(request)
        if isinstance(result, exceptions.ValidationError):
            raise result

        validated_data = result
        user = self.get_object()
        if not user.check_password(validated_data['password']):
            raise exceptions.ValidationError('Password is incorrect.')

        if not user.is_active:
            raise exceptions.ValidationError('Account is already deactivated')

        user.is_active = False
        user.save()
        return Response(status=200)
Ejemplo n.º 8
0
class EditSelfEmailAPIView(APIView, UpdateUserModelMixin,
                           APIViewValidationMixin):
    validators = (RequiredValidator(fields=('email', 'password')), )

    def update(self, request, *args, **kwargs):
        validated_data = self.validate_data(request)
        if isinstance(validated_data, exceptions.ValidationError):
            return Response({'detail': validated_data.detail},
                            status=validated_data.status_code)

        instance = self.get_object()
        if not instance.check_password(validated_data['password']):
            raise exceptions.NotAuthenticated('Password is incorrect.')

        email = validated_data['email']
        try:
            validate_email(email)
        except ValidationError:
            raise exceptions.ValidationError('Email is not valid.')

        instance.email = email
        instance.save()
        return Response(data={'email': email}, status=200)
Ejemplo n.º 9
0
	class Meta:
		model = TagModel
		fields = ('text',)
		validators = [
			RequiredValidator(fields=('text',))
		]
Ejemplo n.º 10
0
 class Meta:
     model = CommentModel
     fields = ('mark', 'points')
     read_only_fields = ('points', )
     mark_range = [-1, 1]
     validators = [RequiredValidator(fields=('mark', ))]
Ejemplo n.º 11
0
 class Meta:
     model = CommentModel
     fields = ('text', )
     extra_kwargs = {'text': {'write_only': True}}
     validators = [RequiredValidator(fields=('text', ))]
Ejemplo n.º 12
0
 class Meta:
     model = ArtworkModel
     fields = ('mark', 'points', 'votes_count')
     read_only_fields = ('points', 'votes_count')
     mark_range = range(-10, 12)
     validators = [RequiredValidator(fields=('mark', ))]