Ticket #10686: permission_inheritance.diff

File permission_inheritance.diff, 2.7 KB (added by faldridge, 15 years ago)
  • django/db/models/base.py

     
    4343            meta = getattr(new_class, 'Meta', None)
    4444        else:
    4545            meta = attr_meta
     46            # Append any inherited permissions to any explicitly declared ones.
     47            if hasattr(meta, 'permissions') and getattr(meta, 'inherit_permissions', True):
     48                if hasattr(new_class, 'Meta') and hasattr(new_class.Meta, 'permissions'):
     49                    meta.permissions += new_class.Meta.permissions
    4650        base_meta = getattr(new_class, '_meta', None)
    4751
    4852        if getattr(meta, 'app_label', None) is None:
  • django/db/models/options.py

     
    2121DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
    2222                 'unique_together', 'permissions', 'get_latest_by',
    2323                 'order_with_respect_to', 'app_label', 'db_tablespace',
    24                  'abstract', 'managed', 'proxy')
     24                 'abstract', 'managed', 'proxy', 'inherit_permissions')
    2525
    2626class Options(object):
    2727    def __init__(self, meta, app_label=None):
     
    8686            if ut and not isinstance(ut[0], (tuple, list)):
    8787                ut = (ut,)
    8888            setattr(self, 'unique_together', ut)
     89           
     90            # check for the %(class)s escape used for inherited permissions.
     91            # If present, replace it with the appropriate text based off of
     92            # the class name for both the name and codename of the permission.
     93            perms = meta_attrs.pop('permissions', getattr(self, 'permissions'))
     94            translated_perms = ()
     95            if perms:
     96                for codename, name in perms:
     97                    codename = codename % {'class': cls.__name__.lower()}
     98                    name = name % {'class': getattr(self, 'verbose_name')}
     99                    translated_perms += ((codename, name),)
     100            setattr(self, 'permissions', translated_perms)
    89101
    90102            # verbose_name_plural is a special case because it uses a 's'
    91103            # by default.
  • AUTHORS

     
    2626    ajs <adi@sieker.info>
    2727    alang@bright-green.com
    2828    Marty Alchin <gulopine@gamemusic.org>
     29    Forrest Aldridge <forrest.aldridge@gmail.com>
    2930    Ahmad Alhashemi <trans@ahmadh.com>
    3031    Daniel Alves Barbosa de Oliveira Vaz <danielvaz@gmail.com>
    3132    AgarFu <heaven@croasanaso.sytes.net>
Back to Top