transports: check mobile numbers use the french format
This commit is contained in:
parent
2d5db8a270
commit
a1e218dd3b
|
@ -87,6 +87,7 @@ class SMSTransport(object):
|
|||
'portail_citoyen_announces/body_{category}.txt',
|
||||
'portail_citoyen_announces/body.txt',
|
||||
]
|
||||
mobile_re = re.compile('^0[67][0-9]{8}$')
|
||||
|
||||
def __init__(self, url, from_mobile, login=None, password=None, identifier='sms'):
|
||||
self.url = url
|
||||
|
@ -104,7 +105,14 @@ class SMSTransport(object):
|
|||
|
||||
def get_sms(self, category):
|
||||
qs = self.get_subscriptions(category)
|
||||
return qs.values_list('identifier', flat=True).distinct()
|
||||
for subscription in qs:
|
||||
sms = ''
|
||||
if subscription.identifier:
|
||||
sms = subscription.identifier
|
||||
elif subscription.user:
|
||||
sms = subscription.user.mobile
|
||||
if self.mobile_re.match(sms):
|
||||
yield sms
|
||||
|
||||
def send(self, announce):
|
||||
category = announce.category
|
||||
|
@ -113,7 +121,7 @@ class SMSTransport(object):
|
|||
category=category.identifier, identifier=self.identifier)
|
||||
ctx = Context({ 'announce': announce, 'site': site, 'category': category })
|
||||
body = body_template.render(ctx)
|
||||
sms = self.get_sms(category)
|
||||
sms = list(self.get_sms(category))
|
||||
logger.info(u'sending announce %(announce)s through %(mode)s to %(count)s emails',
|
||||
dict(announce=announce, mode=self.identifier, count=len(sms)))
|
||||
try:
|
||||
|
|
Reference in New Issue