From cd8426f4d316b1a5db53c91e8584803728ba4796 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Mon, 23 Nov 2020 14:03:39 +0100
Subject: [PATCH] Migration step 2: Now works with Django 2.0

---
 VIPSWeb/settings.py                           | 2 +-
 VIPSWeb/templatetags/template_helper.py       | 2 +-
 VIPSWeb/urls.py                               | 2 +-
 VIPSWeb/views.py                              | 8 +++++---
 VIPSWeb/wsgi.py                               | 3 ++-
 common/middleware/whodid.py                   | 9 +++++++++
 information/migrations/0001_initial.py        | 8 ++++----
 requirements.txt                              | 4 ++--
 security/middleware/check_login_middleware.py | 9 +++++++++
 9 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/VIPSWeb/settings.py b/VIPSWeb/settings.py
index 32823971..ac1cb4ce 100755
--- a/VIPSWeb/settings.py
+++ b/VIPSWeb/settings.py
@@ -79,7 +79,7 @@ STATICFILES_FINDERS = (
 
 
 
-MIDDLEWARE_CLASSES = (
+MIDDLEWARE = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
diff --git a/VIPSWeb/templatetags/template_helper.py b/VIPSWeb/templatetags/template_helper.py
index c13f9a90..71575629 100755
--- a/VIPSWeb/templatetags/template_helper.py
+++ b/VIPSWeb/templatetags/template_helper.py
@@ -93,7 +93,7 @@ def generate_frontpage_menu(context):
 		""" 
 	
 	menu_html = ''
-	col_md = 12/len(settings.FRONTPAGE_MENU)
+	col_md = int(12/len(settings.FRONTPAGE_MENU))
 	for col in settings.FRONTPAGE_MENU:
 		menu_html += '<div class="col-md-%s"><h3>%s</h3>' % (col_md,_(col["label"]))
 		menu_html += "<ul class='linkList'>"
diff --git a/VIPSWeb/urls.py b/VIPSWeb/urls.py
index c0ec1a85..681c5c57 100755
--- a/VIPSWeb/urls.py
+++ b/VIPSWeb/urls.py
@@ -30,7 +30,7 @@ admin.autodiscover()
 # Enabling translation in JavaScript files
 # See https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#internationalization-in-javascript-code
 js_info_dict = {
-    'packages': ['forecasts','messages','VIPSWeb','roughage'],
+    'packages': ['forecasts','vips_messages','VIPSWeb','roughage'],
     'domain': 'djangojs',
 }
 
diff --git a/VIPSWeb/views.py b/VIPSWeb/views.py
index 1d8589a8..74f2fee7 100755
--- a/VIPSWeb/views.py
+++ b/VIPSWeb/views.py
@@ -100,13 +100,15 @@ def vipslogicproxy(request, path):
     params = request.urlencode()
 
 
-    #print "Params:" + params
+    #print ("Params:" + params)
     try:
         url = "%s://%s/%s" % (settings.VIPSLOGIC_PROTOCOL, settings.VIPSLOGIC_SERVER_NAME,path)
-        #print url
+        #print(url)
     except KeyError:
         return HttpResponseBadRequest("URL must be defined")
-    response = r(url.encode("ascii"), params=params.encode("ascii"))
+    url = url.encode("ascii")
+    params_encoded = params.encode("ascii")
+    response = r(url, params=params_encoded)
     if response.status_code == 200:
         return HttpResponse(response.text, status=int(response.status_code), content_type=response.headers.get('content-type',"text/plain"))
     else:
diff --git a/VIPSWeb/wsgi.py b/VIPSWeb/wsgi.py
index ff8ffae4..ff95b082 100755
--- a/VIPSWeb/wsgi.py
+++ b/VIPSWeb/wsgi.py
@@ -32,6 +32,7 @@ framework.
 
 """
 import os
+from django.core.wsgi import get_wsgi_application
 
 # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
 # if running multiple sites in the same mod_wsgi process. To fix this, use
@@ -42,7 +43,7 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "VIPSWeb.settings")
 # This application object is used by any WSGI server configured to use this
 # file. This includes Django's development server, if the WSGI_APPLICATION
 # setting points here.
-from django.core.wsgi import get_wsgi_application
+
 application = get_wsgi_application()
 
 # Apply WSGI middleware here.
diff --git a/common/middleware/whodid.py b/common/middleware/whodid.py
index f14aff18..97b59e2d 100755
--- a/common/middleware/whodid.py
+++ b/common/middleware/whodid.py
@@ -23,8 +23,17 @@ Found here: https://gist.github.com/mindlace/3918300
 """
 from django.db.models import signals
 from django.utils.functional import curry
+from django.http import HttpResponse
  
 class WhodidMiddleware(object):
+    
+    def __init__(self, get_response):
+        self.get_response = get_response
+        
+    def __call__(self, request):
+        self.process_request(request)
+        return self.get_response(request)
+    
     def process_request(self, request):
         if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
             if hasattr(request, 'user') and request.user.is_authenticated():
diff --git a/information/migrations/0001_initial.py b/information/migrations/0001_initial.py
index 997a0015..33f54749 100755
--- a/information/migrations/0001_initial.py
+++ b/information/migrations/0001_initial.py
@@ -16,7 +16,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('main_illustration', models.ImageField(upload_to=b'images/information', verbose_name='Hovedillustrasjon', blank=True)),
-                ('parent_information', models.ForeignKey(related_name='children', verbose_name='Informasjon', blank=True, to='information.Information', null=True)),
+                ('parent_information', models.ForeignKey(related_name='children', verbose_name='Informasjon', blank=True, to='information.Information', null=True,on_delete=models.CASCADE)),
             ],
         ),
         migrations.CreateModel(
@@ -24,7 +24,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('attachment', models.FileField(upload_to=b'attachments/information', verbose_name='Vedlegg', blank=True)),
-                ('information', models.ForeignKey(to='information.Information')),
+                ('information', models.ForeignKey(to='information.Information',on_delete=models.CASCADE)),
             ],
         ),
         migrations.CreateModel(
@@ -32,7 +32,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('illustration', models.ImageField(upload_to=b'images/information', verbose_name='Illustrasjon', blank=True)),
-                ('information', models.ForeignKey(to='information.Information')),
+                ('information', models.ForeignKey(to='information.Information',on_delete=models.CASCADE)),
             ],
         ),
         migrations.CreateModel(
@@ -43,7 +43,7 @@ class Migration(migrations.Migration):
                 ('lead_paragraph', models.TextField(verbose_name='Ingress')),
                 ('body', tinymce.models.HTMLField(verbose_name='Br\xf8dtekst')),
                 ('language_code', models.CharField(max_length=2, verbose_name='Spr\xe5kkode')),
-                ('information', models.ForeignKey(to='information.Information')),
+                ('information', models.ForeignKey(to='information.Information',on_delete=models.CASCADE)),
             ],
         ),
     ]
diff --git a/requirements.txt b/requirements.txt
index d95ce788..c0746db4 100755
--- a/requirements.txt
+++ b/requirements.txt
@@ -18,9 +18,9 @@
 
 # Please add requirements here
 # Read docs for how this works: http://www.pip-installer.org/en/latest/cookbook.html
-Django==1.11.17
+Django==2.0.13
 Pillow
-requests==2.6.0
+requests==2.25.0
 django-tinymce==2.8.0
 python-dateutil==2.8.1
 django-extensions
diff --git a/security/middleware/check_login_middleware.py b/security/middleware/check_login_middleware.py
index b2681fad..e8c856a7 100755
--- a/security/middleware/check_login_middleware.py
+++ b/security/middleware/check_login_middleware.py
@@ -21,11 +21,20 @@ from security.models import VipsLogicUser
 from django.conf import settings
 from datetime import datetime, timedelta
 import json
+from django.http import HttpResponse
 
 
 class CheckLoginMiddleware(object):
     datetime_format = "%Y-%m-%d %H:%M:%S"
     
+    def __init__(self, get_response):
+        self.get_response = get_response
+        
+    def __call__(self, request):
+        self.process_request(request)
+        return self.get_response(request)
+    
+    
     def process_request(self, request):
         # If UUID is provided, login with VIPSLogic
         # VIPSLogicUser exists in session for 24 hours
-- 
GitLab