From 4f3f3b076f354d0fd418a10156502570732cf582 Mon Sep 17 00:00:00 2001 From: zubairshakoorarbisoft Date: Fri, 8 Sep 2023 19:14:53 +0500 Subject: [PATCH] fix: Added support for Django42 --- .github/workflows/ci.yml | 7 ++++++- .travis/run_tests.sh | 1 - Makefile | 4 ++-- notesapi/urls.py | 4 ++-- notesapi/v1/permissions.py | 2 +- notesapi/v1/urls.py | 10 +++++----- notesapi/v1/views.py | 2 +- notesserver/urls.py | 14 +++++++------- tox.ini | 13 +++++++------ 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a074c4d1..39c68ddc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,13 @@ jobs: max-parallel: 4 matrix: python-version: ['py38'] - django-version: ['django32'] + django-version: ['django32', 'django42'] db-version: ['mysql57', 'mysql80'] + # excluding mysql5.7 with Django 4.2 since Django 4.2 has + # dropped support for MySQL<8 + exclude: + - django-version: 'django42' + db-version: 'mysql57' steps: - uses: actions/checkout@v2 diff --git a/.travis/run_tests.sh b/.travis/run_tests.sh index 501899af..b112c68c 100755 --- a/.travis/run_tests.sh +++ b/.travis/run_tests.sh @@ -5,4 +5,3 @@ export DJANGO_SETTINGS_MODULE=notesserver.settings.test cd /edx/app/edx_notes_api/edx_notes_api make validate - diff --git a/Makefile b/Makefile index 1d9148fb..cd8500d9 100644 --- a/Makefile +++ b/Makefile @@ -57,10 +57,10 @@ static: # provide the static target for devstack's tooling. requirements: pip install -q -r requirements/base.txt --exists-action=w -test.requirements: requirements +test.requirements: pip install -q -r requirements/test.txt --exists-action=w -develop: test.requirements +develop: requirements test.requirements piptools: ## install pinned version of pip-compile and pip-sync pip install -r requirements/pip-tools.txt diff --git a/notesapi/urls.py b/notesapi/urls.py index ffdfb316..2f2bb769 100644 --- a/notesapi/urls.py +++ b/notesapi/urls.py @@ -1,7 +1,7 @@ -from django.conf.urls import include, url +from django.urls import include, path app_name = "notesapi.v1" urlpatterns = [ - url(r'^v1/', include('notesapi.v1.urls', namespace='v1')), + path('v1/', include('notesapi.v1.urls', namespace='v1')), ] diff --git a/notesapi/v1/permissions.py b/notesapi/v1/permissions.py index af816aa7..d975d78e 100644 --- a/notesapi/v1/permissions.py +++ b/notesapi/v1/permissions.py @@ -33,7 +33,7 @@ class HasAccessToken(BasePermission): def has_permission(self, request, view): if getattr(settings, 'DISABLE_TOKEN_CHECK', False): return True - token = request.META.get('HTTP_X_ANNOTATOR_AUTH_TOKEN', '') + token = request.headers.get('x-annotator-auth-token', '') if not token: logger.debug("No token found in headers") return False diff --git a/notesapi/v1/urls.py b/notesapi/v1/urls.py index 515ea87d..543ba7a7 100644 --- a/notesapi/v1/urls.py +++ b/notesapi/v1/urls.py @@ -1,15 +1,15 @@ -from django.conf.urls import url +from django.urls import path, re_path from notesapi.v1.views import (AnnotationDetailView, AnnotationListView, AnnotationRetireView, AnnotationSearchView) app_name = "notesapi.v1" urlpatterns = [ - url(r'^annotations/$', AnnotationListView.as_view(), name='annotations'), - url(r'^retire_annotations/$', AnnotationRetireView.as_view(), name='annotations_retire'), - url( + path('annotations/', AnnotationListView.as_view(), name='annotations'), + path('retire_annotations/', AnnotationRetireView.as_view(), name='annotations_retire'), + re_path( r'^annotations/(?P[a-zA-Z0-9_-]+)/?$', AnnotationDetailView.as_view(), name='annotations_detail' ), - url(r'^search/$', AnnotationSearchView.as_view(), name='annotations_search'), + path('search/', AnnotationSearchView.as_view(), name='annotations_search'), ] diff --git a/notesapi/v1/views.py b/notesapi/v1/views.py index ef883ef8..4877990a 100644 --- a/notesapi/v1/views.py +++ b/notesapi/v1/views.py @@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError from django.db.models import Q from django.urls import reverse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework import status from rest_framework.generics import GenericAPIView, ListAPIView from rest_framework.response import Response diff --git a/notesserver/urls.py b/notesserver/urls.py index fb3d2993..51e5e8e1 100644 --- a/notesserver/urls.py +++ b/notesserver/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import include, url +from django.urls import include, path, re_path from drf_yasg.views import get_schema_view from drf_yasg import openapi from rest_framework import permissions @@ -16,10 +16,10 @@ ) urlpatterns = [ - url(r'^heartbeat/$', notesserver.views.heartbeat, name='heartbeat'), - url(r'^selftest/$', notesserver.views.selftest, name='selftest'), - url(r'^robots.txt$', notesserver.views.robots, name='robots'), - url(r'^$', notesserver.views.root, name='root'), - url(r'^api/', include('notesapi.urls', namespace='api')), - url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + path('heartbeat/', notesserver.views.heartbeat, name='heartbeat'), + path('selftest/', notesserver.views.selftest, name='selftest'), + re_path(r'^robots.txt$', notesserver.views.robots, name='robots'), + path('', notesserver.views.root, name='root'), + path('api/', include('notesapi.urls', namespace='api')), + path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), ] diff --git a/tox.ini b/tox.ini index 8d72a0c2..193a8372 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,13 @@ [tox] -envlist = py38-django{32} +envlist = py38-django{32, 42} skipsdist = true [testenv] -deps = - django32: -r requirements/django.txt +deps = + django32: Django>=3.2,<4.0 + django42: Django>=4.2,<4.3 -r {toxinidir}/requirements/test.txt -passenv = +passenv = CONN_MAX_AGE DB_ENGINE DB_HOST @@ -16,7 +17,7 @@ passenv = DB_USER ENABLE_DJANGO_TOOLBAR ELASTICSEARCH_URL -whitelist_externals = +whitelist_externals = make -commands = +commands = make validate