Skip to content

Commit

Permalink
Upgrade Django to v4.2 (#1113)
Browse files Browse the repository at this point in the history
* Upgrade Django to v4.2

* refresh lockfile

* replace is_ajax calls

* upgrade to pyscopg3 (recommended by Django) and update storage settings.

* transfer django-recaptcha2 to designsafe org

* update pytest-django for django 4 compatibility

* fix imports and add more stable debugging

* replace deprecated smart_text import

---------

Co-authored-by: Jake Rosenberg <jrosenberg@wireless-10-145-48-201.public.utexas.edu>
Co-authored-by: Jake Rosenberg <jrosenberg@MacBook-Pro.lan>
  • Loading branch information
3 people authored Nov 6, 2023
1 parent 5e4bbc6 commit 4620dff
Show file tree
Hide file tree
Showing 43 changed files with 122 additions and 114 deletions.
2 changes: 1 addition & 1 deletion bin/run-django.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
# run django dev server as designsafe community account
python manage.py runserver 0.0.0.0:8000
python -m debugpy --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000
2 changes: 1 addition & 1 deletion designsafe/apps/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django import forms
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.utils.safestring import mark_safe
from django.utils.html import escape
from snowpenguin.django.recaptcha2.fields import ReCaptchaField
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.db import models
from django.db import connections, DatabaseError
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.core.mail import send_mail
import logging
import six
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.accounts import views

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.urls import reverse
from django.db.models import Q
from django.http import HttpResponse, HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.accounts import forms, integrations
from designsafe.apps.accounts.models import (NEESUser, DesignSafeProfile,
NotificationPreferences)
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/api/datafiles/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.api.datafiles.views import DataFilesView, TransferFilesView, MicrosurveyView

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/api/licenses/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.api.licenses.views import LicenseView

urlpatterns = [
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/api/notifications/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.dispatch import Signal

ds_event = Signal(providing_args=['session_id', 'event_type', 'event_data'])
generic_event = Signal(providing_args=['event_type', 'event_data', 'event_users'])
ds_event = Signal()
generic_event = Signal()
2 changes: 1 addition & 1 deletion designsafe/apps/api/notifications/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import include, url
from django.urls import re_path as url

from designsafe.apps.api.notifications.views.api import ManageNotificationsView, NotificationsBadgeView
from designsafe.apps.api.notifications.views.webhooks import JobsWebhookView, FilesWebhookView
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/api/projects/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
More specific action should live in the body.
"""
from django.conf.urls import url, include
from django.urls import re_path as url
from designsafe.apps.api.projects.views import (ProjectListingView,
ProjectCollectionView,
ProjectDataView,
Expand Down
12 changes: 6 additions & 6 deletions designsafe/apps/api/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def post(self, request, **kwargs):
"""
Publish a project or version a publication
"""
if request.is_ajax():
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
data = json.loads(request.body)
else:
data = request.POST
Expand Down Expand Up @@ -173,7 +173,7 @@ def put(self, request, **kwargs):
"""
Amend a Publication
"""
if request.is_ajax():
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
data = json.loads(request.body)
else:
data = request.PUT
Expand Down Expand Up @@ -289,7 +289,7 @@ def post(self, request):
# portal service account needs to create the objects on behalf of the user
sa_client = get_service_account_client()

if request.is_ajax():
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
post_data = json.loads(request.body)
else:
post_data = request.POST.copy()
Expand Down Expand Up @@ -449,7 +449,7 @@ def post(self, request, project_id):
should be prevented anyways). Once that data is deleted, then we should update
the type of project.
"""
if request.is_ajax():
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
post_data = json.loads(request.body)
else:
post_data = request.POST.copy()
Expand Down Expand Up @@ -606,7 +606,7 @@ def post(self, request, project_id, name):
"""
sa_client = get_service_account_client()

if request.is_ajax():
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
post_data = json.loads(request.body)
else:
post_data = request.POST.copy()
Expand Down Expand Up @@ -658,7 +658,7 @@ def put(self, request, uuid):
"""
client = request.user.agave_oauth.client

if request.is_ajax():
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
post_data = json.loads(request.body)
else:
post_data = request.POST.copy()
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/api/publications/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.api.publications.views import PublicationListingView, PublicationDetailView, PublicationDataCiteView
from django.http import JsonResponse

Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/api/search/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.api.search.views import SearchView

"""
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=missing-docstring
from django.conf.urls import url, include
from django.urls import re_path as url, include
from designsafe.apps.api.views import LoggerApi
from django.http import JsonResponse

Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/api/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.api.users.views import SearchView, AuthenticatedView, UsageView, PublicView

urlpatterns = [
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/applications/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.applications import views


Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/auth/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import include, url
from django.urls import re_path as url
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.auth import views

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/box_integration/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.box_integration import views

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/cms_plugins/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cms.plugin_pool import plugin_pool
from designsafe.apps.cms_plugins.models import ResponsiveEmbedPlugin
from django.conf import settings
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _


class CMSResponsiveEmbedPlugin(CMSPluginBase):
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/cms_plugins/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from menus.menu_pool import menu_pool
from django.conf import settings
from importlib import import_module
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import logging

logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.dashboard import views

urlpatterns = [
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/data/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.data.views.base import (
DataDepotView,
FileMediaView,
DataDepotPublishedView,
DataDepotLegacyPublishedView
)
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

urlpatterns = [
url(
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/djangoRT/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url

from designsafe.apps.djangoRT import views

Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/dropbox_integration/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.dropbox_integration import views

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/geo/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.urls import reverse
from designsafe.apps.geo import views

Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/googledrive_integration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_prep_value(self, value):
if value is None:
return None
else:
return encoding.smart_text(
return encoding.smart_str(
base64.b64encode(jsonpickle.encode(value).encode()))

def value_to_string(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/googledrive_integration/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.googledrive_integration import views

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/nco/api_urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.nco.views import ProjectsListView, FiltersListView, TtcGrantsView, TtcFacilitiesView

"""
Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/nco/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path as url
from designsafe.apps.nco.views import NcoIndexView, NcoTtcGrantsView

urlpatterns = [
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/notifications/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.notifications import views


Expand Down
2 changes: 1 addition & 1 deletion designsafe/apps/rapid/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.urls import reverse
from designsafe.apps.rapid import views

Expand Down
6 changes: 3 additions & 3 deletions designsafe/apps/search/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.test import RequestFactory

from django.utils.html import strip_tags
from django.utils.encoding import force_text
from django.utils.encoding import force_str

from cms.models import Title, CMSPlugin, Page
# from cms.toolbar.toolbar import CMSToolbar
Expand All @@ -24,7 +24,7 @@ def _strip_tags(value):
whitespace in between replaced tags to make sure words are not erroneously
concatenated.
"""
return re.sub(r'<[^>]*?>', ' ', force_text(value))
return re.sub(r'<[^>]*?>', ' ', force_str(value))


class TextPluginIndex(indexes.SearchIndex, indexes.Indexable):
Expand Down Expand Up @@ -70,7 +70,7 @@ def prepare(self, obj):
# this is an empty plugin
continue
if hasattr(instance, 'search_fields'):
text += ' '.join(force_text(strip_tags(getattr(instance, field, ''))) for field in instance.search_fields)
text += ' '.join(force_str(strip_tags(getattr(instance, field, ''))) for field in instance.search_fields)
if getattr(instance, 'search_fulltext', False) or getattr(plugin_type, 'search_fulltext', False):
text += _strip_tags(instance.render_plugin(context=RequestContext(request))) + ' '
text += page.get_meta_description() or ''
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/search/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.search import views

urlpatterns = [
Expand Down
4 changes: 2 additions & 2 deletions designsafe/apps/signals/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.dispatch import Signal

ds_event = Signal(providing_args=['session_id', 'event_type', 'event_data'])
generic_event = Signal(providing_args=['event_type', 'event_data', 'event_users'])
ds_event = Signal()
generic_event = Signal()
4 changes: 2 additions & 2 deletions designsafe/apps/workspace/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import url
from django.urls import re_path as url
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from designsafe.apps.workspace import views

# TODO look at linking directly into an app in the workspace
Expand Down
2 changes: 1 addition & 1 deletion designsafe/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'schedule': crontab(hour=0, minute=0)
},
'clear_old_notifications': {
'task': 'designsafe.auth.tasks.clear_old_notifications',
'task': 'designsafe.apps.auth.tasks.clear_old_notifications',
'schedule': crontab(hour=0, minute=1)
}
}
Expand Down
2 changes: 1 addition & 1 deletion designsafe/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def mock_agave_client(mocker):


@pytest.fixture
def regular_user(django_user_model, django_db_reset_sequences, mock_agave_client):
def regular_user(django_user_model, mock_agave_client):
django_user_model.objects.create_user(username="username",
password="password",
first_name="Firstname",
Expand Down
11 changes: 9 additions & 2 deletions designsafe/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@
'django.middleware.security.SecurityMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'impersonate.middleware.ImpersonateMiddleware',
'designsafe.middleware.DesignSafeTermsMiddleware',
'designsafe.middleware.DesignsafeProfileUpdateMiddleware',
Expand Down Expand Up @@ -273,7 +273,14 @@
('vendor/d3plus', os.path.join(BASE_DIR, 'node_modules', 'd3plus')),
]

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
},
}
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
Expand Down
2 changes: 1 addition & 1 deletion designsafe/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

from django.conf import settings
from django.conf.urls import include, url
from django.urls import include, re_path as url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import RedirectView, TemplateView
Expand Down
2 changes: 1 addition & 1 deletion designsafe/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DesignSafe-CI Webhook URLs
"""
from django.conf import settings
from django.conf.urls import include, url
from django.urls import include, re_path as url
from designsafe.apps.notifications import views
from designsafe.apps.box_integration import webhooks

Expand Down
Loading

0 comments on commit 4620dff

Please sign in to comment.