From 3308a3df4b987e83d01e15a3aec229d28312019e Mon Sep 17 00:00:00 2001
From: Jacek Lebioda <jacek.lebioda@uni.lu>
Date: Tue, 6 Oct 2020 16:14:57 +0200
Subject: [PATCH] fix: misc python3 changes

---
 requirements.txt                          | 32 +++++-----
 smash/smash/urls.py                       |  4 +-
 smash/web/migrations/0120_holiday_kind.py |  2 +-
 smash/web/models/mail_template.py         | 71 +++++++++++++++++------
 smash/web/urls.py                         |  2 +-
 smash/web/widgets/secure_file_widget.py   |  2 +-
 6 files changed, 75 insertions(+), 38 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index d63534e9..2dcf250a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,21 +3,21 @@ asn1crypto==0.24.0
 Babel==2.6.0
 backports.functools-lru-cache==1.5
 certifi==2018.8.24
-cffi==1.11.5
+cffi==1.14.2
 chardet==3.0.4
 coverage==4.5.1
 cryptography==2.3.1
 cycler==0.10.0
-Django==1.11.5
-django-cleanup==0.4.2
+Django==1.11.17
+django-cleanup==4.0.0
 django-common-helpers==0.9.2
 django-cron==0.5.0
 django-excel==0.0.9
-django-formtools==2.1
-django-otp==0.5.0
+django-formtools==2.2
+django-otp==0.9.4
 django-phonenumber-field==1.3.0
 django-stronghold==0.2.9
-django-two-factor-auth==1.6.1
+django-two-factor-auth==1.9.1
 enum34==1.1.6
 Faker==0.9.2
 funcsigs==1.0.2
@@ -25,30 +25,30 @@ gunicorn==19.6.0
 idna==2.7
 ipaddress==1.0.22
 kiwisolver==1.0.1
-lml==0.0.1
+lml==0.0.4
 luhn==0.2.0
-lxml==3.7.3
+lxml==4.5.2
 matplotlib==2.2.3
 mockito==1.1.1
 nexmo==2.3.0
-numpy==1.15.2
-pandas==0.23.4
+numpy==1.15.4
+pandas==1.1.3
 phonenumberslite==8.9.14
 Pillow==3.4.2
-psycopg2==2.7.6.1
+psycopg2==2.8.6
 pycparser==2.19
-pyexcel==0.5.3
-pyexcel-io==0.5.9.1
+pyexcel==0.6.4
+pyexcel-io==0.5.19
 pyexcel-webio==0.1.4
-pyexcel-xls==0.5.0
+pyexcel-xls==0.5.9
 PyJWT==1.6.4
 pyparsing==2.2.2
 python-dateutil==2.7.3
 python-docx==0.8.6
-pytz==2016.10
+pytz==2017.2
 qrcode==4.0.4
 requests==2.19.1
-six==1.11.0
+six==1.15.0
 sqlparse==0.2.4
 subprocess32==3.5.2
 text-unidecode==1.2
diff --git a/smash/smash/urls.py b/smash/smash/urls.py
index bf0f4e88..a192a431 100644
--- a/smash/smash/urls.py
+++ b/smash/smash/urls.py
@@ -19,6 +19,8 @@ from django.conf.urls import url, include
 from django.conf.urls.static import static
 from django.contrib import admin
 
+from two_factor.urls import urlpatterns as tf_urls
+
 from web import api_urls
 from web import urls
 
@@ -26,5 +28,5 @@ urlpatterns = [
                   url(r'^admin/', admin.site.urls),
                   url(r'', include(urls)),
                   url(r'^api/', include(api_urls)),
-                  url(r'', include('two_factor.urls', 'two_factor'))
+                  url(r'', include(tf_urls)),
               ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
diff --git a/smash/web/migrations/0120_holiday_kind.py b/smash/web/migrations/0120_holiday_kind.py
index 7f4a8482..cb66217c 100644
--- a/smash/web/migrations/0120_holiday_kind.py
+++ b/smash/web/migrations/0120_holiday_kind.py
@@ -15,6 +15,6 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='holiday',
             name='kind',
-            field=models.CharField(choices=[(b'H', b'Holiday'), (b'X', b'Extra Availability')], default=b'H', max_length=1),
+            field=models.CharField(choices=[(b'H', b'Holiday'), (b'X', b'Extra Availability')], default=b'H', max_length=16),
         ),
     ]
diff --git a/smash/web/models/mail_template.py b/smash/web/models/mail_template.py
index 704870cf..c3d59af6 100644
--- a/smash/web/models/mail_template.py
+++ b/smash/web/models/mail_template.py
@@ -36,12 +36,20 @@ def setlocale(name):
 
 
 def get_formatted_time(time_format):
-    return now.strftime(time_format).decode(date_format_encoding())
+    # TODO: 2TO3 removed string decoding using the locale
+    # Was:
+    # return now.strftime(time_format).decode(date_format_encoding())
+    # Is:
+    return now.strftime(time_format)  # /-->
 
 
 def date_to_str(date, format):
     if date is not None:
-        return date.strftime(format).decode(date_format_encoding())
+        # TODO: 2TO3 removed string decoding using the locale
+        # Was:
+        # return date.strftime(format).decode(date_format_encoding())
+        # Is:
+        return date.strftime(format)  # /-->
     else:
         return ""
 
@@ -243,8 +251,14 @@ class MailTemplate(models.Model):
         if worker is not None:
             email = worker.email
         return {
-            "##DATE_FULL##": current_datetime.strftime(DATE_FORMAT_FULL).decode(date_format_encoding()),
-            "##DATE_SHORT##": current_datetime.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
+            # TODO: 2to3
+            # Was:
+            # "##DATE_FULL##": current_datetime.strftime(DATE_FORMAT_FULL).decode(date_format_encoding()),
+            # "##DATE_SHORT##": current_datetime.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
+            # Is:
+            "##DATE_FULL##": current_datetime.strftime(DATE_FORMAT_FULL),
+            "##DATE_SHORT##": current_datetime.strftime(DATE_FORMAT_SHORT),
+            # /-->
             "##WORKER##": str(worker),
             "##WORKER_EMAIL##": email
         }
@@ -261,12 +275,19 @@ class MailTemplate(models.Model):
             worker_phone_number = ""
             worker_email_address = ""
         if appointment.datetime_when is not None:
-            appointment_date_full = appointment.datetime_when.strftime(DATETIME_FORMAT).decode(
-                date_format_encoding())
-            appointment_date_short = appointment.datetime_when.strftime(DATE_FORMAT_SHORT).decode(
-                date_format_encoding())
-            appointment_date_time = appointment.datetime_when.strftime(DATE_FORMAT_TIME).decode(
-                date_format_encoding())
+            # TODO: 2to3
+            # Was:
+            #appointment_date_full = appointment.datetime_when.strftime(DATETIME_FORMAT).decode(
+            #    date_format_encoding())
+            #appointment_date_short = appointment.datetime_when.strftime(DATE_FORMAT_SHORT).decode(
+            #    date_format_encoding())
+            #appointment_date_time = appointment.datetime_when.strftime(DATE_FORMAT_TIME).decode(
+            #    date_format_encoding())
+            # Is:
+            appointment_date_full = appointment.datetime_when.strftime(DATETIME_FORMAT)
+            appointment_date_short = appointment.datetime_when.strftime(DATE_FORMAT_SHORT)
+            appointment_date_time = appointment.datetime_when.strftime(DATE_FORMAT_TIME)
+            # /-->
         else:
             appointment_date_full = appointment_date_short = appointment_date_time = ""
         return {
@@ -289,11 +310,19 @@ class MailTemplate(models.Model):
     def get_visit_replacements(visit):
         if visit is not None:
             return {
-                "##V_DATE_START_FULL##": visit.datetime_begin.strftime(DATETIME_FORMAT).decode(date_format_encoding()),
-                "##V_DATE_START_SHORT##": visit.datetime_begin.strftime(DATE_FORMAT_SHORT).decode(
-                    date_format_encoding()),
-                "##V_DATE_ENDS_FULL##": visit.datetime_end.strftime(DATETIME_FORMAT).decode(date_format_encoding()),
-                "##V_DATE_ENDS_SHORT##": visit.datetime_end.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
+                # TODO: 2to3
+                # Was:
+                # "##V_DATE_START_FULL##": visit.datetime_begin.strftime(DATETIME_FORMAT).decode(date_format_encoding()),
+                # "##V_DATE_START_SHORT##": visit.datetime_begin.strftime(DATE_FORMAT_SHORT).decode(
+                #    date_format_encoding()),
+                #"##V_DATE_ENDS_FULL##": visit.datetime_end.strftime(DATETIME_FORMAT).decode(date_format_encoding()),
+                #"##V_DATE_ENDS_SHORT##": visit.datetime_end.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
+                # Is:
+                "##V_DATE_START_FULL##": visit.datetime_begin.strftime(DATETIME_FORMAT),
+                "##V_DATE_START_SHORT##": visit.datetime_begin.strftime(DATE_FORMAT_SHORT),
+                "##V_DATE_ENDS_FULL##": visit.datetime_end.strftime(DATETIME_FORMAT),
+                "##V_DATE_ENDS_SHORT##": visit.datetime_end.strftime(DATE_FORMAT_SHORT),
+                # /-->
             }
         return {}
 
@@ -381,9 +410,15 @@ class MailTemplate(models.Model):
                 "##C_NUMBER##": voucher.number,
                 "##C_PATIENT_NAME##": voucher.study_subject.subject.first_name + ' ' + voucher.study_subject.subject.last_name,
                 "##C_VOUCHER_TYPE##": voucher_type,
-                "##C_ISSUE_DATE_SHORT##": voucher.issue_date.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
-                "##C_EXPIRY_START_SHORT##": voucher.expiry_date.strftime(DATE_FORMAT_SHORT).decode(
-                    date_format_encoding()),
+                # TODO: 2to3
+                # Was:
+                # "##C_ISSUE_DATE_SHORT##": voucher.issue_date.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
+                # "##C_EXPIRY_START_SHORT##": voucher.expiry_date.strftime(DATE_FORMAT_SHORT).decode(
+                #    date_format_encoding()),
+                # Is:
+                "##C_ISSUE_DATE_SHORT##": voucher.issue_date.strftime(DATE_FORMAT_SHORT),
+                "##C_EXPIRY_START_SHORT##": voucher.expiry_date.strftime(DATE_FORMAT_SHORT),
+                # /-->
                 "##C_PARTNER_NAME##": voucher.usage_partner.first_name + ' ' + voucher.usage_partner.last_name,
                 "##C_PARTNER_ADDRESS##": voucher.usage_partner.address,
                 "##C_PARTNER_POSTAL_CODE##": voucher.usage_partner.postal_code,
diff --git a/smash/web/urls.py b/smash/web/urls.py
index e8b61fa0..0ab7d504 100644
--- a/smash/web/urls.py
+++ b/smash/web/urls.py
@@ -16,7 +16,7 @@ Including another URLconf
 from django.conf import settings
 from django.conf.urls import include
 from django.conf.urls import url
-from django.contrib.auth.views import logout
+from django.contrib.auth import logout
 from django.views.defaults import page_not_found
 from django.views.generic import TemplateView
 
diff --git a/smash/web/widgets/secure_file_widget.py b/smash/web/widgets/secure_file_widget.py
index c930a764..c268ad4a 100644
--- a/smash/web/widgets/secure_file_widget.py
+++ b/smash/web/widgets/secure_file_widget.py
@@ -1,7 +1,7 @@
 import logging
 
 from django import forms
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.utils.safestring import mark_safe
 from django.utils.translation import ugettext_lazy as _
 
-- 
GitLab