Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
gotlium committed Apr 4, 2016
2 parents b9c8004 + ff59572 commit 7b521c5
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Push notification API
slug='welcome',
# recipient can be list, or str separated with comma or simple string
# '+34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8a' or '34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8a, 34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8b' or
# '34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8a' or '34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8a, 34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8b' or
# ['34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8a', '34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8b'] or string Mail group slug
recipient='34cc3e5f0d2abf2ca0f9af170bd8cd2372a22f8c',
Expand Down Expand Up @@ -536,5 +536,5 @@ Screenshots

Compatibility
-------------
* Python: 2.6, 2.7, pypy, 3.4, 3.5, pypy3
* Python: 2.7, pypy, 3.4, 3.5, pypy3
* Django: 1.4, 1.5, 1.6, 1.7, 1.8, 1.9
2 changes: 1 addition & 1 deletion TODO.RU
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Version: 2.5
* [-] Поддержка django-rq
* [-] Добавить приоритеты на уровне воркеров (воркеры с именами: Low, High, Medium). Далее роутить сообщение в нужный воркер
* [-] Поправить документацию с учетом 3 пунктов выше

* [-] Скрывать поля приоритета и тд, в случае когда выбранные инструменты не поддерживают Приоритет

Version: 2.6
------------
Expand Down
8 changes: 7 additions & 1 deletion dbmail/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ def get_settings(key, default):
'sms': 'dbmail.backends.sms',
'push': 'dbmail.backends.push',
})
_BACKEND = dict([(v, k) for k, v in BACKEND.items()])
_BACKEND = {v: k for k, v in BACKEND.iteritems()}
BACKENDS_MODEL_CHOICES = get_settings('DB_MAILER_BACKENDS_MODEL_CHOICES', (
(BACKEND.get('mail'), _('MailBox')),
(BACKEND.get('push'), _('Push')),
(BACKEND.get('sms'), _('SMS')),
(BACKEND.get('tts'), _('TTS')),
))

SMS_PROVIDER = get_settings(
'DB_MAILER_SMS_PROVIDER', 'dbmail.providers.nexmo.sms')
Expand Down
19 changes: 19 additions & 0 deletions dbmail/migrations/0009_auto_20160311_0918.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dbmail', '0008_auto_20151007_1918'),
]

operations = [
migrations.AlterField(
model_name='mailsubscription',
name='address',
field=models.CharField(help_text='Must be phone number/email/token', max_length=60, verbose_name='Address', db_index=True),
),
]
29 changes: 15 additions & 14 deletions dbmail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from dbmail.defaults import (
PRIORITY_STEPS, UPLOAD_TO, DEFAULT_CATEGORY, AUTH_USER_MODEL,
DEFAULT_FROM_EMAIL, DEFAULT_PRIORITY, CACHE_TTL,
BACKEND, _BACKEND, MODEL_HTMLFIELD)
BACKEND, _BACKEND, BACKENDS_MODEL_CHOICES, MODEL_HTMLFIELD)

from dbmail import initial_signals, import_by_string
from dbmail import python_2_unicode_compatible
Expand All @@ -27,13 +27,6 @@

HTMLField = import_by_string(MODEL_HTMLFIELD)

BACKENDS = (
('dbmail.backends.mail', _('MailBox')),
('dbmail.backends.push', _('Push')),
('dbmail.backends.sms', _('SMS')),
('dbmail.backends.tts', _('TTS')),
)


def _upload_mail_file(instance, filename):
if instance is not None:
Expand Down Expand Up @@ -719,8 +712,8 @@ class MailSubscriptionAbstract(models.Model):
user = models.ForeignKey(
AUTH_USER_MODEL, verbose_name=_('User'), null=True, blank=True)
backend = models.CharField(
_('Backend'), choices=BACKENDS, max_length=50,
default='dbmail.backends.mail')
_('Backend'), choices=BACKENDS_MODEL_CHOICES, max_length=50,
default=BACKEND.get('mail'))
start_hour = models.CharField(
_('Start hour'), default='00:00', max_length=5)
end_hour = models.CharField(_('End hour'), default='23:59', max_length=5)
Expand All @@ -731,14 +724,16 @@ class MailSubscriptionAbstract(models.Model):
defer_at_allowed_hours = models.BooleanField(
_('Defer at allowed hours'), default=False)
address = models.CharField(
_('Address'), max_length=60, unique=True,
_('Address'), max_length=60, db_index=True,
help_text=_('Must be phone number/email/token'))

def send_confirmation_link(self, slug='subs-confirmation', **kwargs):
def send_confirmation_link(
self, slug='subs-confirmation', *args, **kwargs):

from dbmail import db_sender

kwargs['backend'] = self.backend
db_sender(slug, self.address, **kwargs)
db_sender(slug, self.address, *args, **kwargs)

@staticmethod
def get_now():
Expand Down Expand Up @@ -773,9 +768,14 @@ def get_notification_list(cls, user_id, **kwargs):

@classmethod
def notify(cls, slug, user_id=None, sub_filter=None, **kwargs):

from dbmail import db_sender

now_hour = cls.get_current_hour()

context_dict = kwargs.pop('context', {})
context_instance = kwargs.pop('context_instance', None)

sub_filter = sub_filter if isinstance(sub_filter, dict) else {}

for method in cls.get_notification_list(user_id, **sub_filter):
Expand All @@ -800,7 +800,8 @@ def notify(cls, slug, user_id=None, sub_filter=None, **kwargs):
use_slug = extra_slug
except MailTemplate.DoesNotExist:
pass
db_sender(use_slug, method.address, **kwargs)
db_sender(use_slug, method.address, context_dict,
context_instance, **kwargs)

def update_notify_kwargs(self, **kwargs):
return kwargs
Expand Down
Loading

0 comments on commit 7b521c5

Please sign in to comment.