Sharing users db

48 views
Skip to first unread message

Evgenii Belykh

unread,
Feb 16, 2012, 11:00:53 AM2/16/12
to Django users
Hi folks!

I've trying to use sharing db via technique proposed by Dustin at
http://dfcode.com/
(available at
http://webcache.googleusercontent.com/search?q=cache:ukYEYwoaJtYJ:dfcode.com/blog/2011/5/sharing-django-users-and-sessions-across-projects/+sharing+users+django&cd=1&hl=ru&ct=clnk&gl=ru&client=opera)

--------------------------------
it works untill I've trying to exclude /admin from routing via the
following code:
import threading


# Object to hold request data
request_cfg = threading.local()


class RouterMiddleware(object):
"""
Sets a flag if we are accessing Django admin to prevent database
rerouting
for the auth model. Removes the flag once the request has been
processed.
"""

def process_view(self, request, view_func, args, kwargs):
if request.path.startswith('/admin'):
request_cfg.admin = True

def process_response(self, request, response):
if hasattr(request_cfg, 'admin'):
del request_cfg.admin
--------------------------------------------------
Accessing site root get an error:
TypeError at /

argument of type 'NoneType' is not iterable
Exception Location: /home/alexey/sites/django/http/utils.py in
fix_location_header, line 19:
if 'Location' in response and request.get_host():
response['Location'] =
request.build_absolute_uri(response['Location'])
return response

-------------------------------------------------
Any help much appreciated.
PS.Maybe smth wrong in RouterMiddleware since it does not return a
response?



Tom Evans

unread,
Feb 16, 2012, 11:30:10 AM2/16/12
to django...@googlegroups.com
On Thu, Feb 16, 2012 at 4:00 PM, Evgenii Belykh <djang...@gmail.com> wrote:
> Hi folks!
>
> I've trying to use sharing db via technique proposed by Dustin at
> […]

>    def process_view(self, request, view_func, args, kwargs):
>        if request.path.startswith('/admin'):
>            request_cfg.admin = True
>
>    def process_response(self, request, response):
>        if hasattr(request_cfg, 'admin'):
>            del request_cfg.admin
>[…]

> -------------------------------------------------
> Any help much appreciated.
> PS.Maybe smth wrong in RouterMiddleware since it does not return a
> response?
>

Asked and answered yourself!

Yes, that is exactly why it is failing. process_response(), if it
exists, must always return a response.

See:

https://docs.djangoproject.com/en/1.3/topics/http/middleware/#process-response

Cheers

Tom

Evgenii Belykh

unread,
Feb 16, 2012, 12:25:27 PM2/16/12
to Django users
it rocks Tom!!


On Feb 16, 7:30 pm, Tom Evans <tevans...@googlemail.com> wrote:
> https://docs.djangoproject.com/en/1.3/topics/http/middleware/#process...
>
> Cheers
>
> Tom
Reply all
Reply to author
Forward
0 new messages