diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index 6380d2f..d408d35 100644
a
|
b
|
import getpass
|
7 | 7 | import unicodedata |
8 | 8 | |
9 | 9 | from django.apps import apps |
| 10 | from django.conf import settings |
10 | 11 | from django.contrib.auth import get_permission_codename |
11 | 12 | from django.core import exceptions |
12 | 13 | from django.core.management.base import CommandError |
13 | 14 | from django.db import DEFAULT_DB_ALIAS, router |
14 | 15 | from django.utils import six |
15 | 16 | from django.utils.encoding import DEFAULT_LOCALE_ENCODING |
| 17 | from django.utils.translation import activate, get_language, ugettext as _ |
16 | 18 | |
17 | 19 | |
18 | 20 | def _get_all_permissions(opts, ctype): |
… |
… |
def _get_all_permissions(opts, ctype):
|
28 | 30 | def _get_builtin_permissions(opts): |
29 | 31 | """ |
30 | 32 | Returns (codename, name) for all autogenerated permissions. |
31 | | By default, this is ('add', 'change', 'delete') |
| 33 | By default, this is ('view', 'add', 'change', 'delete') |
32 | 34 | """ |
33 | 35 | perms = [] |
| 36 | trans = { |
| 37 | 'view': _('Can view %s'), |
| 38 | 'add': _('Can add %s'), |
| 39 | 'change': _('Can change %s'), |
| 40 | 'delete': _('Can delete %s'), |
| 41 | } |
34 | 42 | for action in opts.default_permissions: |
35 | 43 | perms.append((get_permission_codename(action, opts), |
36 | | 'Can %s %s' % (action, opts.verbose_name_raw))) |
| 44 | trans.get(action, 'Can '+action+' %s') % opts.verbose_name)) |
37 | 45 | return perms |
38 | 46 | |
39 | 47 | |
… |
… |
def create_permissions(app_config, verbosity=2, interactive=True, using=DEFAULT_
|
71 | 79 | |
72 | 80 | from django.contrib.contenttypes.models import ContentType |
73 | 81 | |
| 82 | # setup locale |
| 83 | lang = get_language() |
| 84 | try: |
| 85 | activate(settings.LANGUAGE_CODE) |
| 86 | except: |
| 87 | pass |
| 88 | |
| 89 | # For localized prefixes ('Can view ', 'Can add ', 'Can change ' |
| 90 | # and 'Can delete ') digit `30` - probably maximum the length of |
| 91 | # two words in all languages |
74 | 92 | permission_name_max_length = Permission._meta.get_field('name').max_length |
75 | | verbose_name_max_length = permission_name_max_length - 11 # len('Can change ') prefix |
| 93 | verbose_name_max_length = permission_name_max_length - 30 |
76 | 94 | |
77 | 95 | # This will hold the permissions we're looking for as |
78 | 96 | # (content_type, (codename, name)) |
… |
… |
def create_permissions(app_config, verbosity=2, interactive=True, using=DEFAULT_
|
128 | 146 | for perm in perms: |
129 | 147 | print("Adding permission '%s'" % perm) |
130 | 148 | |
| 149 | # revert locale |
| 150 | activate(lang) |
| 151 | |
| 152 | |
131 | 153 | |
132 | 154 | def get_system_username(): |
133 | 155 | """ |
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index ad46c5c..e028926 100644
a
|
b
|
class Permission(models.Model):
|
49 | 49 | list, view the "change" form and change an object. |
50 | 50 | - The "delete" permission limits the ability to delete an object. |
51 | 51 | |
| 52 | The "view" permission allows the user's to view the object without |
| 53 | the possibility of change. This permission not uses in Django admin. |
| 54 | |
52 | 55 | Permissions are set globally per type of object, not per specific object |
53 | 56 | instance. It is possible to say "Mary may change news stories," but it's |
54 | 57 | not currently possible to say "Mary may change news stories, but only the |
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 368ac62..3f1f3c5 100644
a
|
b
|
class Options(object):
|
106 | 106 | self.unique_together = [] |
107 | 107 | self.index_together = [] |
108 | 108 | self.select_on_save = False |
109 | | self.default_permissions = ('add', 'change', 'delete') |
| 109 | self.default_permissions = ('view', 'add', 'change', 'delete') |
110 | 110 | self.permissions = [] |
111 | 111 | self.object_name = None |
112 | 112 | self.app_label = app_label |
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index f45703f..40f50c9 100644
a
|
b
|
class PermissionTestCase(TestCase):
|
570 | 570 | ] |
571 | 571 | create_permissions(auth_app_config, verbosity=0) |
572 | 572 | |
573 | | # add/change/delete permission by default + custom permission |
| 573 | # view/add/change/delete permission by default + custom permission |
574 | 574 | self.assertEqual(models.Permission.objects.filter( |
575 | 575 | content_type=permission_content_type, |
576 | | ).count(), 4) |
| 576 | ).count(), 5) |
577 | 577 | |
578 | 578 | models.Permission.objects.filter(content_type=permission_content_type).delete() |
579 | 579 | models.Permission._meta.default_permissions = [] |
… |
… |
class PermissionTestCase(TestCase):
|
592 | 592 | models.Permission._meta.verbose_name = "some ridiculously long verbose name that is out of control" * 5 |
593 | 593 | |
594 | 594 | six.assertRaisesRegex(self, exceptions.ValidationError, |
595 | | "The verbose_name of auth.permission is longer than 244 characters", |
| 595 | "The verbose_name of auth.permission is longer than 225 characters", |
596 | 596 | create_permissions, auth_app_config, verbosity=0) |
597 | 597 | |
598 | 598 | def test_custom_permission_name_length(self): |