fixes to make the django-settings settable
This commit is contained in:
parent
d2d8c7e3c2
commit
09903f52ce
4 changed files with 16 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -121,16 +121,17 @@ class DjangoServer(HTTPServer, object):
|
|||
|
||||
def start(self, settings):
|
||||
self.server_activate()
|
||||
def 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"):
|
||||
if not hasattr(thread, 'settings'):
|
||||
thread.settings = local()
|
||||
for key, value in getattr(settings, '__dict__', settings).items():
|
||||
for key, value in settings.items():
|
||||
setattr(thread.settings, key, value)
|
||||
while True:
|
||||
self.handle_request()
|
||||
|
||||
self.thr = Thread(target=make_response)
|
||||
self.thr.daemon = True
|
||||
self.thr.start()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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/')
|
||||
|
||||
|
|
Reference in a new issue