Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 52aeedc

Browse files
schenedxSimon Chen
authored andcommitted
[Feat]: Upgrade django from 2.2 to 3.2
The django library 2.2 LTS is going end of life next year. Move the library to django 3.2 Also, with this upgrade, moved to use edx-api-doc-tools to generate the swagger doc UI at /docs
1 parent 0255f3b commit 52aeedc

16 files changed

Lines changed: 187 additions & 216 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ matrix:
2020
- python: '3.8'
2121
env: TESTNAME=test-python-3.8 TARGETS="PYTHON_ENV=py38 main.test"
2222
- python: '3.8'
23-
env: TESTNAME=test-python-3.8-django-3.0 TARGETS="PYTHON_ENV=py38 DJANGO_VERSION=django30 main.test"
23+
env: TESTNAME=test-python-3.8-django-3.0 TARGETS="PYTHON_ENV=py38 DJANGO_VERSION=django32 main.test"
2424
after_success:
2525
- docker exec analytics_api_testing /edx/app/analytics_api/analytics_api/.travis/run_coverage.sh
2626
- codecov --disable pycov

Makefile

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ COVERAGE_DIR = $(ROOT)/build/coverage
33
PACKAGES = analyticsdataserver analytics_data_api
44
DATABASES = default analytics
55
PYTHON_ENV=py38
6-
DJANGO_VERSION=django22
6+
DJANGO_VERSION=django32
77
.DEFAULT_GOAL := help
88

99
help: ## display this help message
@@ -33,18 +33,7 @@ tox.requirements: ## install tox requirements
3333
develop: test.requirements ## install test and dev requirements
3434
pip3 install -q -r requirements/dev.txt
3535

36-
37-
COMMON_CONSTRAINTS_TXT=requirements/common_constraints.txt
38-
.PHONY: $(COMMON_CONSTRAINTS_TXT)
39-
$(COMMON_CONSTRAINTS_TXT):
40-
wget -O "$(@)" https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt || touch "$(@)"
41-
42-
upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
43-
upgrade: $(COMMON_CONSTRAINTS_TXT) ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
44-
sed 's/pyjwt\[crypto\]<2.0.0//g' requirements/common_constraints.txt > requirements/common_constraints.tmp
45-
mv requirements/common_constraints.tmp requirements/common_constraints.txt
46-
sed 's/edx-drf-extensions<7.0.0//g' requirements/common_constraints.txt > requirements/common_constraints.tmp
47-
mv requirements/common_constraints.tmp requirements/common_constraints.txt
36+
upgrade:
4837
pip3 install -q -r requirements/pip_tools.txt
4938
pip-compile --upgrade -o requirements/pip_tools.txt requirements/pip_tools.in
5039
pip-compile --upgrade -o requirements/base.txt requirements/base.in

analyticsdataserver/settings/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@
245245
'rest_framework.authtoken',
246246
'rest_framework_jwt',
247247
'django_countries',
248-
'rest_framework_swagger',
248+
'drf_yasg',
249+
'edx_api_doc_tools',
249250
'storages',
250251
'enterprise_data',
251252
'rules.apps.AutodiscoverRulesConfig',
@@ -477,3 +478,7 @@
477478
########## ENTERPRISE LEARNER ENGAGEMENT REPORTING
478479
EXCLUDED_ENGAGEMENT_ENTITY_TYPES = [DISCUSSION]
479480
ENGAGEMENT_CACHE_TIMEOUT = 1 * 60 * 60 # 1 hour
481+
482+
########## Django 3.2 upgrade settings
483+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
484+
DEFAULT_HASHING_ALGORITHM = "sha1"

analyticsdataserver/urls.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.conf.urls import include, url
22
from django.contrib import admin
33
from django.views.generic import RedirectView
4+
from edx_api_doc_tools import make_api_info, make_docs_ui_view
45
from rest_framework.authtoken.views import obtain_auth_token
56

67
from analyticsdataserver import views
@@ -9,19 +10,30 @@
910
admin.site.site_title = admin.site.site_header
1011

1112
urlpatterns = [
12-
url(r'^$', RedirectView.as_view(url='/docs')), # pylint: disable=no-value-for-parameter
13-
1413
url(r'^api-auth/', include('rest_framework.urls', 'rest_framework')),
1514
url(r'^api-token-auth/', obtain_auth_token),
1615

1716
url(r'^api/', include('analytics_data_api.urls')),
18-
url(r'^docs/', views.SwaggerSchemaView.as_view()),
1917
url(r'^status/$', views.StatusView.as_view(), name='status'),
2018
url(r'^authenticated/$', views.AuthenticationTestView.as_view(), name='authenticated'),
2119
url(r'^health/$', views.HealthView.as_view(), name='health'),
2220
]
2321

2422
urlpatterns.append(url(r'', include('enterprise_data.urls')))
2523

24+
api_ui_view = make_docs_ui_view(
25+
api_info=make_api_info(
26+
title="edX Analytics Data API",
27+
version="v0",
28+
email="program-cosmonauts@edx.org"
29+
),
30+
api_url_patterns=urlpatterns
31+
)
32+
33+
urlpatterns += [
34+
url(r'^docs/$', api_ui_view, name='api-docs'),
35+
url(r'^$', RedirectView.as_view(url='/docs')), # pylint: disable=no-value-for-parameter
36+
]
37+
2638
handler500 = 'analyticsdataserver.views.handle_internal_server_error' # pylint: disable=invalid-name
2739
handler404 = 'analyticsdataserver.views.handle_missing_resource_error' # pylint: disable=invalid-name

analyticsdataserver/views.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
from django.conf import settings
44
from django.db import connections
55
from django.http import HttpResponse
6-
from rest_framework import permissions, schemas
7-
from rest_framework.permissions import AllowAny
6+
from rest_framework import permissions
87
from rest_framework.renderers import JSONRenderer
98
from rest_framework.response import Response
109
from rest_framework.views import APIView
11-
from rest_framework_swagger.renderers import OpenAPIRenderer, SwaggerUIRenderer
1210

1311
logger = logging.getLogger(__name__)
1412

@@ -33,21 +31,6 @@ def _handle_error(status_code):
3331
return HttpResponse(renderer.render(info), content_type=content_type, status=status_code)
3432

3533

36-
class SwaggerSchemaView(APIView):
37-
"""
38-
Renders the swagger schema for the documentation regardless of permissions.
39-
"""
40-
permission_classes = [AllowAny]
41-
renderer_classes = [
42-
OpenAPIRenderer,
43-
SwaggerUIRenderer
44-
]
45-
46-
def get(self, _request):
47-
generator = schemas.SchemaGenerator(title='Analytics API')
48-
return Response(generator.get_schema())
49-
50-
5134
class StatusView(APIView):
5235
"""
5336
Simple check to determine if the server is alive

requirements/base.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
-c constraints.txt
44

5+
edx-api-doc-tools
56
boto==2.42.0 # MIT
67
boto3
8+
coreapi
79
Django # BSD License
810
django-countries # MIT
911
python-memcached # Python Software Foundation License v2
1012
djangorestframework # BSD
11-
django-rest-swagger # BSD
1213
djangorestframework-csv # BSD
1314
django-storages # BSD
1415
elasticsearch-dsl # Apache 2.0
1516
ordered-set # MIT
1617
tqdm # MIT
1718
urllib3 # MIT
18-
Markdown==2.6.6 # BSD:markdown is used by swagger for rendering the api docs
19+
Markdown # BSD:markdown is used by swagger for rendering the api docs
1920
edx-ccx-keys
2021
edx-django-release-util
2122
edx-opaque-keys

requirements/base.txt

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# make upgrade
66
#
7+
asgiref==3.4.1
8+
# via django
79
boto==2.42.0
810
# via -r requirements/base.in
911
boto3==1.18.21
@@ -22,17 +24,18 @@ charset-normalizer==2.0.4
2224
# via requests
2325
coreapi==2.3.3
2426
# via
25-
# django-rest-swagger
26-
# openapi-codec
27+
# -r requirements/base.in
28+
# drf-yasg
2729
coreschema==0.0.4
28-
# via coreapi
30+
# via
31+
# coreapi
32+
# drf-yasg
2933
cryptography==3.4.7
3034
# via
3135
# django-fernet-fields
3236
# pyjwt
33-
django==2.2.24
37+
django==3.2.6
3438
# via
35-
# -c requirements/common_constraints.txt
3639
# -r requirements/base.in
3740
# django-cors-headers
3841
# django-crum
@@ -41,6 +44,8 @@ django==2.2.24
4144
# django-storages
4245
# djangorestframework
4346
# drf-jwt
47+
# drf-yasg
48+
# edx-api-doc-tools
4449
# edx-django-release-util
4550
# edx-django-utils
4651
# edx-drf-extensions
@@ -61,8 +66,6 @@ django-model-utils==4.1.1
6166
# via
6267
# edx-enterprise-data
6368
# edx-rbac
64-
django-rest-swagger==2.2.0
65-
# via -r requirements/base.in
6669
django-storages==1.8
6770
# via
6871
# -c requirements/constraints.txt
@@ -74,17 +77,20 @@ django-waffle==2.2.1
7477
djangorestframework==3.12.4
7578
# via
7679
# -r requirements/base.in
77-
# django-rest-swagger
7880
# djangorestframework-csv
7981
# drf-jwt
82+
# drf-yasg
83+
# edx-api-doc-tools
8084
# edx-drf-extensions
8185
# rest-condition
8286
djangorestframework-csv==2.1.1
8387
# via -r requirements/base.in
84-
drf-jwt==1.19.0
85-
# via
86-
# -c requirements/common_constraints.txt
87-
# edx-drf-extensions
88+
drf-jwt==1.19.1
89+
# via edx-drf-extensions
90+
drf-yasg==1.20.0
91+
# via edx-api-doc-tools
92+
edx-api-doc-tools==1.4.3
93+
# via -r requirements/base.in
8894
edx-ccx-keys==1.2.1
8995
# via -r requirements/base.in
9096
edx-django-release-util==1.1.0
@@ -126,6 +132,8 @@ future==0.18.2
126132
# via pyjwkest
127133
idna==3.2
128134
# via requests
135+
inflection==0.5.1
136+
# via drf-yasg
129137
itypes==1.2.0
130138
# via coreapi
131139
jinja2==3.0.1
@@ -134,18 +142,18 @@ jmespath==0.10.0
134142
# via
135143
# boto3
136144
# botocore
137-
markdown==2.6.6
145+
markdown==3.3.4
138146
# via -r requirements/base.in
139147
markupsafe==2.0.1
140148
# via jinja2
141149
newrelic==6.8.0.163
142150
# via edx-django-utils
143-
openapi-codec==1.3.2
144-
# via django-rest-swagger
145151
ordered-set==3.1.1
146152
# via
147153
# -c requirements/constraints.txt
148154
# -r requirements/base.in
155+
packaging==21.0
156+
# via drf-yasg
149157
pbr==5.6.0
150158
# via stevedore
151159
psutil==5.8.0
@@ -163,6 +171,8 @@ pyjwt[crypto]==2.1.0
163171
# edx-rest-api-client
164172
pymongo==3.12.0
165173
# via edx-opaque-keys
174+
pyparsing==2.4.7
175+
# via packaging
166176
python-dateutil==2.8.2
167177
# via
168178
# botocore
@@ -184,14 +194,16 @@ requests==2.26.0
184194
# slumber
185195
rest-condition==1.0.3
186196
# via edx-drf-extensions
197+
ruamel.yaml==0.17.10
198+
# via drf-yasg
199+
ruamel.yaml.clib==0.2.6
200+
# via ruamel.yaml
187201
rules==3.0
188202
# via edx-enterprise-data
189203
s3transfer==0.5.0
190204
# via boto3
191205
semantic-version==2.8.5
192206
# via edx-drf-extensions
193-
simplejson==3.17.3
194-
# via django-rest-swagger
195207
six==1.16.0
196208
# via
197209
# djangorestframework-csv
@@ -216,7 +228,9 @@ tqdm==4.62.0
216228
unicodecsv==0.14.1
217229
# via djangorestframework-csv
218230
uritemplate==3.0.1
219-
# via coreapi
231+
# via
232+
# coreapi
233+
# drf-yasg
220234
urllib3==1.26.6
221235
# via
222236
# -r requirements/base.in

requirements/common_constraints.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

requirements/constraints.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
# link to other information that will help people in the future to remove the
88
# pin when possible. Writing an issue against the offending project and
99
# linking to it here is good.
10-
11-
# copy/paste all pins from upstream link. It gives us option to override any pin.
12-
# otherwise pip-tools gives conflicting errors.
13-
-c common_constraints.txt
14-
10+
1511
# TODO: Many pinned dependencies should be unpinned and/or moved to this constraints file.
1612

1713
# django-storages version 1.9 drops support for boto storage backend.

0 commit comments

Comments
 (0)