Skip to content
Snippets Groups Projects
Commit a5ed9533 authored by Marco Frailis's avatar Marco Frailis
Browse files

Updating django_euclid example to a more recent django framework

parent e1eef6f8
No related branches found
No related tags found
No related merge requests found
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
Create the anaconda environment for this example Create the anaconda environment for this example
conda create -n euclid_example django conda create -n orm_django django
To activate this environment, use 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 Additional packages are needed, not available in Anaconda but installed with the `pip` command
pip install django-extensions djangorestframework 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 To deactivate an active environment, use
......
""" """
Django settings for euclid_example project. 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 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 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, ...) # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production # 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! # 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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
...@@ -40,12 +40,13 @@ INSTALLED_APPS = [ ...@@ -40,12 +40,13 @@ INSTALLED_APPS = [
'django_extensions', 'django_extensions',
'imagedb', 'imagedb',
'rest_framework', 'rest_framework',
'url_filter', 'django_ufilter',
] ]
REST_FRAMEWORK = { REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': [ 'DEFAULT_FILTER_BACKENDS': [
'url_filter.integrations.drf.DjangoFilterBackend', 'django_ufilter.integrations.drf.DRFFilterBackend',
] ]
} }
...@@ -81,18 +82,18 @@ WSGI_APPLICATION = 'euclid_example.wsgi.application' ...@@ -81,18 +82,18 @@ WSGI_APPLICATION = 'euclid_example.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases # https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 'NAME': BASE_DIR / 'db.sqlite3',
} }
} }
# Password validation # 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 = [ AUTH_PASSWORD_VALIDATORS = [
{ {
...@@ -111,7 +112,7 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -111,7 +112,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
...@@ -119,14 +120,15 @@ TIME_ZONE = 'UTC' ...@@ -119,14 +120,15 @@ TIME_ZONE = 'UTC'
USE_I18N = True USE_I18N = True
USE_L10N = True
USE_TZ = False USE_TZ = False
# Static files (CSS, JavaScript, Images) # 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' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
"""euclid_example URL Configuration """euclid_example URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see: 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: Examples:
Function views Function views
1. Add an import: from my_app import views 1. Add an import: from my_app import views
......
...@@ -4,7 +4,7 @@ WSGI config for euclid_example project. ...@@ -4,7 +4,7 @@ WSGI config for euclid_example project.
It exposes the WSGI callable as a module-level variable named ``application``. It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see 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 import os
......
from django.contrib import admin from django.contrib import admin
# Register your models here.
from .models import(Instrument, NispDetector, Astrometry, DataContainer, from .models import(Instrument, NispDetector, Astrometry, DataContainer,
NispRawFrame) NispRawFrame)
......
...@@ -2,4 +2,5 @@ from django.apps import AppConfig ...@@ -2,4 +2,5 @@ from django.apps import AppConfig
class ImagedbConfig(AppConfig): class ImagedbConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'imagedb' name = 'imagedb'
from django.db import models from django.db import models
from composite_field import CompositeField from composite_field import CompositeField
# Create your models here. # Create your models here.
IMAGE_CATEGORY = ( IMAGE_CATEGORY = (
'SCIENCE', 'SCIENCE',
'CALIBRATION', 'CALIBRATION',
...@@ -212,13 +210,3 @@ class NispRawFrame(ImageSpaceFrame): ...@@ -212,13 +210,3 @@ class NispRawFrame(ImageSpaceFrame):
on_delete=models.CASCADE) on_delete=models.CASCADE)
from django.conf.urls import url, include from django.urls import re_path, include
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from imagedb import views from imagedb import views
...@@ -9,5 +9,5 @@ router.register(r'nisprawframes', views.NispRawFrameViewSet) ...@@ -9,5 +9,5 @@ router.register(r'nisprawframes', views.NispRawFrameViewSet)
router.register(r'nispdetectors', views.NispDetectorViewSet) router.register(r'nispdetectors', views.NispDetectorViewSet)
urlpatterns = [ urlpatterns = [
url(r'^', include(router.urls)) re_path(r'^', include(router.urls))
] ]
from django.shortcuts import render
# Create your views here.
from rest_framework import viewsets from rest_framework import viewsets
from imagedb.serializers import InstrumentSerializer, NispDetectorSerializer, NispRawFrameSerializer from imagedb.serializers import InstrumentSerializer, NispDetectorSerializer, NispRawFrameSerializer
from imagedb.models import Instrument, NispDetector, NispRawFrame from imagedb.models import Instrument, NispDetector, NispRawFrame
from url_filter.filtersets import ModelFilterSet from django_ufilter.filtersets import ModelFilterSet
class InstrumentViewSet(viewsets.ReadOnlyModelViewSet): class InstrumentViewSet(viewsets.ReadOnlyModelViewSet):
...@@ -29,4 +32,3 @@ class NispRawFrameViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -29,4 +32,3 @@ class NispRawFrameViewSet(viewsets.ReadOnlyModelViewSet):
#!/usr/bin/env python #!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os import os
import sys import sys
if __name__ == '__main__':
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'euclid_example.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'euclid_example.settings')
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
...@@ -13,3 +16,7 @@ if __name__ == '__main__': ...@@ -13,3 +16,7 @@ if __name__ == '__main__':
"forget to activate a virtual environment?" "forget to activate a virtual environment?"
) from exc ) from exc
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
...@@ -10,8 +10,7 @@ To activate this environment, use ...@@ -10,8 +10,7 @@ To activate this environment, use
Additional packages are needed, not available in Anaconda but installed with the `pip` command Additional packages are needed, not available in Anaconda but installed with the `pip` command
pip install django-extensions djangorestframework pip install django-extensions
pip install django-composite-field django-url-filter
pip install django-phonenumber-field phonenumbers pip install django-phonenumber-field phonenumbers
pip install Pillow pip install Pillow
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment