Fix for django context settings

This commit is contained in:
Bernardo Heynemann 2011-09-14 14:07:09 -03:00
parent 0f1b99e592
commit 3f2ab0777a
2 changed files with 12 additions and 1 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@
dist/
.project
.pydevproject
build/

View file

@ -10,6 +10,7 @@
import os
import re
from threading import local, current_thread
from pyvows import Vows
from django.http import HttpRequest
@ -31,15 +32,24 @@ class DjangoContext(Vows.Context):
os.environ['DJANGO_SETTINGS_MODULE'] = settings_path
settings_tracker.install()
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
self.settings = {}
self.ignore('get_settings', 'template', 'request', 'model', 'url', 'find_in_parent',
'start_environment', 'port', 'host', 'get_url', 'get', 'post')
@property
def settings(self):
thread = current_thread()
if not hasattr(thread, "settings"):
thread.settings = local()
return thread.settings
def setup(self):
DjangoContext.start_environment(self.get_settings())
def get_settings(self):
if 'DJANGO_SETTINGS_MODULE' in os.environ:
return os.environ['DJANGO_SETTINGS_MODULE']