From 01982480171f8876a058db293e05aa635e7e6e33 Mon Sep 17 00:00:00 2001 From: Naramsim Date: Wed, 21 Jan 2026 11:19:57 +0100 Subject: [PATCH] feat: upgrade to django 5 --- config/docker-compose.py | 4 +--- config/docker.py | 2 +- config/local.py | 2 +- config/settings.py | 28 +++++++++------------------- config/wsgi.py | 27 +++++---------------------- manage.py | 19 ++++++++++++++++--- requirements.txt | 5 +---- 7 files changed, 34 insertions(+), 53 deletions(-) diff --git a/config/docker-compose.py b/config/docker-compose.py index 896854be6..158a698ed 100644 --- a/config/docker-compose.py +++ b/config/docker-compose.py @@ -4,7 +4,7 @@ DATABASES = { "default": { - "ENGINE": "django.db.backends.postgresql_psycopg2", + "ENGINE": "django.db.backends.postgresql", "NAME": os.environ.get("POSTGRES_DB", "pokeapi"), "USER": os.environ.get("POSTGRES_USER", "ash"), "PASSWORD": os.environ.get("POSTGRES_PASSWORD", "pokemon"), @@ -23,6 +23,4 @@ } } -DEBUG = False - ALLOWED_HOSTS = ["*"] diff --git a/config/docker.py b/config/docker.py index 663974929..e8be3ed0f 100755 --- a/config/docker.py +++ b/config/docker.py @@ -3,7 +3,7 @@ DATABASES = { "default": { - "ENGINE": "django.db.backends.postgresql_psycopg2", + "ENGINE": "django.db.backends.postgresql", "NAME": "pokeapi", "USER": "ash", "PASSWORD": "pokemon", diff --git a/config/local.py b/config/local.py index 42f070e38..d181da646 100755 --- a/config/local.py +++ b/config/local.py @@ -3,7 +3,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(PROJECT_ROOT, "db.sqlite3"), + "NAME": BASE_DIR / "db.sqlite3", } } diff --git a/config/settings.py b/config/settings.py index 5275a5ab6..d97e490fd 100755 --- a/config/settings.py +++ b/config/settings.py @@ -1,16 +1,14 @@ # Production settings import os -from unipath import Path +from pathlib import Path -PROJECT_ROOT = Path(__file__).ancestor(2) +BASE_DIR = Path(__file__).resolve().parent.parent DEBUG = False TEMPLATE_DEBUG = DEBUG -ADMINS = ( - os.environ.get("ADMINS", "Paul Hallett,paulandrewhallett@gmail.com").split(","), -) +ADMINS = (os.environ.get("ADMINS", "admin,admin@noemail.com").split(","),) EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" @@ -18,17 +16,15 @@ BASE_URL = os.environ.get("BASE_URL", "http://pokeapi.co") -# Hosts/domain names that are valid for this site; required if DEBUG is False -# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts ALLOWED_HOSTS = [ os.environ.get("ALLOWED_HOSTS", ".pokeapi.co"), "localhost", "127.0.0.1", ] -TIME_ZONE = os.environ.get("TIME_ZONE", "Europe/London") +TIME_ZONE = os.environ.get("TIME_ZONE", "UTC") -LANGUAGE_CODE = os.environ.get("LANGUAGE_CODE", "en-gb") +LANGUAGE_CODE = os.environ.get("LANGUAGE_CODE", "en-us") SITE_ID = 1 @@ -82,28 +78,23 @@ } SECRET_KEY = os.environ.get( - "SECRET_KEY", "ubx+22!jbo(^x2_scm-o$*py3e@-awu-n^hipkm%2l$sw$&2l#" + "SECRET_KEY", "django-insecure-a(!_5+l3$#l1f4n!x+&ns_+8$4q@df*3rh$n#2h@l$2gti7!7-" ) CUSTOM_APPS = ("pokemon_v2",) INSTALLED_APPS = ( + "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", - "django.contrib.sites", - "django.contrib.admin", "django.contrib.messages", - "django.contrib.humanize", "corsheaders", "rest_framework", "cachalot", "drf_spectacular", ) + CUSTOM_APPS - -API_LIMIT_PER_PAGE = 1 - CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_METHODS = "GET" @@ -127,7 +118,6 @@ "APP_DIRS": True, "OPTIONS": { "context_processors": [ - "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", @@ -136,7 +126,7 @@ }, ] -DEFAULT_AUTO_FIELD = "django.db.models.AutoField" +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" SPECTACULAR_SETTINGS = { "TITLE": "PokéAPI", @@ -154,7 +144,7 @@ This API will always be publicly available and will never require any extensive setup process to consume. -Created by [**Paul Hallett**](https://github.com/phalt) and other [**PokéAPI contributors***](https://github.com/PokeAPI/pokeapi#contributing) around the world. Pokémon and Pokémon character names are trademarks of Nintendo. +Created by [**Paul Hallett**](https://github.com/phalt) and other [**PokéAPI contributors**](https://github.com/PokeAPI/pokeapi#contributing) around the world. Pokémon and Pokémon character names are trademarks of Nintendo. """, "SORT_OPERATIONS": False, "SERVERS": [{"url": "https://pokeapi.co"}], diff --git a/config/wsgi.py b/config/wsgi.py index 7ec196310..5526cb895 100755 --- a/config/wsgi.py +++ b/config/wsgi.py @@ -1,33 +1,16 @@ """ -WSGI config for project. +WSGI config for mysite project. -This module contains the WSGI application used by Django's development server -and any production WSGI deployments. It should expose a module-level variable -named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover -this application via the ``WSGI_APPLICATION`` setting. - -Usually you will have the standard Django WSGI application here, but it also -might make sense to replace the whole Django WSGI application with a custom one -that later delegates to the Django one. For example, you could introduce WSGI -middleware here, or combine a Django application with an application of another -framework. +It exposes the WSGI callable as a module-level variable named ``application``. +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ """ 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 -# mod_wsgi daemon mode with each site in its own daemon process, or use -# os.environ["DJANGO_SETTINGS_MODULE"] = ".settings" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.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. application = get_wsgi_application() - -# Apply WSGI middleware here. -# from helloworld.wsgi import HelloWorldApplication -# application = HelloWorldApplication(application) diff --git a/manage.py b/manage.py index 5ec273e19..aabb81818 100755 --- a/manage.py +++ b/manage.py @@ -1,10 +1,23 @@ #!/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", "config.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) - from django.core.management import execute_from_command_line - execute_from_command_line(sys.argv) +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt index 30b70bded..c67da81c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ -Django==4.2.27 -Unipath==1.1 +Django==5.2.10 coverage==7.13.1 django-cors-headers==4.9.0 django-redis==6.0.0 @@ -7,7 +6,5 @@ django-cachalot==2.8.0 djangorestframework==3.16.1 gunicorn==23.0.0 psycopg[binary]==3.3.2 -python-dateutil==2.9.0 -python-mimeparse==2.0.0 drf-spectacular==0.29.0 legacy-cgi; python_version >= '3.13'