Пример #1
0
 def handle(self, *args, **options):
     billables_created = 0
     for domain in Domain.get_all():
         key = [domain.name, 'SMSLog']
         start_date = [datetime.datetime(2014, 1, 1).isoformat()]
         end_date = [datetime.datetime(2014, 1, 24).isoformat()]
         sms_docs = SMSLog.get_db().view('sms/by_domain',
                                         reduce=False,
                                         startkey=key + start_date,
                                         endkey=key + end_date + [{}])
         for sms_doc in sms_docs:
             sms_log = SMSLog.get(sms_doc['id'])
             try:
                 if sms_log.phone_number is not None:
                     parse_phone_number(sms_log.phone_number)
             except PhoneNumberParseException:
                 billables = SmsBillable.objects.filter(log_id=sms_log._id)
                 if len(billables) == 0:
                     SmsBillable.create(sms_log)
                     billables_created += 1
                     print 'created SmsBillable for invalid number %s in domain %s, id=%s'\
                           % (sms_log.phone_number, domain.name, sms_log._id)
                 elif len(billables) > 1:
                     print "Warning: >1 SmsBillable exists for SMSLog with id=%" % sms_log._id
     print 'Number of SmsBillables created: %d' % billables_created
     print 'Completed retrobilling.'
Пример #2
0
 def clean_phone_number(self):
     data = self.cleaned_data['phone_number']
     parsed_number = None
     if data:
         for country in ["US", "GB", None]:
             parsed_number = parse_phone_number(data, country, failhard=False)
             if parsed_number is not None:
                 break
         if parsed_number is None:
             raise forms.ValidationError(_("It looks like this phone number is invalid. "
                                           "Did you forget the country code?"))
         return "+%s%s" % (parsed_number.country_code, parsed_number.national_number)
Пример #3
0
 def clean_phone_number(self):
     data = self.cleaned_data['phone_number']
     parsed_number = None
     if data:
         for country in ["US", "GB", None]:
             parsed_number = parse_phone_number(data,
                                                country,
                                                failhard=False)
             if parsed_number is not None:
                 break
         if parsed_number is None:
             raise forms.ValidationError(
                 _("It looks like this phone number is invalid. "
                   "Did you forget the country code?"))
         return "+%s%s" % (parsed_number.country_code,
                           parsed_number.national_number)