diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 0717acaab..eff20805f 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -894,6 +894,7 @@ class AlphabeticFieldValidator: if not re.match(r'^[A-Za-z ]*$', value): raise ValueError("This field must contain only alphabetic characters and spaces.") + class AlphanumericFieldValidator: """ Custom validator to ensure the field contains only alphanumeric characters (letters and numbers). @@ -906,6 +907,7 @@ class AlphanumericFieldValidator: if not re.match(r'^[A-Za-z0-9]*$', value): raise ValueError("This field must contain only alphanumeric characters (letters and numbers).") + class CustomLengthValidator: """ Custom validator to ensure the length of a string is within specified limits. diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py index 3c0de3d67..9c9211d8f 100644 --- a/rest_framework/permissions.py +++ b/rest_framework/permissions.py @@ -172,6 +172,7 @@ class IsAuthenticatedOrReadOnly(BasePermission): request.user.is_authenticated ) + class IsAdminUserOrReadOnly(BasePermission): """ Custom permission to only allow admin users to edit an object. diff --git a/tests/models.py b/tests/models.py index 1c5d58c1d..90be1d7b6 100644 --- a/tests/models.py +++ b/tests/models.py @@ -157,4 +157,4 @@ class OwnershipTestModel(models.Model): title = models.CharField(max_length=100) def __str__(self): - return self.title \ No newline at end of file + return self.title diff --git a/tests/test_fields.py b/tests/test_fields.py index 089772b8a..a278015a2 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1141,6 +1141,7 @@ class TestAlphanumericField: validator(value) assert str(excinfo.value) == "This field must be a string." + class TestCustomLengthField: """ Valid and invalid values for `CustomLengthValidator`. diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 417dbd3c8..e1b17d0ac 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -819,4 +819,4 @@ class PermissionTests(TestCase): self.assertTrue(permission.has_object_permission(request, None, obj)) request.user = self.admin_user - self.assertTrue(permission.has_object_permission(request, None, obj)) \ No newline at end of file + self.assertTrue(permission.has_object_permission(request, None, obj)) diff --git a/tests/test_status.py b/tests/test_status.py index 7fbe1b522..4d7aeb90a 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -1,8 +1,7 @@ from django.test import TestCase from rest_framework.status import ( - is_client_error, is_informational, is_redirect, is_server_error, - is_success + is_client_error, is_informational, is_redirect, is_server_error, is_success ) diff --git a/tests/test_validators.py b/tests/test_validators.py index 5ea0542c4..4bb8658d5 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -10,8 +10,7 @@ from django.test import TestCase from rest_framework import serializers from rest_framework.exceptions import ValidationError from rest_framework.validators import ( - BaseUniqueForValidator, UniqueTogetherValidator, UniqueValidator, - qs_exists + BaseUniqueForValidator, UniqueTogetherValidator, UniqueValidator, qs_exists )