Skip to content

Commit

Permalink
Simplify url patterns
Browse files Browse the repository at this point in the history
Favor `django.urls.path` over `re_path` where possible.
  • Loading branch information
medmunds committed Feb 8, 2023
1 parent 4e3e76f commit f5f3fc8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
70 changes: 36 additions & 34 deletions anymail/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import re_path
from django.urls import path, re_path

from .webhooks.amazon_ses import (
AmazonSESInboundWebhookView,
Expand All @@ -18,89 +18,91 @@

app_name = "anymail"
urlpatterns = [
re_path(
r"^amazon_ses/inbound/$",
path(
"amazon_ses/inbound/",
AmazonSESInboundWebhookView.as_view(),
name="amazon_ses_inbound_webhook",
),
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)?/$",
MailgunInboundWebhookView.as_view(),
name="mailgun_inbound_webhook",
),
re_path(
r"^mailjet/inbound/$",
path(
"mailjet/inbound/",
MailjetInboundWebhookView.as_view(),
name="mailjet_inbound_webhook",
),
re_path(
r"^postal/inbound/$",
path(
"postal/inbound/",
PostalInboundWebhookView.as_view(),
name="postal_inbound_webhook",
),
re_path(
r"^postmark/inbound/$",
path(
"postmark/inbound/",
PostmarkInboundWebhookView.as_view(),
name="postmark_inbound_webhook",
),
re_path(
r"^sendgrid/inbound/$",
path(
"sendgrid/inbound/",
SendGridInboundWebhookView.as_view(),
name="sendgrid_inbound_webhook",
),
re_path(
r"^sparkpost/inbound/$",
path(
"sparkpost/inbound/",
SparkPostInboundWebhookView.as_view(),
name="sparkpost_inbound_webhook",
),
re_path(
r"^amazon_ses/tracking/$",
path(
"amazon_ses/tracking/",
AmazonSESTrackingWebhookView.as_view(),
name="amazon_ses_tracking_webhook",
),
re_path(
r"^mailgun/tracking/$",
path(
"mailgun/tracking/",
MailgunTrackingWebhookView.as_view(),
name="mailgun_tracking_webhook",
),
re_path(
r"^mailjet/tracking/$",
path(
"mailjet/tracking/",
MailjetTrackingWebhookView.as_view(),
name="mailjet_tracking_webhook",
),
re_path(
r"^postal/tracking/$",
path(
"postal/tracking/",
PostalTrackingWebhookView.as_view(),
name="postal_tracking_webhook",
),
re_path(
r"^postmark/tracking/$",
path(
"postmark/tracking/",
PostmarkTrackingWebhookView.as_view(),
name="postmark_tracking_webhook",
),
re_path(
r"^sendgrid/tracking/$",
path(
"sendgrid/tracking/",
SendGridTrackingWebhookView.as_view(),
name="sendgrid_tracking_webhook",
),
re_path(
r"^sendinblue/tracking/$",
path(
"sendinblue/tracking/",
SendinBlueTrackingWebhookView.as_view(),
name="sendinblue_tracking_webhook",
),
re_path(
r"^sparkpost/tracking/$",
path(
"sparkpost/tracking/",
SparkPostTrackingWebhookView.as_view(),
name="sparkpost_tracking_webhook",
),
# Anymail uses a combined Mandrill webhook endpoint,
# to simplify Mandrill's key-validation scheme:
re_path(
r"^mandrill/$", MandrillCombinedWebhookView.as_view(), name="mandrill_webhook"
),
path("mandrill/", MandrillCombinedWebhookView.as_view(), name="mandrill_webhook"),
# This url is maintained for backwards compatibility with earlier Anymail releases:
re_path(
r"^mandrill/tracking/$",
path(
"mandrill/tracking/",
MandrillCombinedWebhookView.as_view(),
name="mandrill_tracking_webhook",
),
Expand Down
6 changes: 3 additions & 3 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ If you want to use Anymail's inbound or tracking webhooks:

.. code-block:: python
from django.urls import include, re_path
from django.urls import include, path
urlpatterns = [
...
re_path(r'^anymail/', include('anymail.urls')),
path("anymail/", include("anymail.urls")),
]
(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
your ESP in the next step.)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_settings/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import include, re_path
from django.urls import include, path

urlpatterns = [
re_path(r"^anymail/", include("anymail.urls")),
path("anymail/", include("anymail.urls")),
]

0 comments on commit f5f3fc8

Please sign in to comment.