0001-Simplify-SMSGatewayMixin.clean_numbers-normalize-num.patch
passerelle/sms/__init__.py | ||
---|---|---|
1 | 1 |
import re |
2 | 2 | |
3 | 3 |
from django.utils.translation import ugettext_lazy as _ |
4 | 4 | |
5 | 5 |
class SMSGatewayMixin(object): |
6 | 6 |
category = _('SMS Providers') |
7 | 7 | |
8 | 8 |
@classmethod |
9 |
def clean_numbers(cls, destinations, default_country_code, prefix='+'):
|
|
9 |
def clean_numbers(cls, destinations, default_country_code): |
|
10 | 10 |
numbers = [] |
11 | 11 |
for dest in destinations: |
12 | 12 |
# most gateways needs the number prefixed by the country code, this is |
13 | 13 |
# really unfortunate. |
14 |
dest = dest.strip() |
|
14 | 15 |
number = ''.join(re.findall('[0-9]', dest)) |
15 | 16 |
if dest.startswith('+'): |
16 |
pass # it already is fully qualified
|
|
17 |
number = '00' + number
|
|
17 | 18 |
elif number.startswith('00'): |
18 | 19 |
# assumes 00 is international access code, remove it |
19 |
number = number[2:]
|
|
20 |
pass
|
|
20 | 21 |
elif number.startswith('0'): |
21 |
# local prefix, remove 0 and add default country code |
|
22 |
# french local prefix, remove 0 and add default country code
|
|
22 | 23 |
number = default_country_code + number[1:] |
23 |
numbers.append(prefix + number)
|
|
24 |
numbers.append(number) |
|
24 | 25 |
return numbers |
25 | 26 | |
26 |
- |