diff --git a/ippisite/ippisite/settings.py b/ippisite/ippisite/settings.py index 65844de0017d83c7dcab4267a5ae480d1d38a006..30f909d8f92cca3ff74faa7197b87abce06cc66d 100644 --- a/ippisite/ippisite/settings.py +++ b/ippisite/ippisite/settings.py @@ -60,6 +60,7 @@ INSTALLED_APPS = [ "rest_framework", "polymorphic", "biodblinks", + "maintenance_mode", ] MIDDLEWARE = [ @@ -73,6 +74,7 @@ MIDDLEWARE = [ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "debug_toolbar.middleware.DebugToolbarMiddleware", + "maintenance_mode.middleware.MaintenanceModeMiddleware", ] ROOT_URLCONF = "ippisite.urls" @@ -91,6 +93,7 @@ TEMPLATES = [ "ippidb.views.marvinjs", "ippidb.views.google_analytics", "live_settings.context_processors.processors", + "maintenance_mode.context_processors.maintenance_mode", ] }, } @@ -212,3 +215,37 @@ LABLINKS_RESOURCE_DESCRIPTION = ( "iPPI-DB : An interactive database of protein-protein interactions modulators" ) LABLINKS_CONTACT_EMAIL = "ippidb@pasteur.fr" + +# MAINTENANCE SETTINGS + +# if True the maintenance-mode will be activated +MAINTENANCE_MODE = None +# by default, to get/set the state value a local file backend is used +# if you want to use the db or cache, you can create a custom backend +# custom backends must extend 'maintenance_mode.backends.AbstractStateBackend' class +# and implement get_value(self) and set_value(self, val) methods +MAINTENANCE_MODE_STATE_BACKEND = "maintenance_mode.backends.LocalFileBackend" +# if True admin site will not be affected by the maintenance-mode page +MAINTENANCE_MODE_IGNORE_ADMIN_SITE = True +# if True anonymous users will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_ANONYMOUS_USER = False +# if True authenticated users will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_AUTHENTICATED_USER = False +# if True the staff will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_STAFF = False +# if True the superuser will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_SUPERUSER = False +# if True the maintenance mode will not return 503 response while running tests +# useful for running tests while maintenance mode is on, before opening the site to public use +MAINTENANCE_MODE_IGNORE_TESTS = False +# the template that will be shown by the maintenance-mode page +MAINTENANCE_MODE_TEMPLATE = "503.html" +# the path of the function that will return the template context -> 'myapp.mymodule.myfunction' +MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None +# the HTTP status code to send +MAINTENANCE_MODE_STATUS_CODE = 503 +# the value in seconds of the Retry-After header during maintenance-mode +MAINTENANCE_MODE_RETRY_AFTER = 3600 # 1 hour +# list of urls that will not be affected by the maintenance-mode +# urls will be used to compile regular expressions objects +MAINTENANCE_MODE_IGNORE_URLS = (r"^((?!\/targetcentric).)*$",) diff --git a/ippisite/ippisite/settings.template.py b/ippisite/ippisite/settings.template.py index 163bd2fe325501390d797585f1d2b7f24cd16fed..c4f1b3c917562d7087fbf65255b455a46c62d233 100644 --- a/ippisite/ippisite/settings.template.py +++ b/ippisite/ippisite/settings.template.py @@ -62,6 +62,7 @@ INSTALLED_APPS = [ "allauth.socialaccount.providers.orcid", "rest_framework", "polymorphic", + "maintenance_mode", ] MIDDLEWARE = [ @@ -74,6 +75,7 @@ MIDDLEWARE = [ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "debug_toolbar.middleware.DebugToolbarMiddleware", + "maintenance_mode.middleware.MaintenanceModeMiddleware", ] ROOT_URLCONF = "ippisite.urls" @@ -92,6 +94,7 @@ TEMPLATES = [ "ippidb.views.marvinjs", "ippidb.views.google_analytics", "live_settings.context_processors.processors", + "maintenance_mode.context_processors.maintenance_mode", ] }, } @@ -190,3 +193,37 @@ LABLINKS_RESOURCE_DESCRIPTION = ( "iPPI-DB : An interactive database of protein-protein interactions modulators" ) LABLINKS_CONTACT_EMAIL = "ippidb@pasteur.fr" + +# MAINTENANCE SETTINGS + +# if True the maintenance-mode will be activated +MAINTENANCE_MODE = None +# by default, to get/set the state value a local file backend is used +# if you want to use the db or cache, you can create a custom backend +# custom backends must extend 'maintenance_mode.backends.AbstractStateBackend' class +# and implement get_value(self) and set_value(self, val) methods +MAINTENANCE_MODE_STATE_BACKEND = "maintenance_mode.backends.LocalFileBackend" +# if True admin site will not be affected by the maintenance-mode page +MAINTENANCE_MODE_IGNORE_ADMIN_SITE = True +# if True anonymous users will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_ANONYMOUS_USER = False +# if True authenticated users will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_AUTHENTICATED_USER = False +# if True the staff will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_STAFF = False +# if True the superuser will not see the maintenance-mode page +MAINTENANCE_MODE_IGNORE_SUPERUSER = False +# if True the maintenance mode will not return 503 response while running tests +# useful for running tests while maintenance mode is on, before opening the site to public use +MAINTENANCE_MODE_IGNORE_TESTS = False +# the template that will be shown by the maintenance-mode page +MAINTENANCE_MODE_TEMPLATE = "503.html" +# the path of the function that will return the template context -> 'myapp.mymodule.myfunction' +MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None +# the HTTP status code to send +MAINTENANCE_MODE_STATUS_CODE = 503 +# the value in seconds of the Retry-After header during maintenance-mode +MAINTENANCE_MODE_RETRY_AFTER = 3600 # 1 hour +# list of urls that will not be affected by the maintenance-mode +# urls will be used to compile regular expressions objects +MAINTENANCE_MODE_IGNORE_URLS = (r"^((?!\/targetcentric).)*$",) diff --git a/ippisite/ippisite/urls.py b/ippisite/ippisite/urls.py index 85d84d964b6745464344ec4174690a5bbb5e61c5..6cb2032ae3ac8ae9c3dd1f29daf0ed20081ab103 100644 --- a/ippisite/ippisite/urls.py +++ b/ippisite/ippisite/urls.py @@ -15,6 +15,7 @@ Including another URLconf """ from django.conf.urls import include, url from django.contrib import admin +from . import views urlpatterns = [ url(r"^", include("ippidb.urls")), @@ -22,4 +23,6 @@ urlpatterns = [ url(r"^admin/", admin.site.urls), url(r"^accounts/", include("allauth.urls")), url(r"^auth/", include("django.contrib.auth.urls")), + url(r'^maintenance-mode/on/', views.maintenance_mode_on, name="maintenance_on"), + url(r'^maintenance-mode/off/', views.maintenance_mode_off, name="maintenance_off"), ] diff --git a/ippisite/templates/503.html b/ippisite/templates/503.html new file mode 100644 index 0000000000000000000000000000000000000000..dfe1955331a29327c004bcac8b720c6167d17067 --- /dev/null +++ b/ippisite/templates/503.html @@ -0,0 +1,38 @@ +{% extends "index.html" %} + +{% block content %} +<div class="inner-wrap"> + <div id="main-wrapper" class="page"> + <div id="main"> + <div id="content" class="main-content"> + <div class="section"> + <main role="main"> + <h1 class="page-title"> {% block pagetitle %}We’ll be back soon!{% endblock%} </h1> + <div class="tabs"></div> + <div class="main__inner"> + <div class="region region-content"> + <div class="page-intro"> + </div> + <div class="color-wrap"> + <div class="region region-content"> + <div class="block block-system block-system-main"> + <div class="content"> + <div class="view-content"> +{% block view_content %} +<p>Sorry for the inconvenience but we’re performing some maintenance at the moment. We’ll be back online shortly!</p> +<p>— The iPPI-DB Team</p> +{% endblock %} + </div> + </div> + </div> + </div> + </div> + </div> + </div> + </main><!-- .site-main --> + </div> + </div> + </div><!-- div main --> + </div> +</div> +{% endblock %} diff --git a/ippisite/templates/admin/index.html b/ippisite/templates/admin/index.html index 82295da00df61a8bf3e6a0c8684875c100de9ff6..44a2c4a2883b57e6a2c676bd6431cb025c7382e7 100644 --- a/ippisite/templates/admin/index.html +++ b/ippisite/templates/admin/index.html @@ -39,6 +39,24 @@ {%endif%} </form> <hr/> + {% if maintenance_mode %} + <form method="GET" action="/maintenance-mode/off/" + style="display:block">{% csrf_token %} + + <span><b>Maintenance</b>: Activated</span> + <input type="hidden" name="value" value="False"/> + <input type="submit" value="Unactive maintenance mode"/> + </form> + {%else%} + <form method="GET" action="/maintenance-mode/on/" + style="display:block">{% csrf_token %} + <span><b>Maintenance</b>: Unactivated</span> + <input type="hidden" name="value" value="True"/> + <input type="submit" value="Active maintenance mode"/> + </form> + {%endif%} + </form> + <hr/> </div>