After reading the docs and looking for posts relating this problem
here and in .users, I found no "standard" way of checking for a
user's group permissions in the templates.

So what I did is to add the following method to auth.models.User
(yeah, yeah, it *should* be in appname.models.UserProfile):

def group_permissions(self):
    class GroupPermissions:
        def __init__(self, permissions):
            for perm in permissions:
                setattr(self, perm, True)

        def __str__(self):
            return 'The user belongs to the following groups: %s' % \
                ', '.join([k for k, v in self.__dict__.iteritems()])

    return GroupPermissions(self.get_group_permissions())

which lets me write something like the following in my templates:
{% if user.group_permissions.permission_name %} draw custom menues for
this particular group here {% endif %}

So, is there already a way to do this and I missed it? If not, given
that it is apparently not advisable (is it?) to extend the
auth.models.User class, how about we add it?

-Facundo.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to