Google Groups Home
Help | Sign in
permissions in template
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
masuran  
View profile
 More options Mar 12 2007, 9:02 am
From: "masuran" <michael.ancka...@gmail.com>
Date: Mon, 12 Mar 2007 06:02:16 -0700
Local: Mon, Mar 12 2007 9:02 am
Subject: permissions in template
Hello everyone,

I've created a custom permission on one of my models and I've given a
user the custom permission.

When I go into the shell (manage.py shell), I can confirm that the
user has the custom permission. But when I use the perms object in one
of my templates, it simple doesn't work.

{% if perms.custom_perm %}
 do something
{% endif %}

According to the documentation, the perms object is included in the
template language. So I assume I don't have to create the object and
pass it to my template?
I've even tried the fix posted here http://code.djangoproject.com/ticket/2418
but to no avail. I still can't use the perms object in my template.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bgcooper  
View profile
 More options Mar 13 2007, 2:15 am
From: "bgcooper" <bgcoo...@gmail.com>
Date: Tue, 13 Mar 2007 06:15:26 -0000
Local: Tues, Mar 13 2007 2:15 am
Subject: Re: permissions in template
Funny that I should run into this post the same day that I'm trying to
work out how to do this.

I've got the same problem. From the shell:

>>> user = User.objects.get(id = 3)
>>> user.get_all_permissions()

Set(['ivms.can_play'])
>>> user.has_perm('ivms.can_play')

True

Fantastic. When I try and access it via my template it doesn't work.
e.g.

{% if perms.ivms.can_play %}
I have permissions
{% else %}
I don't have permissions
{% endif %}

Do I need to load any template tags to access this tag?

Note that I'm still using 0.95.

Thanks,
Ben

On Mar 13, 12:02 am, "masuran" <michael.ancka...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
masuran  
View profile
 More options Mar 13 2007, 8:53 am
From: "masuran" <michael.ancka...@gmail.com>
Date: Tue, 13 Mar 2007 12:53:47 -0000
Local: Tues, Mar 13 2007 8:53 am
Subject: Re: permissions in template
I'm going to download the development version and try that one out,
might do the trick :)

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bgcooper  
View profile
 More options Mar 14 2007, 12:46 am
From: "bgcooper" <bgcoo...@gmail.com>
Date: Wed, 14 Mar 2007 04:46:54 -0000
Local: Wed, Mar 14 2007 12:46 am
Subject: Re: permissions in template
Ahh, the authentication documentation (http://www.djangoproject.com/
documentation/authentication/) mentions that you need use
RequestContext to get user and perms in your template. We were simply
passing request.user into our template to get user information.

Here's how you do it. In your view

from django.template import RequestContext
return render_to_response("mytemplate.html",
context_instance=RequestContext(request))

Works for me!

On Mar 13, 11:53 pm, "masuran" <michael.ancka...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google