Re: user and perms context variables from auth context processor (in Django 1.2.3)

2011-04-30 Thread Karen Tracey
On Fri, Apr 29, 2011 at 9:22 AM, simon  wrote:

>
> I am using Django 1.2.3. I was trying to check user permissions on a
> certain model using the perms context variable from
> contrib.auth.context_processors.auth. As per the documentation, I
> tried this (foo is the app label, Bar is the model, and I'm using
> default permissions):
>
> {% if perms.foo.change_bar %} do stuff {% endif %}
>
> It's always false even when logged in as a superuser. I tried doing
> {{user.username}} to see if the user variable worked and it also
> displayed nothing. So I checked in the debug toolbar and the variables
> I get from the auth context processor are these:
>
> {'messages':
>  object at 0xa38284c>,
>  'perms': ,
>  'user':  0xa31748c>}


Is your view using a RequestContext to render the response? If not, that
would explain why user does not appear to be set in your context. In order
for context processors to affect your template's context, you must use a
RequestContext for rendering. Context processors are not run for templates
rendered with a regular Context.

Note the debug toolbar displaying the context processor and the variables it
would set for the response don't imply that those variables were actually
set in the context used to render the response: debug toolbar shows this
information for all responses, regardless of whether a RequestContext was
used to render the response.

Karen
-- 
http://tracey.org/kmt/

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



user and perms context variables from auth context processor (in Django 1.2.3)

2011-04-29 Thread simon
Hello,

I am using Django 1.2.3. I was trying to check user permissions on a
certain model using the perms context variable from
contrib.auth.context_processors.auth. As per the documentation, I
tried this (foo is the app label, Bar is the model, and I'm using
default permissions):

{% if perms.foo.change_bar %} do stuff {% endif %}

It's always false even when logged in as a superuser. I tried doing
{{user.username}} to see if the user variable worked and it also
displayed nothing. So I checked in the debug toolbar and the variables
I get from the auth context processor are these:

{'messages':
,
 'perms': ,
 'user': }

My questions are:
1) wasn't the SimpleLazyObject for user not fixed as claimed by ticket
12060 ( http://code.djangoproject.com/ticket/12060 ) ? Or was it fixed
after 1.2.3?
2) How do I go about checking permissions using the perms variable? It
seemed to be wrapped in some other function.

Please help.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.