I added a method to threadlocals.py that allows me to set the user so
I can run code in the shell that depends on get_current_user()
returning a user:

def set_current_user(user):
    _thread_locals.user = user

This should work for you.


On Mar 6, 3:35 am, "Aidas Bendoraitis" <[EMAIL PROTECTED]>
wrote:
> Can't help you much with this, but according to the docs
> (http://www.djangoproject.com/documentation/authentication/#methods),
> "is_authenticated() -- Always returns True" for User model and it
> returns False for AnonymousUser model.
>
> Regards,
> Aidas Bendoraitis [aka Archatas]
>
> On 3/6/07, sandro.dentella <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi all,
>
> >   How can I authenticate in a shell? I'm playing with Managers to meke
> > them behave different according to the permission of the user, but I
> > don't know how to play with the shell as authenticated user.
>
> > Really what happens is that if I test a user that results
> > authenticated and I dont' understand why:
>
> > from django.utils._threading_local import local
> > from django.contrib.auth.models import User
> > u = User.objects.filter(username='sandro')[0]
> > print "user %s is authenticated: %s" % (u,u.is_authenticated())
> > >>> user sandro is authenticated: True
>
> > On the other side inside the manager  I use middleware trick
> >http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUserto get
> > the user: it works perfectly from the browser but fails to get the
> > user from the shell even if I write:
>
> > _thread_locals = local()
> > _thread_locals.user = u
>
> > Any hint to understand this behaviour?
>
> > Thanks
> > sandro
> > *:-)


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to