Skip to content

Commit

Permalink
Deal with some Django 4 deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos authored and sagepe committed Jun 7, 2022
1 parent 2144c39 commit 764b1a1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 49 deletions.
14 changes: 7 additions & 7 deletions api_keys/urls.py
Original file line number Diff line number Diff line change
@@ -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<pk>\d+)/delete',
path(
'<int:pk>/delete',
login_required(APIKeyDeleteView.as_view()),
name="api_keys_delete_key"
)
Expand Down
6 changes: 3 additions & 3 deletions bulk_lookup/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion bulk_lookup/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 4 additions & 4 deletions bulk_lookup/urls.py
Original file line number Diff line number Diff line change
@@ -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<pk>\d+)/(?P<token>.+)$', FinishedView.as_view(), name='finished'),
path('', WizardView.as_view(), name='home'),
path('ajax-confirm', AjaxConfirmView, name='ajax-confirm'),
path('<int:pk>/<token>', FinishedView.as_view(), name='finished'),
]
4 changes: 2 additions & 2 deletions bulk_lookup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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':
Expand Down
2 changes: 2 additions & 0 deletions mapit_mysociety_org/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions mapit_mysociety_org/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, path
from django.contrib import admin
from django.views.generic.base import RedirectView

Expand All @@ -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<key>\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/<key>/", ConfirmEmailView.as_view(), name="account_confirm_email"),
path("account/", RedirectView.as_view(pattern_name='subscription', permanent=True)),
path("account/", include("account.urls")),
]
26 changes: 13 additions & 13 deletions subscriptions/urls.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
from django.conf.urls import url
from django.urls import path
from django.contrib.auth.decorators import login_required

from .views import (
stripe_hook, InvoicesView, SubscriptionView, SubscriptionUpdateView,
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"
),
Expand Down

0 comments on commit 764b1a1

Please sign in to comment.