mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Rename EmailBackends for Django consistency
* **Future breaking change:** Rename all Anymail backends to just `EmailBackend`, matching Django's naming convention. (E.g., switch to "anymail.backends.mailgun.EmailBackend" rather than "anymail.backends.mailgun.MailgunBackend".) The old names still work, but will issue a DeprecationWarning and will be removed in some future release. (Apologies for this change; the old naming convention was a holdover from Djrill, and I wanted consistency with other Django EmailBackends before hitting 1.0.) Fixes #49.
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
import re
|
||||
import warnings
|
||||
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
|
||||
from ..exceptions import AnymailRequestsAPIError
|
||||
from ..exceptions import AnymailRequestsAPIError, AnymailDeprecationWarning
|
||||
from ..message import AnymailRecipientStatus
|
||||
from ..utils import get_anymail_setting
|
||||
|
||||
from .base_requests import AnymailRequestsBackend, RequestsPayload
|
||||
|
||||
|
||||
class PostmarkBackend(AnymailRequestsBackend):
|
||||
class EmailBackend(AnymailRequestsBackend):
|
||||
"""
|
||||
Postmark API Email Backend
|
||||
"""
|
||||
|
||||
esp_name = "Postmark"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Init options from Django settings"""
|
||||
esp_name = self.esp_name
|
||||
@@ -22,7 +25,7 @@ class PostmarkBackend(AnymailRequestsBackend):
|
||||
default="https://api.postmarkapp.com/")
|
||||
if not api_url.endswith("/"):
|
||||
api_url += "/"
|
||||
super(PostmarkBackend, self).__init__(api_url, **kwargs)
|
||||
super(EmailBackend, self).__init__(api_url, **kwargs)
|
||||
|
||||
def build_message_payload(self, message, defaults):
|
||||
return PostmarkPayload(message, defaults, self)
|
||||
@@ -30,7 +33,7 @@ class PostmarkBackend(AnymailRequestsBackend):
|
||||
def raise_for_status(self, response, payload, message):
|
||||
# We need to handle 422 responses in parse_recipient_status
|
||||
if response.status_code != 422:
|
||||
super(PostmarkBackend, self).raise_for_status(response, payload, message)
|
||||
super(EmailBackend, self).raise_for_status(response, payload, message)
|
||||
|
||||
def parse_recipient_status(self, response, payload, message):
|
||||
parsed_response = self.deserialize_json_response(response, payload, message)
|
||||
@@ -89,6 +92,15 @@ class PostmarkBackend(AnymailRequestsBackend):
|
||||
return []
|
||||
|
||||
|
||||
# Pre-v0.8 naming (deprecated)
|
||||
class PostmarkBackend(EmailBackend):
|
||||
def __init__(self, **kwargs):
|
||||
warnings.warn(AnymailDeprecationWarning(
|
||||
"Please update your EMAIL_BACKEND setting to "
|
||||
"'anymail.backends.postmark.EmailBackend'"))
|
||||
super(PostmarkBackend, self).__init__(**kwargs)
|
||||
|
||||
|
||||
class PostmarkPayload(RequestsPayload):
|
||||
|
||||
def __init__(self, message, defaults, backend, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user