Commits

schacki  committed 1763cc2

Changed wording and doctype of the register_permission util, to reflect the fact that it expects Django Model Classes and not Content Types as parameters

  • Participants
  • Parent commits 9ee661a

Comments (0)

Files changed (2)

File permissions/models.py

     @receiver(pre_delete,sender=Permission)
     def remove_object_permission_checker_delete(sender,**kwargs):
         instance=kwargs['instance']
-        print 'delete'
         for content_type in instance.content_types.all():
             model=content_type.model_class()    
             name=OBJECTS_PERM_STRING %instance.codename

File permissions/utils.py

 
 # Registering ################################################################
 
-def register_permission(name, codename, ctypes=None):
+def register_permission(name, codename, model_cls=None):
     """Registers a permission to the framework. Returns the permission if the
     registration was successfully, otherwise False.
 
         The unique codename of the permission. This is used internally to
         identify the permission.
 
-    content_types
-        The content type for which the permission is active. This can be
+    model_cls
+        The model classes for which the permission is active. This can be
         used to display only reasonable permissions for an object. This
-        must be a Django ContentType
+        must be a Django Model
     """
 
     # Permission with same codename and/or name must not exist.
     if Permission.objects.filter(Q(name=name) | Q(codename=codename)):
         return False
 
-    if ctypes is None:
-        ctypes = []
-    elif issubclass(ctypes,Model):
-        ctypes=[ctypes]
+    if model_cls is None:
+        model_cls = []
+    elif issubclass(model_cls,Model):
+        model_cls=[model_cls]
 
     p = Permission.objects.create(name=name, codename=codename)
-    ctypes = [ContentType.objects.get_for_model(ctype) for ctype in ctypes]
+    ctypes = [ContentType.objects.get_for_model(mcls) for mcls in model_cls]
     if ctypes:
         p.content_types = ctypes
         p.save()