Merge branch 'master' into debian

This commit is contained in:
Jérôme Schneider 2013-06-28 17:16:48 +02:00
commit 58df7a029f
4 changed files with 11 additions and 4 deletions

View File

@ -14,6 +14,7 @@ class SendingAction(object):
def __init__(self, mode):
self.mode = mode
self.__name__ = mode
@property
def short_description(self):

View File

@ -45,6 +45,6 @@ class SubscriptionForm(forms.Form):
for category, transport in wanted_subscriptions:
models.Subscription.objects.get_or_create(
user=self.user,
identifier=self.user.mobile,
identifier='',
category=category,
transport=transport)

View File

@ -80,7 +80,7 @@ class Subscription(TimeStampedModel):
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user'),
blank=True, null=True)
category = models.ForeignKey('Category', verbose_name=_('category'))
identifier = models.CharField(_('identifier'), max_length=128, blank=False,
identifier = models.CharField(_('identifier'), max_length=128, blank=True,
help_text=_('ex.: email, mobile phone number, jabber id'))
transport = models.CharField(_('transport'),
max_length=32, choices=transports.get_transport_choices(),

View File

@ -181,7 +181,13 @@ class EmailTransport(object):
def get_emails(self, category):
qs = self.get_subscriptions(category)
return qs.values_list('identifier', flat=True).distinct()
for subscription in qs:
email = ''
if subscription.identifier:
email = subscription.identifier
elif subscription.user:
email = subscription.user.email
yield email
def send(self, announce):
category = announce.category
@ -193,7 +199,7 @@ class EmailTransport(object):
ctx = Context({ 'announce': announce, 'site': site, 'category': category })
subject = subject_template.render(ctx).replace('\r', '').replace('\n', '')
body = body_template.render(ctx)
emails = self.get_emails(category)
emails = list(self.get_emails(category))
logger.info(u'sending announce %(announce)s through %(mode)s to %(count)s emails',
dict(announce=announce, mode=self.identifier, count=len(emails)))
try: