Ticket #10686: permission_inheritance.2.diff
File permission_inheritance.2.diff, 2.9 KB (added by , 13 years ago) |
---|
-
AUTHORS
540 540 Gasper Zejn <zejn@kiberpipa.org> 541 541 Jarek Zgoda <jarek.zgoda@gmail.com> 542 542 Cheng Zhang 543 Forrest Aldridge <forrest.aldridge@gmail.com> 543 544 544 545 A big THANK YOU goes to: 545 546 -
django/db/models/base.py
44 44 meta = getattr(new_class, 'Meta', None) 45 45 else: 46 46 meta = attr_meta 47 # Append any inherited permissions to any explicitly declared ones. 48 if hasattr(meta, 'permissions') and getattr(meta, 'inherit_permissions', True): 49 all_perms = set(meta.permissions) 50 for parent in parents: 51 if hasattr(parent, 'Meta') and hasattr(parent.Meta, 'permissions'): 52 # De-dupe inherited permission in case the Meta class also inherited from another Meta 53 all_perms.update(parent.Meta.permissions) 54 meta.permissions = list(all_perms) 47 55 base_meta = getattr(new_class, '_meta', None) 48 56 49 57 if getattr(meta, 'app_label', None) is None: -
django/db/models/options.py
17 17 DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering', 18 18 'unique_together', 'permissions', 'get_latest_by', 19 19 'order_with_respect_to', 'app_label', 'db_tablespace', 20 'abstract', 'managed', 'proxy', 'auto_created' )20 'abstract', 'managed', 'proxy', 'auto_created', 'inherit_permissions') 21 21 22 22 class Options(object): 23 23 def __init__(self, meta, app_label=None): … … 87 87 if ut and not isinstance(ut[0], (tuple, list)): 88 88 ut = (ut,) 89 89 self.unique_together = ut 90 91 # check for the %(class)s escape used for inherited permissions. 92 # If present, replace it with the appropriate text based off of 93 # the class name for both the name and codename of the permission. 94 perms = meta_attrs.pop('permissions', self.permissions) 95 translated_perms = [] 96 if perms: 97 for codename, name in perms: 98 codename = codename % {'class': cls.__name__.lower()} 99 name = name % {'class': self.verbose_name} 100 translated_perms.append((codename, name),) 101 self.permissions = translated_perms 90 102 91 103 # verbose_name_plural is a special case because it uses a 's' 92 104 # by default.