From 43183096242fd2b1b10fc450de929b90fa4d9273 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@bioforsk.no>
Date: Wed, 30 Nov 2016 12:35:01 -0800
Subject: [PATCH] Creating maintenance mode myself!

---
 VIPSWeb/settings.py        |  1 -
 VIPSWeb/templates/503.html | 15 ++++----
 VIPSWeb/urls.py            | 73 ++++++++++++++++++++------------------
 VIPSWeb/views.py           |  3 ++
 requirements.txt           |  3 +-
 5 files changed, 51 insertions(+), 44 deletions(-)

diff --git a/VIPSWeb/settings.py b/VIPSWeb/settings.py
index 9fc8f625..c9b56592 100644
--- a/VIPSWeb/settings.py
+++ b/VIPSWeb/settings.py
@@ -93,7 +93,6 @@ MIDDLEWARE_CLASSES = (
     'django.contrib.messages.middleware.MessageMiddleware',
     'common.middleware.whodid.WhodidMiddleware',
     'django.middleware.locale.LocaleMiddleware',
-    'maintenancemode.middleware.MaintenanceModeMiddleware',
     'security.middleware.check_login_middleware.CheckLoginMiddleware'
     # Uncomment the next line for simple clickjacking protection:
     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
diff --git a/VIPSWeb/templates/503.html b/VIPSWeb/templates/503.html
index e535b03b..56da82cd 100644
--- a/VIPSWeb/templates/503.html
+++ b/VIPSWeb/templates/503.html
@@ -1,7 +1,8 @@
-{% extends "base.html" %}
-{% load i18n %}
-{% block title %}{% trans "Temporarily down for maintenance" %}{% endblock %}
-{% block content %}
-<h1>{% trans "Temporarily down for maintenance" %}</h1>
-<p>{% trans "We are sorry, but the web site is currently underdoing maintenance. We should be back online shortly." %}</p>
-{% endblock %}
+<html>
+<head><title>Site down for maintenance</title></head>
+<body>
+<img src="/static/images/logo_vips_newest.png"/>
+<h1>Site down for maintenance</h1>
+<p>We are sorry, but the web site is currently underdoing maintenance. We should be back online shortly.</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/VIPSWeb/urls.py b/VIPSWeb/urls.py
index 3d37873a..869c9138 100644
--- a/VIPSWeb/urls.py
+++ b/VIPSWeb/urls.py
@@ -32,37 +32,42 @@ js_info_dict = {
     'domain': 'djangojs',
 }
 
-urlpatterns = patterns('',
-    # Examples:
-    # url(r'^$', 'VIPSWeb.views.home', name='home'),
-    # url(r'^VIPSWeb/', include('VIPSWeb.foo.urls')),
-
-    # Uncomment the admin/doc line below to enable admin documentation:
-    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
-    url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")),
-    url(r'^messages/', include('vips_messages.urls', namespace = "vips_messages")),
-    url(r'^organisms/', include('organisms.urls', namespace = "organisms")),
-    url(r'^observations/', include('observations.urls', namespace = "observations")),
-    url(r'^information/', include('information.urls', namespace = "information")),
-    url(r'^blotch/', include('cerealblotchmodels.urls', namespace = "cerealblotchmodels")),
-    url(r'^calculators/', include('calculators.urls', namespace = "calculators")),
-    url(r'^roughage/', include('roughage.urls', namespace = "roughage")),
-    url(r'^security/', include('security.urls', namespace = "security")),
-    url(r'^fusarium/', include('fusarium.urls', namespace = "fusarium")),
-    url(r'^applefruitmoth/', include('applefruitmoth.urls', namespace = "applefruitmoth")),
-    # Uncomment the next line to enable the admin:
-    url(r'^admin/', include(admin.site.urls)),
-    url(r'^tinymce/', include('tinymce.urls')),
-    # Static serving of media files
-    url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
-    # Enabling translation in JavaScript files
-    # See https://docs.djangoproject.com/en/1.6/topics/i18n/translation/#internationalization-in-javascript-code
-    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
-    (r'^i18n/', include('django.conf.urls.i18n')),
-    (r'^settings.js', views.settings_js),
-    (r'^vipslogicproxy/(?P<path>.*)$', views.vipslogicproxy),
-    # Default view is index
-    url(r'^$', views.index, name='index'),
-    #url(r'^$', TemplateView.as_view(template_name="index.html"))
-)
+if settings.MAINTENANCE_MODE is True:
+    urlpatterns = patterns('',
+                           url(r'^$', views.maintenance, name='maintenance')
+    )
+else:
+    urlpatterns = patterns('',
+        # Examples:
+        # url(r'^$', 'VIPSWeb.views.home', name='home'),
+        # url(r'^VIPSWeb/', include('VIPSWeb.foo.urls')),
+    
+        # Uncomment the admin/doc line below to enable admin documentation:
+        # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+    
+        url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")),
+        url(r'^messages/', include('vips_messages.urls', namespace = "vips_messages")),
+        url(r'^organisms/', include('organisms.urls', namespace = "organisms")),
+        url(r'^observations/', include('observations.urls', namespace = "observations")),
+        url(r'^information/', include('information.urls', namespace = "information")),
+        url(r'^blotch/', include('cerealblotchmodels.urls', namespace = "cerealblotchmodels")),
+        url(r'^calculators/', include('calculators.urls', namespace = "calculators")),
+        url(r'^roughage/', include('roughage.urls', namespace = "roughage")),
+        url(r'^security/', include('security.urls', namespace = "security")),
+        url(r'^fusarium/', include('fusarium.urls', namespace = "fusarium")),
+        url(r'^applefruitmoth/', include('applefruitmoth.urls', namespace = "applefruitmoth")),
+        # Uncomment the next line to enable the admin:
+        url(r'^admin/', include(admin.site.urls)),
+        url(r'^tinymce/', include('tinymce.urls')),
+        # Static serving of media files
+        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
+        # Enabling translation in JavaScript files
+        # See https://docs.djangoproject.com/en/1.6/topics/i18n/translation/#internationalization-in-javascript-code
+        (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
+        (r'^i18n/', include('django.conf.urls.i18n')),
+        (r'^settings.js', views.settings_js),
+        (r'^vipslogicproxy/(?P<path>.*)$', views.vipslogicproxy),
+        # Default view is index
+        url(r'^$', views.index, name='index'),
+        #url(r'^$', TemplateView.as_view(template_name="index.html"))
+    )
diff --git a/VIPSWeb/views.py b/VIPSWeb/views.py
index a15d0e8f..2749f049 100644
--- a/VIPSWeb/views.py
+++ b/VIPSWeb/views.py
@@ -68,6 +68,9 @@ def settings_js(request):
 def resourcebundle(request):
     return render(request, 'resourcebundle.js',content_type="application/javascript")
 
+def maintenance(request):
+    return render(request, '503.html')
+
 @cache_page(60 * 10)
 @gzip_page
 def vipslogicproxy(request, path):
diff --git a/requirements.txt b/requirements.txt
index 62a618f5..0315d8ac 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2014 NIBIO <http://www.nibio.no/>. 
+# Copyright (c) 2016 NIBIO <http://www.nibio.no/>. 
 # 
 # This file is part of VIPSWeb.
 # VIPSWeb is free software: you can redistribute it and/or modify
@@ -23,4 +23,3 @@ Pillow
 requests==2.6.0
 django-tinymce
 python-dateutil==1.5
-django-maintenancemode
-- 
GitLab