Ticket #10616: permissions-translations.diff

File permissions-translations.diff, 1.9 KB (added by Alex Gaynor, 16 years ago)
  • django/contrib/auth/management/__init__.py

    diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
    index 01fa524..6b237c7 100644
    a b Creates permissions for all installed apps that need permissions.  
    44
    55from django.db.models import get_models, signals
    66from django.contrib.auth import models as auth_app
     7from django.utils.encoding import force_unicode
    78
    89def _get_permission_codename(action, opts):
    910    return u'%s_%s' % (action, opts.object_name.lower())
    def create_permissions(app, created_models, verbosity, **kwargs):  
    2526        ctype = ContentType.objects.get_for_model(klass)
    2627        for codename, name in _get_all_permissions(klass._meta):
    2728            p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
    28                 defaults={'name': name, 'content_type': ctype})
     29                defaults={'name': force_unicode(name), 'content_type': ctype})
    2930            if created and verbosity >= 2:
    3031                print "Adding permission '%s'" % p
    3132
  • new file tests/regressiontests/auth_permissions/models.py

    diff --git a/tests/regressiontests/auth_permissions/__init__.py b/tests/regressiontests/auth_permissions/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/auth_permissions/models.py b/tests/regressiontests/auth_permissions/models.py
    new file mode 100644
    index 0000000..4c4e005
    - +  
     1from django.utils.translation import ugettext_lazy as _
     2from django.db import models
     3
     4class Citizen(models.Model):
     5    name = models.CharField(max_length=20)
     6
     7    class Meta:
     8        permissions = (
     9            ('vote', _("Can vote")),
     10        )
     11
     12__test__ = {'perms_tests': """
     13>>> from django.contrib.auth.models import Permission
     14>>> Permission.objects.filter(name="Can vote")
     15[<Permission: auth_permissions | citizen | Can vote>]
     16"""
     17}
Back to Top