def has_perm_or_owns(user, perm, obj, perm_obj, field_name='creator'):
 if user.is_anonymous():
  return False
 if hasattr(obj, ('%s_id' % field_name)):
  if (getattr(obj, ('%s_id' % field_name)) == user.pk):
   return True
 elif (user == getattr(obj, field_name)):
  return True
 check = get_check(user, perm)
 return (user.has_perm(perm) or (check and check(perm_obj)))

def has_perm_or_owns ( user , perm , obj , perm_obj , field_name = 'creator' ) : if user . is_anonymous ( ) : return False if hasattr ( obj , ( '%s_id' % field_name ) ) : if ( getattr ( obj , ( '%s_id' % field_name ) ) == user . pk ) : return True elif ( user == getattr ( obj , field_name ) ) : return True check = get_check ( user , perm ) return ( user . has_perm ( perm ) or ( check and check ( perm_obj ) ) )
check if the user has a permission or owns the object .