From ceb10d116e7b7ca55fe9a58c8164dc3d2c12dcf4 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 4 Jul 2017 20:44:59 +0200 Subject: [PATCH 1/5] Added python-memcached to requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index de1b1500..74637112 100644 --- a/requirements.txt +++ b/requirements.txt @@ -84,5 +84,5 @@ django-admin-honeypot==1.0.0 coverage==4.3.4 git+https://github.com/ungleich/python-oca.git#egg=python-oca djangorestframework - +python-memcached==1.58 From 41220ef17275947597d028abfd828d59c2d82061 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 4 Jul 2017 20:46:42 +0200 Subject: [PATCH 2/5] Added bool_env function to retrieve env variable and convert to python boolean --- dynamicweb/settings/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index ba304ff9..29b19c5b 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -17,6 +17,9 @@ gettext = lambda s: s def env(env_name): return os.environ.get(env_name) +def bool_env(val): + """Replaces string based environment values with Python booleans""" + return True if os.environ.get(val, False) == 'True' else False BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -470,7 +473,7 @@ REGISTRATION_MESSAGE = {'subject': "Validation mail", STRIPE_API_PRIVATE_KEY = env('STRIPE_API_PRIVATE_KEY') STRIPE_API_PUBLIC_KEY = env('STRIPE_API_PUBLIC_KEY') -DEBUG = True +DEBUG = bool_env('DEBUG') if DEBUG: from .local import * From 6d7a1d4e4a142179020fae108c1c99b92599f51d Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 4 Jul 2017 21:00:00 +0200 Subject: [PATCH 3/5] Added memcached cache --- dynamicweb/settings/prod.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dynamicweb/settings/prod.py b/dynamicweb/settings/prod.py index 4f96593f..9b5ffcc0 100644 --- a/dynamicweb/settings/prod.py +++ b/dynamicweb/settings/prod.py @@ -7,6 +7,13 @@ DEBUG=False EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': '127.0.0.1:11211', + } +} + #MANAGERS = ADMINS REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='digitalglarus.ungleich.ch',slug='{slug}') From 4bdae326f75808dfc24eb3bc978175563d9172d9 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 4 Jul 2017 23:16:27 +0200 Subject: [PATCH 4/5] Refactored the call to import local and prod files --- dynamicweb/settings/base.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 29b19c5b..f2af7a0e 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -473,14 +473,6 @@ REGISTRATION_MESSAGE = {'subject': "Validation mail", STRIPE_API_PRIVATE_KEY = env('STRIPE_API_PRIVATE_KEY') STRIPE_API_PUBLIC_KEY = env('STRIPE_API_PUBLIC_KEY') -DEBUG = bool_env('DEBUG') - -if DEBUG: - from .local import * -else: - from .prod import * - - ANONYMOUS_USER_NAME = 'anonymous@ungleich.ch' GUARDIAN_GET_INIT_ANONYMOUS_USER = 'membership.models.get_anonymous_user_instance' @@ -524,3 +516,10 @@ GOOGLE_ANALYTICS_PROPERTY_IDS = { 'dynamicweb-development.ungleich.ch': 'development', 'dynamicweb-staging.ungleich.ch': 'staging' } + +DEBUG = bool_env('DEBUG') + +if DEBUG: + from .local import * +else: + from .prod import * From 3304d862cb5e9c7354935c7d4206ee90e7d9501d Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Wed, 5 Jul 2017 00:07:06 +0200 Subject: [PATCH 5/5] Moved static images urlpattern out of DEBUG case --- dynamicweb/urls.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index 0b1a0844..dad511fc 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -42,12 +42,11 @@ urlpatterns += i18n_patterns('', url(r'^blog/', include('ungleich.urls', namespace='ungleich')), url(r'^', include('cms.urls')) ) - +urlpatterns += patterns('', + url(r'^media/(?P.*)$', + 'django.views.static.serve', { + 'document_root': settings.MEDIA_ROOT, + }), + ) if settings.DEBUG: - urlpatterns += patterns('', - url(r'^media/(?P.*)$', - 'django.views.static.serve', { - 'document_root': settings.MEDIA_ROOT, - }), - ) urlpatterns += patterns('',url(r'^__debug__/', include(debug_toolbar.urls)))