Simplify url patterns

Favor `django.urls.path` over `re_path` where possible.
This commit is contained in:
medmunds
2023-02-08 14:23:15 -08:00
parent 4e3e76f997
commit f5f3fc86e6
3 changed files with 41 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
from django.urls import re_path from django.urls import path, re_path
from .webhooks.amazon_ses import ( from .webhooks.amazon_ses import (
AmazonSESInboundWebhookView, AmazonSESInboundWebhookView,
@@ -18,89 +18,91 @@ from .webhooks.sparkpost import (
app_name = "anymail" app_name = "anymail"
urlpatterns = [ urlpatterns = [
re_path( path(
r"^amazon_ses/inbound/$", "amazon_ses/inbound/",
AmazonSESInboundWebhookView.as_view(), AmazonSESInboundWebhookView.as_view(),
name="amazon_ses_inbound_webhook", name="amazon_ses_inbound_webhook",
), ),
re_path( re_path(
# Mailgun delivers inbound messages differently based on whether
# the webhook url contains "mime" (anywhere). You can use either
# ".../mailgun/inbound/" or ".../mailgun/inbound_mime/" depending
# on the behavior you want.
r"^mailgun/inbound(_mime)?/$", r"^mailgun/inbound(_mime)?/$",
MailgunInboundWebhookView.as_view(), MailgunInboundWebhookView.as_view(),
name="mailgun_inbound_webhook", name="mailgun_inbound_webhook",
), ),
re_path( path(
r"^mailjet/inbound/$", "mailjet/inbound/",
MailjetInboundWebhookView.as_view(), MailjetInboundWebhookView.as_view(),
name="mailjet_inbound_webhook", name="mailjet_inbound_webhook",
), ),
re_path( path(
r"^postal/inbound/$", "postal/inbound/",
PostalInboundWebhookView.as_view(), PostalInboundWebhookView.as_view(),
name="postal_inbound_webhook", name="postal_inbound_webhook",
), ),
re_path( path(
r"^postmark/inbound/$", "postmark/inbound/",
PostmarkInboundWebhookView.as_view(), PostmarkInboundWebhookView.as_view(),
name="postmark_inbound_webhook", name="postmark_inbound_webhook",
), ),
re_path( path(
r"^sendgrid/inbound/$", "sendgrid/inbound/",
SendGridInboundWebhookView.as_view(), SendGridInboundWebhookView.as_view(),
name="sendgrid_inbound_webhook", name="sendgrid_inbound_webhook",
), ),
re_path( path(
r"^sparkpost/inbound/$", "sparkpost/inbound/",
SparkPostInboundWebhookView.as_view(), SparkPostInboundWebhookView.as_view(),
name="sparkpost_inbound_webhook", name="sparkpost_inbound_webhook",
), ),
re_path( path(
r"^amazon_ses/tracking/$", "amazon_ses/tracking/",
AmazonSESTrackingWebhookView.as_view(), AmazonSESTrackingWebhookView.as_view(),
name="amazon_ses_tracking_webhook", name="amazon_ses_tracking_webhook",
), ),
re_path( path(
r"^mailgun/tracking/$", "mailgun/tracking/",
MailgunTrackingWebhookView.as_view(), MailgunTrackingWebhookView.as_view(),
name="mailgun_tracking_webhook", name="mailgun_tracking_webhook",
), ),
re_path( path(
r"^mailjet/tracking/$", "mailjet/tracking/",
MailjetTrackingWebhookView.as_view(), MailjetTrackingWebhookView.as_view(),
name="mailjet_tracking_webhook", name="mailjet_tracking_webhook",
), ),
re_path( path(
r"^postal/tracking/$", "postal/tracking/",
PostalTrackingWebhookView.as_view(), PostalTrackingWebhookView.as_view(),
name="postal_tracking_webhook", name="postal_tracking_webhook",
), ),
re_path( path(
r"^postmark/tracking/$", "postmark/tracking/",
PostmarkTrackingWebhookView.as_view(), PostmarkTrackingWebhookView.as_view(),
name="postmark_tracking_webhook", name="postmark_tracking_webhook",
), ),
re_path( path(
r"^sendgrid/tracking/$", "sendgrid/tracking/",
SendGridTrackingWebhookView.as_view(), SendGridTrackingWebhookView.as_view(),
name="sendgrid_tracking_webhook", name="sendgrid_tracking_webhook",
), ),
re_path( path(
r"^sendinblue/tracking/$", "sendinblue/tracking/",
SendinBlueTrackingWebhookView.as_view(), SendinBlueTrackingWebhookView.as_view(),
name="sendinblue_tracking_webhook", name="sendinblue_tracking_webhook",
), ),
re_path( path(
r"^sparkpost/tracking/$", "sparkpost/tracking/",
SparkPostTrackingWebhookView.as_view(), SparkPostTrackingWebhookView.as_view(),
name="sparkpost_tracking_webhook", name="sparkpost_tracking_webhook",
), ),
# Anymail uses a combined Mandrill webhook endpoint, # Anymail uses a combined Mandrill webhook endpoint,
# to simplify Mandrill's key-validation scheme: # to simplify Mandrill's key-validation scheme:
re_path( path("mandrill/", MandrillCombinedWebhookView.as_view(), name="mandrill_webhook"),
r"^mandrill/$", MandrillCombinedWebhookView.as_view(), name="mandrill_webhook"
),
# This url is maintained for backwards compatibility with earlier Anymail releases: # This url is maintained for backwards compatibility with earlier Anymail releases:
re_path( path(
r"^mandrill/tracking/$", "mandrill/tracking/",
MandrillCombinedWebhookView.as_view(), MandrillCombinedWebhookView.as_view(),
name="mandrill_tracking_webhook", name="mandrill_tracking_webhook",
), ),

View File

@@ -142,15 +142,15 @@ If you want to use Anymail's inbound or tracking webhooks:
.. code-block:: python .. code-block:: python
from django.urls import include, re_path from django.urls import include, path
urlpatterns = [ urlpatterns = [
... ...
re_path(r'^anymail/', include('anymail.urls')), path("anymail/", include("anymail.urls")),
] ]
(You can change the "anymail" prefix in the first parameter to (You can change the "anymail" prefix in the first parameter to
:func:`~django.urls.re_path` if you'd like the webhooks to be served :func:`~django.urls.path` if you'd like the webhooks to be served
at some other URL. Just match whatever you use in the webhook URL you give at some other URL. Just match whatever you use in the webhook URL you give
your ESP in the next step.) your ESP in the next step.)

View File

@@ -1,5 +1,5 @@
from django.urls import include, re_path from django.urls import include, path
urlpatterns = [ urlpatterns = [
re_path(r"^anymail/", include("anymail.urls")), path("anymail/", include("anymail.urls")),
] ]