Fixing problem with parent configuration.
This commit is contained in:
parent
728dee527d
commit
f3470f2693
4 changed files with 33 additions and 8 deletions
|
@ -9,6 +9,7 @@
|
||||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
from pyvows import Vows
|
from pyvows import Vows
|
||||||
|
@ -28,9 +29,14 @@ class DjangoContext(Vows.Context):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super(DjangoContext, self).__init__(parent)
|
super(DjangoContext, self).__init__(parent)
|
||||||
self.port = 8080
|
if parent:
|
||||||
self.host = '127.0.0.1'
|
self.port = parent.port
|
||||||
self.ignore('get_settings', 'template', 'request', 'model', 'url', 'start_environment', 'get_url', 'get', 'post')
|
self.host = parent.host
|
||||||
|
else:
|
||||||
|
self.port = 3331
|
||||||
|
self.host = '127.0.0.1'
|
||||||
|
self.ignore('get_settings', 'template', 'request', 'model', 'url',
|
||||||
|
'start_environment', 'port', 'host', 'get_url', 'get', 'post')
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
DjangoContext.start_environment(self.get_settings())
|
DjangoContext.start_environment(self.get_settings())
|
||||||
|
@ -75,9 +81,10 @@ class DjangoHTTPContext(DjangoContext):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super(DjangoHTTPContext, self).__init__(parent)
|
super(DjangoHTTPContext, self).__init__(parent)
|
||||||
self.port = 3331
|
self.ignore('start_server', 'settings')
|
||||||
self.host = '127.0.0.1'
|
|
||||||
self.ignore('start_server', 'port', 'host')
|
|
||||||
|
|
||||||
def get_url(self, path):
|
def get_url(self, path):
|
||||||
|
if re.match('^https?:\/\/', path):
|
||||||
|
return path
|
||||||
return 'http://%s:%d%s' % (self.host, self.port, path)
|
return 'http://%s:%d%s' % (self.host, self.port, path)
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,27 @@
|
||||||
# http://www.opensource.org/licenses/mit-license
|
# http://www.opensource.org/licenses/mit-license
|
||||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
return HttpResponse('hello world')
|
return HttpResponse('hello world')
|
||||||
|
|
||||||
def say_hello(request):
|
def say_hello(request):
|
||||||
if not 'name' in request.GET:
|
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?")
|
return HttpResponse("What's your name?")
|
||||||
return HttpResponse("Hello, %s!" % request.GET['name'])
|
|
||||||
|
elif SAY_HELLO_WITHOUT_NAME:
|
||||||
|
name = 'guess'
|
||||||
|
|
||||||
|
return HttpResponse("Hello, %s!" % name)
|
||||||
|
|
||||||
|
def get_setting(request, attr):
|
||||||
|
return HttpResponse(str(getattr(settings, attr)))
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,8 @@ INSTALLED_APPS = (
|
||||||
# 'django.contrib.admindocs',
|
# 'django.contrib.admindocs',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SAY_HELLO_WITHOUT_NAME = False
|
||||||
|
|
||||||
# A sample logging configuration. The only tangible logging
|
# A sample logging configuration. The only tangible logging
|
||||||
# performed by this configuration is to send an email to
|
# performed by this configuration is to send an email to
|
||||||
# the site admins on every HTTP 500 error.
|
# the site admins on every HTTP 500 error.
|
||||||
|
|
|
@ -17,6 +17,7 @@ from django.conf.urls.defaults import patterns, include, url
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^$', 'sandbox.main.views.home', name='home'),
|
url(r'^$', 'sandbox.main.views.home', name='home'),
|
||||||
url(r'^say/$', 'sandbox.main.views.say_hello', name='say_hello'),
|
url(r'^say/$', 'sandbox.main.views.say_hello', name='say_hello'),
|
||||||
|
url(r'^settings/(?P<attr>[\w_]+)/?$', 'sandbox.main.views.get_setting', name='get_setting'),
|
||||||
|
|
||||||
# url(r'^sandbox/', include('sandbox.foo.urls')),
|
# url(r'^sandbox/', include('sandbox.foo.urls')),
|
||||||
|
|
||||||
|
|
Reference in a new issue