Loading AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -463,6 +463,7 @@ answer newbie questions, and generally made Django that much better: Neal Norwitz <nnorwitz@google.com> Todd O'Bryan <toddobryan@mac.com> Alex Ogier <alex.ogier@gmail.com> Joao Oliveira <joaoxsouls@gmail.com> Selwin Ong <selwin@ui.co.id> Gerardo Orozco <gerardo.orozco.mosqueda@gmail.com> Christian Oudard <christian.oudard@gmail.com> Loading django/contrib/auth/management/__init__.py +6 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,12 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kw for ctype, (codename, name) in searched_perms if (ctype.pk, codename) not in all_perms ] # Validate the permissions before bulk_creation to avoid cryptic # database error when the verbose_name is longer than 50 characters for perm in perms: if len(perm.name) > 50: raise exceptions.ValidationError( "The verbose_name of %s is longer than 39 characters" % perm.content_type) auth_app.Permission.objects.using(db).bulk_create(perms) if verbosity >= 2: for perm in perms: Loading django/contrib/auth/tests/test_management.py +12 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ from django.contrib.auth.models import User from django.contrib.auth.tests.custom_user import CustomUser from django.contrib.auth.tests.utils import skipIfCustomUser from django.contrib.contenttypes.models import ContentType from django.core import exceptions from django.core.management import call_command from django.core.management.base import CommandError from django.core.management.validation import get_validation_errors Loading Loading @@ -201,10 +202,12 @@ class PermissionTestCase(TestCase): def setUp(self): self._original_permissions = models.Permission._meta.permissions[:] self._original_default_permissions = models.Permission._meta.default_permissions self._original_verbose_name = models.Permission._meta.verbose_name def tearDown(self): models.Permission._meta.permissions = self._original_permissions models.Permission._meta.default_permissions = self._original_default_permissions models.Permission._meta.verbose_name = self._original_verbose_name ContentType.objects.clear_cache() def test_duplicated_permissions(self): Loading Loading @@ -258,3 +261,12 @@ class PermissionTestCase(TestCase): self.assertEqual(models.Permission.objects.filter( content_type=permission_content_type, ).count(), 1) def test_verbose_name_length(self): permission_content_type = ContentType.objects.get_by_natural_key('auth', 'permission') models.Permission.objects.filter(content_type=permission_content_type).delete() models.Permission._meta.verbose_name = "some ridiculously long verbose name that is out of control" six.assertRaisesRegex(self, exceptions.ValidationError, "The verbose_name of permission is longer than 39 characters", create_permissions, models, [], verbosity=0) Loading
AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -463,6 +463,7 @@ answer newbie questions, and generally made Django that much better: Neal Norwitz <nnorwitz@google.com> Todd O'Bryan <toddobryan@mac.com> Alex Ogier <alex.ogier@gmail.com> Joao Oliveira <joaoxsouls@gmail.com> Selwin Ong <selwin@ui.co.id> Gerardo Orozco <gerardo.orozco.mosqueda@gmail.com> Christian Oudard <christian.oudard@gmail.com> Loading
django/contrib/auth/management/__init__.py +6 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,12 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kw for ctype, (codename, name) in searched_perms if (ctype.pk, codename) not in all_perms ] # Validate the permissions before bulk_creation to avoid cryptic # database error when the verbose_name is longer than 50 characters for perm in perms: if len(perm.name) > 50: raise exceptions.ValidationError( "The verbose_name of %s is longer than 39 characters" % perm.content_type) auth_app.Permission.objects.using(db).bulk_create(perms) if verbosity >= 2: for perm in perms: Loading
django/contrib/auth/tests/test_management.py +12 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ from django.contrib.auth.models import User from django.contrib.auth.tests.custom_user import CustomUser from django.contrib.auth.tests.utils import skipIfCustomUser from django.contrib.contenttypes.models import ContentType from django.core import exceptions from django.core.management import call_command from django.core.management.base import CommandError from django.core.management.validation import get_validation_errors Loading Loading @@ -201,10 +202,12 @@ class PermissionTestCase(TestCase): def setUp(self): self._original_permissions = models.Permission._meta.permissions[:] self._original_default_permissions = models.Permission._meta.default_permissions self._original_verbose_name = models.Permission._meta.verbose_name def tearDown(self): models.Permission._meta.permissions = self._original_permissions models.Permission._meta.default_permissions = self._original_default_permissions models.Permission._meta.verbose_name = self._original_verbose_name ContentType.objects.clear_cache() def test_duplicated_permissions(self): Loading Loading @@ -258,3 +261,12 @@ class PermissionTestCase(TestCase): self.assertEqual(models.Permission.objects.filter( content_type=permission_content_type, ).count(), 1) def test_verbose_name_length(self): permission_content_type = ContentType.objects.get_by_natural_key('auth', 'permission') models.Permission.objects.filter(content_type=permission_content_type).delete() models.Permission._meta.verbose_name = "some ridiculously long verbose name that is out of control" six.assertRaisesRegex(self, exceptions.ValidationError, "The verbose_name of permission is longer than 39 characters", create_permissions, models, [], verbosity=0)