Hello again

I am coming back to my permission/moderation problem.
I finally understood the trick with super, and I am starting to have an 
idea about how to modify the queryset method.
There is another matter, though. I began to create a permission_app to 
create my moderation permission, in that app I created a directory called 
"management" in which I wrote a __init__.py fil containing this :
from django.db.models.signals import post_syncdb
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission

def add_moderation_permissions(sender, **kwargs):
    """
    This syncdb hooks takes care of adding a moderation permission too all 
our
    content types.
    """
    # for each of our content types
    for content_type in ContentType.objects.all():
        # build our permission slug
        codename = "moderation_%s" % content_type.model
        # if it doesn't exist..
        if not Permission.objects.filter(content_type=content_type, codename
=codename):
            # add it
            Permission.objects.create(content_type=content_type,
                    codename=codename,
                    name="Can moderation %s" % content_type.name)
            print "Added moderation permission for %s" % content_type.name
# check for all our moderation permissions after a syncdb
post_syncdb.connect(add_moderation_permissions)
It seems to have correctly added the permission, but only for the 
django_comments. I get that it's because it is the only ContentType, but 
the trick is that when I try to adapt the code for Page or BasePage, it 
doesn't work. I have a (completely normal) error that is raised : 
ValueError: Cannot query "Blog": Must be "ContentType" instance.
(and it says "blog" only because it is the first model that is tried, but 
it must be the same for all the models).
I looked at the django/contrib/auth/models.py file to understand the type 
of Permission and Permission.objects, and it seems like everything was 
written to "be contenttypes". I also looked at the Displayable, BasePage 
and Page types of mezzanine and it doesn't seem to inherit from ContentType 
in anyway... Besides, I would also want all of the objects I create in apps 
(I mean objects that inherit directly from models.Model) to recognise that 
permission.

So, how could I "cleanly" add my moderation permission for all the models 
that are in the apps I declared in INSTALLED_APPS and that can be editable 
in the admin interface, and not just content types ?

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to