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.
Double posting to two groups like this is _really_ bad form. On top of
this, the django-developers group is intended for discussion of the
internals of Django itself.
If you're asking a "How do I do this" questions, django-users is the
place to do it.
Yours
Russ Magee %-)
On May 31, 6:18 pm, "Russell Keith-Magee" <freakboy3...@gmail.com>
wrote:
I meant to CC this group when I posted to users.
It's both a *how do I do this?*, and a *if there isn't a way already,
how about we do it this one?* thingy, so I thought it'd be appropriate
for the two groups. I think that much is apparent.
Thanks for the netiquette lesson thou :)
-Facundo.
It's not. If you don't know how to do something, ask on django-users.
Proposing a solution for a problem is exceedingly premature when you
have already admitted that you don't know if a solution already
exists.
CC'ing the dev list is no better - your message is sent regardless of
how it is sent, and the group archive doesn't distinguish between To
and CC.
If, as a result of asking your original question, a design issue
arises, and needs internal discussion, _then_ start the second thread.
In many cases, the second thread won't even be required - all the
django-developers read django-users too, so quite often raising the
issue in the users list will get the problem addressed.
Sorry if this seems like I'm coming down hard on you personally - it's
not intended as a personal attack. We (the developers) need to keep a
hard line on issues like this or the value in having a low-volume
developer-only list evaporates.
Yours,
Russ Magee %-)