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,7 +1,10 @@
|
||||
from __future__ import absolute_import # we want the sparkpost package, not our own module
|
||||
|
||||
import warnings
|
||||
|
||||
from .base import AnymailBaseBackend, BasePayload
|
||||
from ..exceptions import AnymailAPIError, AnymailImproperlyInstalled, AnymailConfigurationError
|
||||
from ..exceptions import (AnymailAPIError, AnymailImproperlyInstalled,
|
||||
AnymailConfigurationError, AnymailDeprecationWarning)
|
||||
from ..message import AnymailRecipientStatus
|
||||
from ..utils import get_anymail_setting
|
||||
|
||||
@@ -11,14 +14,16 @@ except ImportError:
|
||||
raise AnymailImproperlyInstalled(missing_package='sparkpost', backend='sparkpost')
|
||||
|
||||
|
||||
class SparkPostBackend(AnymailBaseBackend):
|
||||
class EmailBackend(AnymailBaseBackend):
|
||||
"""
|
||||
SparkPost Email Backend (using python-sparkpost client)
|
||||
"""
|
||||
|
||||
esp_name = "SparkPost"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Init options from Django settings"""
|
||||
super(SparkPostBackend, self).__init__(**kwargs)
|
||||
super(EmailBackend, self).__init__(**kwargs)
|
||||
# SPARKPOST_API_KEY is optional - library reads from env by default
|
||||
self.api_key = get_anymail_setting('api_key', esp_name=self.esp_name,
|
||||
kwargs=kwargs, allow_bare=True, default=None)
|
||||
@@ -77,6 +82,15 @@ class SparkPostBackend(AnymailBaseBackend):
|
||||
return {recipient.email: recipient_status for recipient in payload.all_recipients}
|
||||
|
||||
|
||||
# Pre-v0.8 naming (deprecated)
|
||||
class SparkPostBackend(EmailBackend):
|
||||
def __init__(self, **kwargs):
|
||||
warnings.warn(AnymailDeprecationWarning(
|
||||
"Please update your EMAIL_BACKEND setting to "
|
||||
"'anymail.backends.sparkpost.EmailBackend'"))
|
||||
super(SparkPostBackend, self).__init__(**kwargs)
|
||||
|
||||
|
||||
class SparkPostPayload(BasePayload):
|
||||
def init_payload(self):
|
||||
self.params = {}
|
||||
|
||||
Reference in New Issue
Block a user