Ticket #9057: 9057.diff

File 9057.diff, 3.7 KB (added by Koen Biermans, 13 years ago)

patch with no_default_permission meta option

  • tests/regressiontests/auth_permissions/tests.py

     
     1from django.utils import unittest
     2
     3from django.contrib.auth.models import Permission
     4from django.contrib.contenttypes.models import ContentType
     5
     6class 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

     
     1from django.db import models
     2
     3class Poll(models.Model):
     4    question = models.CharField(max_length=200)
     5    pub_date = models.DateTimeField('date published')
     6
     7class 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

     
    1515get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()
    1616
    1717DEFAULT_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')
    2121
    2222class Options(object):
    2323    def __init__(self, meta, app_label=None):
     
    2828        self.db_table = ''
    2929        self.ordering = []
    3030        self.unique_together =  []
     31        self.no_default_permissions = False
    3132        self.permissions =  []
    3233        self.object_name, self.app_label = None, app_label
    3334        self.get_latest_by = None
  • django/contrib/auth/management/__init__.py

     
    1616def _get_all_permissions(opts):
    1717    "Returns (codename, name) for all permissions in the given opts."
    1818    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)))
    2122    return perms + list(opts.permissions)
    2223
    2324
Back to Top