From 764b1a164345e4ce363659eafa9f5fef63882922 Mon Sep 17 00:00:00 2001 From: M Somerville Date: Fri, 13 May 2022 18:23:10 +0100 Subject: [PATCH] Deal with some Django 4 deprecations. --- api_keys/urls.py | 14 ++++++------ bulk_lookup/forms.py | 6 +++--- bulk_lookup/models.py | 2 +- bulk_lookup/urls.py | 8 +++---- bulk_lookup/views.py | 4 ++-- mapit_mysociety_org/settings.py | 2 ++ mapit_mysociety_org/urls.py | 38 ++++++++++++++++----------------- subscriptions/urls.py | 26 +++++++++++----------- 8 files changed, 51 insertions(+), 49 deletions(-) diff --git a/api_keys/urls.py b/api_keys/urls.py index 54ae4cbd..b2c4b7ec 100644 --- a/api_keys/urls.py +++ b/api_keys/urls.py @@ -1,21 +1,21 @@ -from django.conf.urls import url +from django.urls import path from django.contrib.auth.decorators import login_required from .views import APIKeyListView, APIKeyDeleteView, APIKeyCreateView urlpatterns = [ - url( - r'^keys', + path( + 'keys', login_required(APIKeyListView.as_view()), name="api_keys_keys" ), - url( - r'^create', + path( + 'create', login_required(APIKeyCreateView.as_view()), name="api_keys_create_key" ), - url( - r'^(?P\d+)/delete', + path( + '/delete', login_required(APIKeyDeleteView.as_view()), name="api_keys_delete_key" ) diff --git a/bulk_lookup/forms.py b/bulk_lookup/forms.py index 259236c3..b263ffec 100644 --- a/bulk_lookup/forms.py +++ b/bulk_lookup/forms.py @@ -3,7 +3,7 @@ import re from django import forms from django.utils.crypto import get_random_string -from django.utils.encoding import smart_text +from django.utils.encoding import smart_str import stripe from ukpostcodeutils.validation import is_valid_postcode @@ -12,7 +12,7 @@ def clean_postcode(pc): - return re.sub('[^A-Z0-9]', '', smart_text(pc).upper()) + return re.sub('[^A-Z0-9]', '', smart_str(pc).upper()) class CSVForm(forms.Form): @@ -128,7 +128,7 @@ def clean(self): super(PersonalDetailsForm, self).clean() # If we're doing this for free if self.free: - self.cleaned_data['charge_id'] = 'r_%s' % get_random_string() + self.cleaned_data['charge_id'] = 'r_%s' % get_random_string(12) elif not self.cleaned_data['charge_id']: raise forms.ValidationError("You need to pay for the lookup") else: diff --git a/bulk_lookup/models.py b/bulk_lookup/models.py index 12c613ab..0a060df9 100644 --- a/bulk_lookup/models.py +++ b/bulk_lookup/models.py @@ -47,7 +47,7 @@ def output_file_upload_to(instance, filename): def random_folder_path(base_folder, filename): - random_folder = get_random_string() + random_folder = get_random_string(12) return os.path.join(base_folder, random_folder, filename) diff --git a/bulk_lookup/urls.py b/bulk_lookup/urls.py index e75bab2f..905ef73e 100644 --- a/bulk_lookup/urls.py +++ b/bulk_lookup/urls.py @@ -1,9 +1,9 @@ -from django.conf.urls import url +from django.urls import path from .views import AjaxConfirmView, WizardView, FinishedView urlpatterns = [ - url(r'^$', WizardView.as_view(), name='home'), - url(r'^ajax-confirm$', AjaxConfirmView, name='ajax-confirm'), - url(r'^(?P\d+)/(?P.+)$', FinishedView.as_view(), name='finished'), + path('', WizardView.as_view(), name='home'), + path('ajax-confirm', AjaxConfirmView, name='ajax-confirm'), + path('/', FinishedView.as_view(), name='finished'), ] diff --git a/bulk_lookup/views.py b/bulk_lookup/views.py index 36feaa58..dd502103 100644 --- a/bulk_lookup/views.py +++ b/bulk_lookup/views.py @@ -5,7 +5,7 @@ from django.core.files.storage import FileSystemStorage from django.shortcuts import redirect from django.views.generic import DetailView -from django.utils.encoding import force_text +from django.utils.encoding import force_str from formtools.wizard.views import SessionWizardView import stripe @@ -81,7 +81,7 @@ def get_form_initial(self, step): if step == 'postcode_field': bulk_lookup = self.get_cleaned_csv_data for choice in bulk_lookup.field_names: - if re.match(r'post(\s)*code', force_text(choice), flags=re.IGNORECASE): + if re.match(r'post(\s)*code', force_str(choice), flags=re.IGNORECASE): initial['postcode_field'] = choice break elif step == 'personal_details': diff --git a/mapit_mysociety_org/settings.py b/mapit_mysociety_org/settings.py index 602ca556..133d1a3f 100644 --- a/mapit_mysociety_org/settings.py +++ b/mapit_mysociety_org/settings.py @@ -50,6 +50,8 @@ def allow_migrate(self, db, app_label, model_name=None, **hints): DATABASE_ROUTERS = ['mapit_mysociety_org.settings.PrimaryReplicaRouter'] MIDDLEWARE.insert(0, 'mapit_mysociety_org.middleware.force_primary_middleware') +DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' + INSTALLED_APPS.extend(['django.contrib.sites', 'account', 'mailer', 'api_keys', 'subscriptions', 'bulk_lookup']) # Insert our project app before mapit and mapit_gb so that the templates diff --git a/mapit_mysociety_org/urls.py b/mapit_mysociety_org/urls.py index 461b9729..814a3133 100644 --- a/mapit_mysociety_org/urls.py +++ b/mapit_mysociety_org/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import include, url +from django.urls import include, path from django.contrib import admin from django.views.generic.base import RedirectView @@ -7,26 +7,26 @@ from .views import LoginView, LogoutView, SignupView, ConfirmEmailView urlpatterns = [ - url(r'^changelog$', render, {'template_name': 'changelog.html'}, 'mapit_changelog'), - url(r'^', include('mapit.urls')), - url(r'^contact$', render, {'template_name': 'mapit/contact.html'}, 'mapit_contact'), - url(r'^pricing/', render, {'template_name': 'pricing.html'}, 'mapit_pricing'), - url(r'^legal/', render, {'template_name': 'mapit/licensing.html'}, 'mapit_legal'), - url(r'^privacy/', render, {'template_name': 'mapit/privacy.html'}, 'mapit_privacy'), - url(r'^docs/', render, {'template_name': 'docs.html'}, 'mapit_docs'), - url(r'^admin$', RedirectView.as_view(url='admin/', permanent=True)), - url(r'^admin/', admin.site.urls), - url(r"^bulk/", include("bulk_lookup.urls")), - url(r"^account/api_keys/", include("api_keys.urls")), - url(r"^account/subscription", include("subscriptions.urls")), + path('changelog', render, {'template_name': 'changelog.html'}, 'mapit_changelog'), + path('', include('mapit.urls')), + path('contact', render, {'template_name': 'mapit/contact.html'}, 'mapit_contact'), + path('pricing/', render, {'template_name': 'pricing.html'}, 'mapit_pricing'), + path('legal/', render, {'template_name': 'mapit/licensing.html'}, 'mapit_legal'), + path('privacy/', render, {'template_name': 'mapit/privacy.html'}, 'mapit_privacy'), + path('docs/', render, {'template_name': 'docs.html'}, 'mapit_docs'), + path('admin', RedirectView.as_view(url='admin/', permanent=True)), + path('admin/', admin.site.urls), + path("bulk/", include("bulk_lookup.urls")), + path("account/api_keys/", include("api_keys.urls")), + path("account/subscription", include("subscriptions.urls")), # Override the login and signup views from the account app, so we can use # our versions which use an email address instead of a username. - url(r"^account/signup/$", SignupView.as_view(), name="account_signup"), - url(r"^account/login/$", LoginView.as_view(), name="account_login"), - url(r"^account/logout/$", LogoutView.as_view(), name="account_logout"), + path("account/signup/", SignupView.as_view(), name="account_signup"), + path("account/login/", LoginView.as_view(), name="account_login"), + path("account/logout/", LogoutView.as_view(), name="account_logout"), # Override the confirm_email view from the account app, so we can sign # people in immediately after they confirm. - url(r"^account/confirm_email/(?P\w+)/$", ConfirmEmailView.as_view(), name="account_confirm_email"), - url(r"^account/$", RedirectView.as_view(pattern_name='subscription', permanent=True)), - url(r"^account/", include("account.urls")), + path("account/confirm_email//", ConfirmEmailView.as_view(), name="account_confirm_email"), + path("account/", RedirectView.as_view(pattern_name='subscription', permanent=True)), + path("account/", include("account.urls")), ] diff --git a/subscriptions/urls.py b/subscriptions/urls.py index 325c9c63..0e66e76e 100644 --- a/subscriptions/urls.py +++ b/subscriptions/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.urls import path from django.contrib.auth.decorators import login_required from .views import ( @@ -6,33 +6,33 @@ SubscriptionCardUpdateView, SubscriptionCancelView) urlpatterns = [ - url( - r'^$', + path( + '', login_required(SubscriptionView.as_view()), name="subscription" ), - url( - r'^/invoices$', + path( + '/invoices', login_required(InvoicesView.as_view()), name="invoices" ), - url( - r'^/update$', + path( + '/update', login_required(SubscriptionUpdateView.as_view()), name="subscription_update" ), - url( - r'^/update-card$', + path( + '/update-card', login_required(SubscriptionCardUpdateView.as_view()), name="subscription_card_update" ), - url( - r'^/cancel$', + path( + '/cancel', login_required(SubscriptionCancelView.as_view()), name="subscription_cancel" ), - url( - r'^/stripe-hook$', + path( + '/stripe-hook', stripe_hook, name="stripe-hook" ),