Skip to content

Commit 491b628

Browse files
authored
Merge pull request #2 from skip-pay/UpstreamSync076
Upstream sync 0.7.6
2 parents 1eda107 + f206be7 commit 491b628

File tree

5 files changed

+142
-12
lines changed

5 files changed

+142
-12
lines changed

docs/emails.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,32 @@ Webhooks
305305
--------
306306

307307
Mandrill provides notification system which notifies your URL endpoint that some message status was changed. For this purpose pymess provides view ``pymess.webhooks.mandrill.MandrillWebhookView`` which you simply add to your ``django urls``. Every notification will mark message to be updated with the ``pull_emails_info`` command.
308+
309+
310+
Migrations
311+
----------
312+
313+
The library provides utilities to migrate e-mail templates into database. The e-mail bodies can be stored in the files with path defined in the setting ``EMAIL_HTML_DATA_DIRECTORY``. Every file should be named its the template slug. You can use the ``pymess.utils.migrations.SyncEmailTemplates`` migration helper to sync e-mail body as in the example::
314+
315+
# Django settings
316+
EMAIL_HTML_DATA_DIRECTORY = '/data/emails
317+
318+
# data/emails directory
319+
data/emails
320+
- set-pasword.html
321+
- welcome.html
322+
323+
# Migration
324+
from django.db import migrations
325+
from pymess.utils.migrations import SyncEmailTemplates
326+
327+
328+
class Migration(migrations.Migration):
329+
330+
dependencies = [
331+
('communication', '0001_migration'),
332+
]
333+
334+
operations = [
335+
migrations.RunPython(SyncEmailTemplates(('set-password', 'welcome))), # Body of the e-mails will be updated (e-mail templates must exist in the database)
336+
]

docs/installation.rst

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,44 @@ SMS
6161

6262
Country code that is set to the recipient if phone number doesn't contain another one.
6363

64-
.. attribute:: PYMESS_SMS_SENDER_BACKEND
64+
.. attribute:: PYMESS_SMS_BACKENDS
6565

66-
Path to the SMS backend that will be used for sending SMS messages. Default value is ``'pymess.backend.sms.dummy.DummySMSBackend'``.
66+
Path to the SMS backends that will be used for sending SMS messages. The default value is::
67+
68+
PYMESS_SMS_BACKENDS = {
69+
'default': {
70+
'backend': 'pymess.backend.sms.dummy.DummySMSBackend'
71+
}
72+
}
73+
74+
It can be used more backends with different names (like ``DATABASES`` Django setting)
75+
76+
.. attribute:: PYMESS_SMS_DEFAULT_SENDER_BACKEND_NAME
77+
78+
Name of the default SMS sender backend. The default value is ``default``.
79+
80+
.. attribute:: PYMESS_SMS_BACKEND_ROUTER
81+
82+
Path to the router class which select SMS backend name according to a recipient value. The default value is ``'pymess.backend.routers.DefaultBackendRouter'`` which returns None (None value means the default backend name should be set). You can implement custom router with::
83+
84+
# sms_routers.py file
85+
from pymess.backend.routers import BaseRouter
86+
87+
class CustomRouter(BaseRouter):
88+
89+
def get_backend_name(self, recipient):
90+
return 'admin' if recipient in ADMIN_PHONES else None
91+
92+
# django settings file
93+
PYMESS_SMS_BACKEND_ROUTER = 'sms_routers.CustomRouter'
94+
PYMESS_SMS_BACKENDS = {
95+
'default': {
96+
'backend': 'pymess.backend.sms.dummy.DummySMSBackend'
97+
},
98+
'admin': {
99+
'backend': 'path.to.the.SomeAdminBackend'
100+
}
101+
}
67102

68103
.. attribute:: PYMESS_SMS_BATCH_SENDING
69104

@@ -81,6 +116,11 @@ SMS
81116

82117
Defines maximum number of seconds to try to send a SMS message that ended in an ``ERROR_RETRY`` state. Default value is ``60 * 60`` (1 hour).
83118

119+
.. attribute:: PYMESS_SMS_RETRY_SENDING
120+
121+
Setting defines if sending should be retried if fails. Works only together with batch sending. Default value is ``True``.
122+
123+
84124
E-MAIL
85125
^^^^^^
86126

@@ -112,9 +152,23 @@ E-MAIL
112152

113153
List of HTML tags which cannot be used in the e-mail content.
114154

115-
.. attribute:: PYMESS_EMAIL_SENDER_BACKEND
155+
.. attribute:: PYMESS_EMAIL_BACKENDS
156+
157+
Path to the e-mail backends that will be used for sending E-mail messages. The default value is::
158+
159+
PYMESS_EMAIL_BACKENDS = {
160+
'default': {
161+
'backend': 'pymess.backend.emails.dummy.DummyEmailBackend'
162+
}
163+
}
116164

117-
Path to the E-mail backend that will be used for sending e-mail messages. Default value is ``'pymess.backend.emails.dummy.DummyEmailBackend'``.
165+
.. attribute:: PYMESS_EMAIL_DEFAULT_SENDER_BACKEND_NAME
166+
167+
Name of the default E-mail sender backend. The default value is ``default``.
168+
169+
.. attribute:: PYMESS_EMAIL_BACKEND_ROUTER
170+
171+
Path to the router class which select e-mail backend name according to a recipient value. The default value is ``'pymess.backend.routers.DefaultBackendRouter'`` which returns None (None value means the default backend name should be set).
118172

119173
.. attribute:: PYMESS_EMAIL_BATCH_SENDING
120174

@@ -145,6 +199,10 @@ E-MAIL
145199
Path for storing e-mail attachments and contents (bodies).
146200
If changed after initial migration, existing files must be moved manually via data migration.
147201

202+
.. attribute:: PYMESS_EMAIL_RETRY_SENDING
203+
204+
Setting defines if sending should be retried if fails. Works only together with batch sending. Default value is ``True``.
205+
148206

149207
DIALER
150208
^^^^^^
@@ -157,6 +215,24 @@ DIALER
157215

158216
Path to the dialer backend that will be used for sending dialer messages. Default value is ``'pymess.backend.dialer.dummy.DummyDialerBackend'``.
159217

218+
.. attribute:: PYMESS_DIALER_BACKENDS
219+
220+
Path to the dialer backends that will be used for sending dialer messages. The default value is::
221+
222+
PYMESS_DIALER_BACKENDS = {
223+
'default': {
224+
'backend': 'pymess.backend.dialer.dummy.DummyDialerBackend'
225+
}
226+
}
227+
228+
.. attribute:: PYMESS_DIALER_DEFAULT_SENDER_BACKEND_NAME
229+
230+
Name of the default dialer sender backend. The default value is ``default``.
231+
232+
.. attribute:: PYMESS_DIALER_BACKEND_ROUTER
233+
234+
Path to the router class which select dialer backend name according to a recipient value. The default value is ``'pymess.backend.routers.DefaultBackendRouter'`` which returns None (None value means the default backend name should be set).
235+
160236
.. attribute:: PYMESS_DIALER_BATCH_SENDING
161237

162238
Because sending messages speed is dependent on the provider which can slow down your application speed, messages can be send in background with command ``send_messages_batch``. Default value is ``False``.
@@ -181,6 +257,10 @@ DIALER
181257

182258
Number of check attempts to get dialer message state. Default value is ``5``
183259

260+
.. attribute:: PYMESS_DIALER_RETRY_SENDING
261+
262+
Setting defines if sending should be retried if fails. Works only together with batch sending. Default value is ``True``.
263+
184264

185265
Push notifications
186266
^^^^^^^^^^^^^^^^^^
@@ -189,9 +269,23 @@ Push notifications
189269

190270
If you want to use your own push notification template model you must set this setting with your custom push notification template model that extends ``pymess.models.push.AbstractPushNotificationMessage`` otherwise is used ``pymess.models.push.PushNotificationMessage``.
191271

192-
.. attribute:: PYMESS_PUSH_NOTIFICATION_SENDER_BACKEND
272+
.. attribute:: PYMESS_PUSH_NOTIFICATION_BACKENDS
273+
274+
Path to the push notification backends that will be used for sending dialer messages. The default value is::
275+
276+
PYMESS_PUSH_NOTIFICATION_BACKENDS = {
277+
'default': {
278+
'backend': 'pymess.backend.push.dummy.DummyPushNotificationBackend'
279+
}
280+
}
281+
282+
.. attribute:: PYMESS_PUSH_NOTIFICATION_DEFAULT_SENDER_BACKEND_NAME
283+
284+
Name of the default push notification sender backend. The default value is ``default``.
193285

194-
Path to the push notification backend that will be used for sending push notifications. Default value is ``'pymess.backend.push.dummy.DummyPushNotificationBackend'``.
286+
.. attribute:: PYMESS_PUSH_NOTIFICATION_BACKEND_ROUTER
287+
288+
Path to the router class which select push notification backend name according to a recipient value. The default value is ``'pymess.backend.routers.DefaultBackendRouter'`` which returns None (None value means the default backend name should be set).
195289

196290
.. attribute:: PYMESS_PUSH_NOTIFICATION_BATCH_SENDING
197291

@@ -208,3 +302,8 @@ Push notifications
208302
.. attribute:: PYMESS_PUSH_NOTIFICATION_BATCH_MAX_SECONDS_TO_SEND
209303

210304
Defines maximum number of seconds to try to send an push notification message that ended in an ``ERROR_RETRY`` state. Default value is ``60 * 60`` (1 hour).
305+
306+
.. attribute:: PYMESS_PUSH_NOTIFICATION_RETRY_SENDING
307+
308+
Setting defines if sending should be retried if fails. Works only together with batch sending. Default value is ``True``.
309+

pymess/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ControllerType(Enum):
7474
'EMAIL_PULL_INFO_DELAY_SECONDS': 60 * 60, # 1 hour
7575
'EMAIL_PULL_INFO_MAX_TIMEOUT_FROM_SENT_SECONDS': 60 * 60 * 24 * 30, # 30 days
7676
'EMAIL_RETRY_SENDING': True,
77-
'EMAIL_STORAGE_PATH' : 'pymess/emails',
77+
'EMAIL_STORAGE_PATH': 'pymess/emails',
7878

7979
# Dialer configuration
8080
'DIALER_BACKENDS': {

pymess/utils/migrations.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def __call__(self, apps, schema_editor):
2323
email_template_qs = email_template_class.objects.all()
2424
if self.template_slugs:
2525
email_template_qs = email_template_qs.filter(slug__in=self.template_slugs)
26-
email_template_list = list(email_template_qs)
27-
for email_template in email_template_list:
26+
email_templates_found = list(email_template_qs)
27+
if self.template_slugs:
28+
email_templates_not_found = set(self.template_slugs) - {t.slug for t in email_templates_found}
29+
assert not email_templates_not_found, f"Email templates {email_templates_not_found} were not found."
30+
for email_template in email_templates_found:
2831
email_template.body = get_email_template_body_from_file(email_template.slug)
29-
email_template_class.objects.bulk_update(email_template_list, ['body'])
30-
32+
email_template_class.objects.bulk_update(email_templates_found, ['body'])

pymess/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = (0, 7, 5, 1)
1+
VERSION = (0, 7, 6, 1)
22

33

44
def get_version():

0 commit comments

Comments
 (0)