diff --git a/django_pyvows/context.py b/django_pyvows/context.py index e1dd2ab..e971351 100644 --- a/django_pyvows/context.py +++ b/django_pyvows/context.py @@ -48,10 +48,7 @@ class DjangoContext(Vows.Context): DjangoContext.start_environment(self.get_settings()) def get_settings(self): - if 'DJANGO_SETTINGS_MODULE' in os.environ: - return os.environ['DJANGO_SETTINGS_MODULE'] - else: - return 'settings' + return os.environ.get('DJANGO_SETTINGS_MODULE', 'settings') def url(self, path): return Url(self, path) diff --git a/django_pyvows/server.py b/django_pyvows/server.py index ce76aec..78793ec 100644 --- a/django_pyvows/server.py +++ b/django_pyvows/server.py @@ -121,16 +121,17 @@ class DjangoServer(HTTPServer, object): def start(self, settings): self.server_activate() - def make_response(): - thread = current_thread() - if not hasattr(thread, "settings"): - thread.settings = local() - for key, value in getattr(settings, '__dict__', settings).items(): - setattr(thread.settings, key, value) - while True: - self.handle_request() - - self.thr = Thread(target=make_response) + self.thr = Thread(target=self.make_response_thread, args=(getattr(settings, '__dict__', settings),)) self.thr.daemon = True self.thr.start() + def make_response_thread(self, settings): + thread = current_thread() + if not hasattr(thread, 'settings'): + thread.settings = local() + for key, value in settings.items(): + setattr(thread.settings, key, value) + while True: + self.handle_request() + + diff --git a/vows/sandbox/main/views.py b/vows/sandbox/main/views.py index 9490e96..b956c7c 100644 --- a/vows/sandbox/main/views.py +++ b/vows/sandbox/main/views.py @@ -19,10 +19,10 @@ def say_hello(request): SAY_HELLO_WITHOUT_NAME = getattr(settings, "SAY_HELLO_WITHOUT_NAME", False) if 'name' in request.GET: name = request.GET['name'] - elif not SAY_HELLO_WITHOUT_NAME: - return HttpResponse("What's your name?") elif SAY_HELLO_WITHOUT_NAME: name = 'guess' + else: + return HttpResponse("What's your name?") return HttpResponse("Hello, %s!" % name) def post_it(request): diff --git a/vows/settings_vows.py b/vows/settings_vows.py index 20f9a95..0dead0a 100644 --- a/vows/settings_vows.py +++ b/vows/settings_vows.py @@ -53,7 +53,7 @@ class SettingsVows(DjangoContext): class CannotSayHelloWithoutName(DjangoHTTPContext): def topic(self): - self.settings['SAY_HELLO_WITHOUT_NAME'] = False + self.settings.SAY_HELLO_WITHOUT_NAME = False self.start_server(port=8002) return self.get('/say/') @@ -66,7 +66,7 @@ class SettingsVows(DjangoContext): class SayHelloWithoutName(DjangoHTTPContext): def topic(self): - self.settings['SAY_HELLO_WITHOUT_NAME'] = True + self.settings.SAY_HELLO_WITHOUT_NAME = True self.start_server(port=8003) return self.get('/say/')