2007/6/28, David Larlet <[EMAIL PROTECTED]>:
> 2007/6/26, David Larlet <[EMAIL PROTECTED]>:
> > 2007/6/22, Chris Brand <[EMAIL PROTECTED]>:
> > >
> > > > > I just wonder why this permission is not part of the default
> > > > > permissions (like add, change and delete)?
> > > > >
> > > > > David
> > > > >
> > > > No more thoughts about that? I'm really surprised that it only happens
> > > > to me, maybe I will be luckier on the users' mailing-list?
> > >
> > > Chapter 18 of the Django book 
> > > (http://www.djangobook.com/en/beta/chapter18/)
> > > says this :
> > > " For instance, although the admin is quite useful for reviewing data (see
> > > above), it's not designed with that purpose as a goal: note the lack of a
> > > "can view" permission (see Chapter 12). Django assumes that if people are
> > > allowed to view content in the admin, they're also allowed to edit it."
> >
> > You're absolutely right, I miss that page. Thanks for the reminder.
> >
>
> Eventually (for the record), if someone want to do the same without
> breaking his django installation, just drop this management.py in one
> of your app directory and syncdb.
>
Grrr, GMail didn't update attachments... try this more elegant version.

David

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

"""
Creates retrieve permissions for all installed apps that need permissions.
"""

from django.dispatch import dispatcher
from django.db.models import get_models, signals
from django.contrib.auth.management import _get_permission_codename

def create_retrieve_permissions(app, created_models, verbosity):
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.auth.models import Permission
    app_models = get_models(app)
    if not app_models:
        return
    for klass in app_models:
        ctype = ContentType.objects.get_for_model(klass)
        codename = _get_permission_codename('retrieve', klass._meta)
        name = 'Can %s %s' % ('retrieve', klass._meta.verbose_name)
        p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
            defaults={'name': name, 'content_type': ctype})
        if created and verbosity >= 2:
            print "Adding permission '%s'" % p

dispatcher.connect(create_retrieve_permissions, signal=signals.post_syncdb)

Reply via email to