From 7d3924af558c49e0cd8c49b4eda0382888e1d47d Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Thu, 28 Nov 2013 14:52:01 +0530 Subject: [PATCH 1/3] [minor] move static data middleware to development serve command --- webnotes/app.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/webnotes/app.py b/webnotes/app.py index a6de33b0d1..24943ebcc7 100644 --- a/webnotes/app.py +++ b/webnotes/app.py @@ -54,17 +54,17 @@ def application(request): application = local_manager.make_middleware(application) - -application = StaticDataMiddleware(application, { - '/': 'public', -}) - - def serve(port=8000, profile=False): webnotes.validate_versions() global application from werkzeug.serving import run_simple + if profile: application = ProfilerMiddleware(application) + + application = StaticDataMiddleware(application, { + '/': 'public', + }) + run_simple('0.0.0.0', int(port), application, use_reloader=True, use_debugger=True, use_evalex=True) From 46b860e93d8a9e8dda3499b7306e30ebcd0e0174 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Thu, 28 Nov 2013 14:52:13 +0530 Subject: [PATCH 2/3] handle session stopped --- webnotes/app.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/webnotes/app.py b/webnotes/app.py index 24943ebcc7..865b157231 100644 --- a/webnotes/app.py +++ b/webnotes/app.py @@ -20,6 +20,19 @@ import webnotes.webutils local_manager = LocalManager([webnotes.local]) +def handle_session_stopped(): + res = Response(""" + +

+ Updating. + We will be back in a few moments... +

+ + """) + res.status_code = 503 + res.content_type = 'text/html' + return res + @Request.application def application(request): webnotes.local.request = request @@ -46,11 +59,14 @@ def application(request): except HTTPException, e: return e + except webnotes.SessionStopped, e: + webnotes.local._response = handle_session_stopped() + finally: if webnotes.conn: webnotes.conn.close() - return webnotes._response + return webnotes.local._response application = local_manager.make_middleware(application) From 001f4389cf7595caf0a33657ea35696207322eab Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Fri, 29 Nov 2013 12:42:24 +0530 Subject: [PATCH 3/3] [minor] do not serve statics if NO_STATICS in environ --- webnotes/app.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/webnotes/app.py b/webnotes/app.py index 865b157231..f30f5d830b 100644 --- a/webnotes/app.py +++ b/webnotes/app.py @@ -70,6 +70,11 @@ def application(request): application = local_manager.make_middleware(application) +if not os.environ.get('NO_STATICS'): + application = StaticDataMiddleware(application, { + '/': 'public', + }) + def serve(port=8000, profile=False): webnotes.validate_versions() global application @@ -78,9 +83,5 @@ def serve(port=8000, profile=False): if profile: application = ProfilerMiddleware(application) - application = StaticDataMiddleware(application, { - '/': 'public', - }) - run_simple('0.0.0.0', int(port), application, use_reloader=True, use_debugger=True, use_evalex=True)