Ticket #9057: 9057.diff
File 9057.diff, 3.7 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/auth_permissions/tests.py
1 from django.utils import unittest 2 3 from django.contrib.auth.models import Permission 4 from django.contrib.contenttypes.models import ContentType 5 6 class AuthPermissionsTest(unittest.TestCase): 7 8 def test_permissions(self): 9 self.assertEqual(Permission.objects.filter(content_type= 10 ContentType.objects.get_by_natural_key('auth_permissions', 'poll') 11 ).count(), 3) 12 self.assertEqual(Permission.objects.filter(content_type= 13 ContentType.objects.get_by_natural_key('auth_permissions', 'choice') 14 ).count(), 1) 15 -
tests/regressiontests/auth_permissions/models.py
1 from django.db import models 2 3 class Poll(models.Model): 4 question = models.CharField(max_length=200) 5 pub_date = models.DateTimeField('date published') 6 7 class Choice(models.Model): 8 poll = models.ForeignKey(Poll) 9 choice = models.CharField(max_length=200) 10 votes = models.IntegerField() 11 12 class Meta: 13 no_default_permissions = True 14 permissions = ( 15 ("display_choices", "May display choices"), 16 ) 17 -
django/db/models/options.py
15 15 get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip() 16 16 17 17 DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering', 18 'unique_together', ' permissions', 'get_latest_by',19 ' order_with_respect_to', 'app_label', 'db_tablespace',20 ' abstract', 'managed', 'proxy', 'auto_created')18 'unique_together', 'no_default_permissions', 'permissions', 19 'get_latest_by', 'order_with_respect_to', 'app_label', 20 'db_tablespace', 'abstract', 'managed', 'proxy', 'auto_created') 21 21 22 22 class Options(object): 23 23 def __init__(self, meta, app_label=None): … … 28 28 self.db_table = '' 29 29 self.ordering = [] 30 30 self.unique_together = [] 31 self.no_default_permissions = False 31 32 self.permissions = [] 32 33 self.object_name, self.app_label = None, app_label 33 34 self.get_latest_by = None -
django/contrib/auth/management/__init__.py
16 16 def _get_all_permissions(opts): 17 17 "Returns (codename, name) for all permissions in the given opts." 18 18 perms = [] 19 for action in ('add', 'change', 'delete'): 20 perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw))) 19 if not opts.no_default_permissions: 20 for action in ('add', 'change', 'delete'): 21 perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw))) 21 22 return perms + list(opts.permissions) 22 23 23 24