Checking Permission Template Tag

8 views
Skip to first unread message

Chris Long

unread,
Aug 14, 2006, 8:14:11 PM8/14/06
to Django developers
Hi,

Joseph and I were talking earlier this evening about how to replace the
permission wrapper context to allow for his generic auth and my row
level permission. We could not determine a way to expand the current
context processor to allow an object to be passed (if you have any
ideas, please let us know).

So what I have done is create a template tag to check for permissions.
It is basically an if statement focused on permissions.

The syntax is
{% load auth %}
{% if_has_perm [not] (permission_codename) [object] %}
....
{% end_if_has_perm %}

The params in square brackets are optional, you do need to pass on the
permission codename. Right now, the permission codename has to be in
the format that is accepted by user.has_perm (which is
app_label.codename). It can also have an {% else %} tag imbetween the
start and end. I did not implement any AND or OR into it, I think it
would be too busy if they were put in. The user is assumed to be the
current user

Any thoughts on this? Do you think this is an ideal way of checking for
permissions? Or do you know a method we can use to pass the object to
the perm wrapper?

Thanks,

Chris

PS: To see the actual code, check revision 3589 in
per-object-permission branch.

Reply all
Reply to author
Forward
0 new messages