@@ -62,13 +62,13 @@ def add_local_role(obj, principal, role):
6262 ctype = ContentType .objects .get_for_model (obj )
6363 if isinstance (principal , User ):
6464 try :
65- ppr = PrincipalRoleRelation .objects .get (user = principal , role = role , content_id = obj .id , content_type = ctype )
65+ ppr = PrincipalRoleRelation .objects .get (user = principal , role = role , content_id = obj .pk , content_type = ctype )
6666 except PrincipalRoleRelation .DoesNotExist :
6767 PrincipalRoleRelation .objects .create (user = principal , role = role , content = obj )
6868 return True
6969 else :
7070 try :
71- ppr = PrincipalRoleRelation .objects .get (group = principal , role = role , content_id = obj .id , content_type = ctype )
71+ ppr = PrincipalRoleRelation .objects .get (group = principal , role = role , content_id = obj .pk , content_type = ctype )
7272 except PrincipalRoleRelation .DoesNotExist :
7373 PrincipalRoleRelation .objects .create (group = principal , role = role , content = obj )
7474 return True
@@ -120,10 +120,10 @@ def remove_local_role(obj, principal, role):
120120
121121 if isinstance (principal , User ):
122122 ppr = PrincipalRoleRelation .objects .get (
123- user = principal , role = role , content_id = obj .id , content_type = ctype )
123+ user = principal , role = role , content_id = obj .pk , content_type = ctype )
124124 else :
125125 ppr = PrincipalRoleRelation .objects .get (
126- group = principal , role = role , content_id = obj .id , content_type = ctype )
126+ group = principal , role = role , content_id = obj .pk , content_type = ctype )
127127
128128 except PrincipalRoleRelation .DoesNotExist :
129129 return False
@@ -169,10 +169,10 @@ def remove_local_roles(obj, principal):
169169
170170 if isinstance (principal , User ):
171171 ppr = PrincipalRoleRelation .objects .filter (
172- user = principal , content_id = obj .id , content_type = ctype )
172+ user = principal , content_id = obj .pk , content_type = ctype )
173173 else :
174174 ppr = PrincipalRoleRelation .objects .filter (
175- group = principal , content_id = obj .id , content_type = ctype )
175+ group = principal , content_id = obj .pk , content_type = ctype )
176176
177177 if ppr :
178178 ppr .delete ()
@@ -222,7 +222,7 @@ def get_roles(user, obj=None):
222222 FROM permissions_principalrolerelation
223223 WHERE (user_id='%s' OR group_id IN (%s))
224224 AND content_id='%s'
225- AND content_type_id='%s'""" % (user .id , groups_ids_str , obj .id , ctype .id ))
225+ AND content_type_id='%s'""" % (user .id , groups_ids_str , obj .pk , ctype .id ))
226226
227227 for row in cursor .fetchall ():
228228 roles .append (row [0 ])
@@ -253,10 +253,10 @@ def get_local_roles(obj, principal):
253253
254254 if isinstance (principal , User ):
255255 return [prr .role for prr in PrincipalRoleRelation .objects .filter (
256- user = principal , content_id = obj .id , content_type = ctype )]
256+ user = principal , content_id = obj .pk , content_type = ctype )]
257257 else :
258258 return [prr .role for prr in PrincipalRoleRelation .objects .filter (
259- group = principal , content_id = obj .id , content_type = ctype )]
259+ group = principal , content_id = obj .pk , content_type = ctype )]
260260
261261# Permissions ################################################################
262262
@@ -306,7 +306,7 @@ def grant_permission(obj, role, permission):
306306
307307 ct = ContentType .objects .get_for_model (obj )
308308 try :
309- ObjectPermission .objects .get (role = role , content_type = ct , content_id = obj .id , permission = permission )
309+ ObjectPermission .objects .get (role = role , content_type = ct , content_id = obj .pk , permission = permission )
310310 except ObjectPermission .DoesNotExist :
311311 ObjectPermission .objects .create (role = role , content = obj , permission = permission )
312312
@@ -337,7 +337,7 @@ def remove_permission(obj, role, permission):
337337 ct = ContentType .objects .get_for_model (obj )
338338
339339 try :
340- op = ObjectPermission .objects .get (role = role , content_type = ct , content_id = obj .id , permission = permission )
340+ op = ObjectPermission .objects .get (role = role , content_type = ct , content_id = obj .pk , permission = permission )
341341 except ObjectPermission .DoesNotExist :
342342 return False
343343
@@ -362,7 +362,7 @@ def has_permission(obj, user, codename, roles=None):
362362 If given these roles will be assigned to the user temporarily before
363363 the permissions are checked.
364364 """
365- cache_key = "%s-%s-%s" % (obj .content_type , obj .id , codename )
365+ cache_key = "%s-%s-%s" % (obj .content_type , obj .pk , codename )
366366 result = _get_cached_permission (user , cache_key )
367367 if result is not None :
368368 return result
@@ -381,7 +381,7 @@ def has_permission(obj, user, codename, roles=None):
381381 result = False
382382 while obj is not None :
383383 p = ObjectPermission .objects .filter (
384- content_type = ct , content_id = obj .id , role__in = roles , permission__codename = codename ).values ("id" )
384+ content_type = ct , content_id = obj .pk , role__in = roles , permission__codename = codename ).values ("id" )
385385
386386 if len (p ) > 0 :
387387 result = True
@@ -422,7 +422,7 @@ def add_inheritance_block(obj, permission):
422422
423423 ct = ContentType .objects .get_for_model (obj )
424424 try :
425- ObjectPermissionInheritanceBlock .objects .get (content_type = ct , content_id = obj .id , permission = permission )
425+ ObjectPermissionInheritanceBlock .objects .get (content_type = ct , content_id = obj .pk , permission = permission )
426426 except ObjectPermissionInheritanceBlock .DoesNotExist :
427427 try :
428428 result = ObjectPermissionInheritanceBlock .objects .create (content = obj , permission = permission )
@@ -451,7 +451,7 @@ def remove_inheritance_block(obj, permission):
451451
452452 ct = ContentType .objects .get_for_model (obj )
453453 try :
454- opi = ObjectPermissionInheritanceBlock .objects .get (content_type = ct , content_id = obj .id , permission = permission )
454+ opi = ObjectPermissionInheritanceBlock .objects .get (content_type = ct , content_id = obj .pk , permission = permission )
455455 except ObjectPermissionInheritanceBlock .DoesNotExist :
456456 return False
457457
@@ -473,7 +473,7 @@ def is_inherited(obj, codename):
473473 ct = ContentType .objects .get_for_model (obj )
474474 try :
475475 ObjectPermissionInheritanceBlock .objects .get (
476- content_type = ct , content_id = obj .id , permission__codename = codename )
476+ content_type = ct , content_id = obj .pk , permission__codename = codename )
477477 except ObjectDoesNotExist :
478478 return True
479479 else :
@@ -515,8 +515,8 @@ def reset(obj):
515515 """Resets all permissions and inheritance blocks of passed object.
516516 """
517517 ctype = ContentType .objects .get_for_model (obj )
518- ObjectPermissionInheritanceBlock .objects .filter (content_id = obj .id , content_type = ctype ).delete ()
519- ObjectPermission .objects .filter (content_id = obj .id , content_type = ctype ).delete ()
518+ ObjectPermissionInheritanceBlock .objects .filter (content_id = obj .pk , content_type = ctype ).delete ()
519+ ObjectPermission .objects .filter (content_id = obj .pk , content_type = ctype ).delete ()
520520
521521# Registering ################################################################
522522
@@ -662,4 +662,4 @@ def _get_cached_permission(user, cache_key):
662662 """
663663 permissions = getattr (user , "permissions" , None )
664664 if permissions :
665- return user .permissions .get (cache_key , None )
665+ return user .permissions .get (cache_key , None )
0 commit comments