From a5ed9533175b5981bae22890f762936414886a76 Mon Sep 17 00:00:00 2001
From: Marco Frailis <marco.frailis@inaf.it>
Date: Tue, 25 Oct 2022 11:58:54 +0200
Subject: [PATCH] Updating django_euclid example to a more recent django
 framework

---
 django_example_euclid/README.md               |  6 +--
 .../euclid_example/settings.py                | 38 ++++++++++---------
 django_example_euclid/euclid_example/urls.py  |  2 +-
 django_example_euclid/euclid_example/wsgi.py  |  2 +-
 django_example_euclid/imagedb/admin.py        |  2 +
 django_example_euclid/imagedb/apps.py         |  1 +
 django_example_euclid/imagedb/models.py       | 12 ------
 django_example_euclid/imagedb/urls.py         |  4 +-
 django_example_euclid/imagedb/views.py        |  6 ++-
 django_example_euclid/manage.py               |  9 ++++-
 django_example_insurance/README.md            |  3 +-
 11 files changed, 43 insertions(+), 42 deletions(-)

diff --git a/django_example_euclid/README.md b/django_example_euclid/README.md
index 256a0db..191cd6d 100644
--- a/django_example_euclid/README.md
+++ b/django_example_euclid/README.md
@@ -2,16 +2,16 @@
 
 Create the anaconda environment for this example
 
-    conda create -n euclid_example django
+    conda create -n orm_django django
 
 To activate this environment, use
 
-    conda activate euclid_example
+    conda activate orm_django
 
 Additional packages are needed, not available in Anaconda but installed with the `pip` command
 
     pip install django-extensions djangorestframework
-    pip install django-composite-field django-url-filter
+    pip install django-composite-field django-ufilter
 
 To deactivate an active environment, use
 
diff --git a/django_example_euclid/euclid_example/settings.py b/django_example_euclid/euclid_example/settings.py
index fea55f8..c4e7d2c 100644
--- a/django_example_euclid/euclid_example/settings.py
+++ b/django_example_euclid/euclid_example/settings.py
@@ -1,26 +1,26 @@
 """
 Django settings for euclid_example project.
 
-Generated by 'django-admin startproject' using Django 2.1.1.
+Generated by 'django-admin startproject' using Django 4.1.
 
 For more information on this file, see
-https://docs.djangoproject.com/en/2.1/topics/settings/
+https://docs.djangoproject.com/en/4.1/topics/settings/
 
 For the full list of settings and their values, see
-https://docs.djangoproject.com/en/2.1/ref/settings/
+https://docs.djangoproject.com/en/4.1/ref/settings/
 """
 
-import os
+from pathlib import Path
 
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
 
 
 # Quick-start development settings - unsuitable for production
-# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
+# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = '5yu24^zybby@-q_x%ry-nit^!%o8oc2oxmos7d3_d@hf(+qo5k'
+SECRET_KEY = 'django-insecure-b=h18+$p+el@nqc+7lb7r^b+@xuo26ip92)pd=-=kjiyty&f@%'
 
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
@@ -40,12 +40,13 @@ INSTALLED_APPS = [
     'django_extensions',
     'imagedb',
     'rest_framework',
-    'url_filter',
+    'django_ufilter',
 ]
 
+
 REST_FRAMEWORK = {
     'DEFAULT_FILTER_BACKENDS': [
-        'url_filter.integrations.drf.DjangoFilterBackend',
+        'django_ufilter.integrations.drf.DRFFilterBackend',
     ]
 }
 
@@ -81,18 +82,18 @@ WSGI_APPLICATION = 'euclid_example.wsgi.application'
 
 
 # Database
-# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
+# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
 
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+        'NAME': BASE_DIR / 'db.sqlite3',
     }
 }
 
 
 # Password validation
-# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
+# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
 
 AUTH_PASSWORD_VALIDATORS = [
     {
@@ -111,7 +112,7 @@ AUTH_PASSWORD_VALIDATORS = [
 
 
 # Internationalization
-# https://docs.djangoproject.com/en/2.1/topics/i18n/
+# https://docs.djangoproject.com/en/4.1/topics/i18n/
 
 LANGUAGE_CODE = 'en-us'
 
@@ -119,14 +120,15 @@ TIME_ZONE = 'UTC'
 
 USE_I18N = True
 
-USE_L10N = True
-
 USE_TZ = False
 
 
 # Static files (CSS, JavaScript, Images)
-# https://docs.djangoproject.com/en/2.1/howto/static-files/
+# https://docs.djangoproject.com/en/4.1/howto/static-files/
+
+STATIC_URL = 'static/'
 
-STATIC_URL = '/static/'
+# Default primary key field type
+# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
 
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
diff --git a/django_example_euclid/euclid_example/urls.py b/django_example_euclid/euclid_example/urls.py
index 1514eb7..8c2b33b 100644
--- a/django_example_euclid/euclid_example/urls.py
+++ b/django_example_euclid/euclid_example/urls.py
@@ -1,7 +1,7 @@
 """euclid_example URL Configuration
 
 The `urlpatterns` list routes URLs to views. For more information please see:
-    https://docs.djangoproject.com/en/2.1/topics/http/urls/
+    https://docs.djangoproject.com/en/4.1/topics/http/urls/
 Examples:
 Function views
     1. Add an import:  from my_app import views
diff --git a/django_example_euclid/euclid_example/wsgi.py b/django_example_euclid/euclid_example/wsgi.py
index 0f490d7..28765b4 100644
--- a/django_example_euclid/euclid_example/wsgi.py
+++ b/django_example_euclid/euclid_example/wsgi.py
@@ -4,7 +4,7 @@ WSGI config for euclid_example project.
 It exposes the WSGI callable as a module-level variable named ``application``.
 
 For more information on this file, see
-https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
+https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
 """
 
 import os
diff --git a/django_example_euclid/imagedb/admin.py b/django_example_euclid/imagedb/admin.py
index 0b5aa36..1447de1 100644
--- a/django_example_euclid/imagedb/admin.py
+++ b/django_example_euclid/imagedb/admin.py
@@ -1,5 +1,7 @@
 from django.contrib import admin
 
+# Register your models here.
+
 from .models import(Instrument, NispDetector, Astrometry, DataContainer, 
                     NispRawFrame)
 
diff --git a/django_example_euclid/imagedb/apps.py b/django_example_euclid/imagedb/apps.py
index 044a53a..12b4df9 100644
--- a/django_example_euclid/imagedb/apps.py
+++ b/django_example_euclid/imagedb/apps.py
@@ -2,4 +2,5 @@ from django.apps import AppConfig
 
 
 class ImagedbConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
     name = 'imagedb'
diff --git a/django_example_euclid/imagedb/models.py b/django_example_euclid/imagedb/models.py
index 7bd48b6..5e81703 100644
--- a/django_example_euclid/imagedb/models.py
+++ b/django_example_euclid/imagedb/models.py
@@ -1,10 +1,8 @@
-
 from django.db import models
 from composite_field import CompositeField
 
 # Create your models here.
 
-
 IMAGE_CATEGORY = (
   'SCIENCE',
   'CALIBRATION',
@@ -212,13 +210,3 @@ class NispRawFrame(ImageSpaceFrame):
                                    on_delete=models.CASCADE)
   
 
-
-
-
-
-  
-  
-  
-  
-  
-  
diff --git a/django_example_euclid/imagedb/urls.py b/django_example_euclid/imagedb/urls.py
index 50f0483..271c85c 100644
--- a/django_example_euclid/imagedb/urls.py
+++ b/django_example_euclid/imagedb/urls.py
@@ -1,4 +1,4 @@
-from django.conf.urls import url, include
+from django.urls import re_path, include
 from rest_framework.routers import DefaultRouter
 
 from imagedb import views
@@ -9,5 +9,5 @@ router.register(r'nisprawframes', views.NispRawFrameViewSet)
 router.register(r'nispdetectors', views.NispDetectorViewSet)
 
 urlpatterns = [
-  url(r'^', include(router.urls))
+  re_path(r'^', include(router.urls))
 ]
diff --git a/django_example_euclid/imagedb/views.py b/django_example_euclid/imagedb/views.py
index 1023113..55f20d2 100644
--- a/django_example_euclid/imagedb/views.py
+++ b/django_example_euclid/imagedb/views.py
@@ -1,8 +1,11 @@
+from django.shortcuts import render
+
+# Create your views here.
 
 from rest_framework import viewsets
 from imagedb.serializers import InstrumentSerializer, NispDetectorSerializer, NispRawFrameSerializer
 from imagedb.models import Instrument, NispDetector, NispRawFrame
-from url_filter.filtersets import ModelFilterSet
+from django_ufilter.filtersets import ModelFilterSet
 
 
 class InstrumentViewSet(viewsets.ReadOnlyModelViewSet):
@@ -29,4 +32,3 @@ class NispRawFrameViewSet(viewsets.ReadOnlyModelViewSet):
   
 
 
-
diff --git a/django_example_euclid/manage.py b/django_example_euclid/manage.py
index 09333b0..7d9fbe4 100755
--- a/django_example_euclid/manage.py
+++ b/django_example_euclid/manage.py
@@ -1,8 +1,11 @@
 #!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
 import os
 import sys
 
-if __name__ == '__main__':
+
+def main():
+    """Run administrative tasks."""
     os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'euclid_example.settings')
     try:
         from django.core.management import execute_from_command_line
@@ -13,3 +16,7 @@ if __name__ == '__main__':
             "forget to activate a virtual environment?"
         ) from exc
     execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/django_example_insurance/README.md b/django_example_insurance/README.md
index 790e976..43b807c 100644
--- a/django_example_insurance/README.md
+++ b/django_example_insurance/README.md
@@ -10,8 +10,7 @@ To activate this environment, use
 
 Additional packages are needed, not available in Anaconda but installed with the `pip` command
 
-    pip install django-extensions djangorestframework
-    pip install django-composite-field django-url-filter
+    pip install django-extensions
     pip install django-phonenumber-field phonenumbers
     pip install Pillow
 
-- 
GitLab