The code is what Anthony posted, and the traceback is simply:

Traceback:
File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/handlers/base.py"
in get_response
  89.                     response = middleware_method(request)
File "/usr/local/motor/motor/../motor/middleware.py" in process_request
  29.             backend = get_backends()[0]

Exception Type: NameError at /report/CDSEM/RawFile/
Exception Value: global name 'get_backends' is not defined


And I was under the impression that his middleware code would
eliminate the need to disable all login_required decorators, etc.


On Wed, Sep 5, 2012 at 1:48 PM, Amyth Arora <aroras.offic...@gmail.com> wrote:
> could you post the traceback and the respective code. Most probably you'll
> need to disable all login_required decorators and also disable your user
> login based template tags in all the templates for it to work properly.
>
>
> On Wed, Sep 5, 2012 at 10:36 PM, Larry Martell <larry.mart...@gmail.com>
> wrote:
>>
>> Thanks - but now I'm getting
>>
>> NameError: "global name 'get_backends' is not defined"
>>
>>
>> On Wed, Sep 5, 2012 at 12:59 PM, Kurtis Mullins
>> <kurtis.mull...@gmail.com> wrote:
>> > Looks like you just need a quick:
>> >
>> > from django.contrib.auth.models import User
>> >
>> > towards the top :)
>> >
>> >
>> > On Wed, Sep 5, 2012 at 12:57 PM, Larry Martell <larry.mart...@gmail.com>
>> > wrote:
>> >>
>> >> On Wed, Sep 5, 2012 at 12:21 PM, anthony tresontani
>> >> <dev.tresont...@gmail.com> wrote:
>> >> > We are using a middleware to enforce a user login:
>> >> >
>> >> > class AutoAuthMiddleware(object):
>> >> >     """
>> >> >         Middleware for testing purpose only.
>> >> >         Can enforce the user login.
>> >> >     """
>> >> >
>> >> >     def process_request(self, request):
>> >> >         enforce_user = request.GET.get("enforce_user", None)
>> >> >         if hasattr(request, "user") and not enforce_user:
>> >> >             return
>> >> >
>> >> >         user = User.objects.filter(username = enforce_user)
>> >>
>> >>
>> >> I'm getting: 'NameError: "global name 'User' is not defined"' on the
>> >> above line. This is the same issue I was running into when I was
>> >> trying to hard code the initialization of a request.user object. Where
>> >> is that defined?
>> >>
>> >>
>> >> >         if user:
>> >> >             backend = get_backends()[0]
>> >> >             user = user[0]
>> >> >             user.backend = "%s.%s" % (backend.__module__,
>> >> > backend.__class__.__name__) #fake authentication
>> >> >             login(request, user)
>> >> >
>> >> > You can add that to your testing environnement MIDDLEWARE_CLASSES.
>> >> >
>> >> > Then you can just go to any url and add ?enforce_user=<username>
>> >> >
>> >> >
>> >> >
>> >> > On 05/09/12 17:56, Larry Martell wrote:
>> >> >
>> >> > On Wed, Sep 5, 2012 at 9:36 AM, Kurtis Mullins
>> >> > <kurtis.mull...@gmail.com>
>> >> > wrote:
>> >> >
>> >> > I don't see why not.
>> >> >
>> >> > I've been trying to do that, but it's still complaining.
>> >> >
>> >> > Are you running unit tests (testing scripts) or are you
>> >> > just using the browser for testing?
>> >> >
>> >> > I'm trying to do performance measuring. I have a list of all the urls
>> >> > accessed over the past few months by a client, along with metrics on
>> >> > their execution times. I want to run all those on a new server we've
>> >> > set up and collect metrics and compare them. I have a python script
>> >> > that uses urllib2 but, I can't run anything without logging in. I've
>> >> > tried to login from python, but I get a 403. I also tried using the
>> >> > requests module - that doesn't give me the 403, but doesn't log me in
>> >> > - it just returns the login page as if the login failed.
>> >> >
>> >> > On Wed, Sep 5, 2012 at 11:24 AM, Larry Martell
>> >> > <larry.mart...@gmail.com>
>> >> > wrote:
>> >> >
>> >> > On Wed, Sep 5, 2012 at 9:22 AM, Kurtis Mullins
>> >> > <kurtis.mull...@gmail.com>
>> >> > wrote:
>> >> >
>> >> > If any of your templates/views depend upon a request.user object,
>> >> > you'll
>> >> > run
>> >> > into issues because that will not exist without "logging in". I'm not
>> >> > sure
>> >> > of a good way around this off-hand without knowing more about your
>> >> > site.
>> >> > Sorry!
>> >> >
>> >> > Yes, they do depend on a request.user object. Can I hard code the
>> >> > initialization of it?
>> >> >
>> >> > On Wed, Sep 5, 2012 at 11:18 AM, Larry Martell
>> >> > <larry.mart...@gmail.com>
>> >> > wrote:
>> >> >
>> >> > We have a django app that requires the users to login. For some
>> >> > testing we want to do, we want to disable this so the app can be run
>> >> > without logging in. Is there some way to easily do this? I've tried
>> >> > commenting out all the @login_required decorations, but then I was
>> >> > getting a 403. I tried commenting out the 'if not
>> >> > controller.has_access' lines, but then I was getting 'Report.owner"
>> >> > must be a "User" instance.' Before I hack up the code any more, is
>> >> > there some way to just globally disable the need to login?
>> >> >
>> >> > --
>> >> > 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.
>> >> >
>> >> > --
>> >> > 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.
>> >> >
>> >> > --
>> >> > 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.
>> >> >
>> >> > --
>> >> > 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.
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > 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.
>> >>
>> >> --
>> >> 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.
>> >>
>> >
>> > --
>> > 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.
>>
>> --
>> 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.
>>
>
>
>
> --
> Thanks & Regards
> ----------------------------
>
> Amyth [Admin - Techstricks]
> Email - aroras.offic...@gmail.com, ad...@techstricks.com
> Twitter - @a_myth_________
> http://techstricks.com/
>
> --
> 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.

-- 
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.

Reply via email to