Victor Gavro  committed 14fd709

generators correctly used in models, mass_send and get_statuses class methods now returns tuple of (total,real) result

  • Participants
  • Parent commits 03dfa64

Comments (0)

Files changed (3)

File smsgate/management/commands/

     def handle(self, *args, **options):
         statuses = map(int, options['sms_statuses'].split(','))
         count = SmsRecipient.get_statuses(statuses)
-        print '%s statuses retrieved.' % count
+        print '%s/%s statuses retrieved.' % count

File smsgate/management/commands/

     def handle(self, *args, **options):
         statuses = map(int, options['sms_statuses'].split(','))
         count = Sms.mass_send(statuses)
-        print '%s messages sent.' % count
+        print '%s/%s messages sent.' % count

File smsgate/

     def mass_send(cls, statuses=(STATUS_QUEUED,), *kwargs):
         Send all stored SMS messages with given statuses (default - queued).
-        Returns count of total recipients.
+        Returns tuple of total and sent recipients count.
         You may also specify keyword arguments for passing to
-        mass_sent_data = send_mass_sms(datatuple, **kwargs)
+        result_count = 0
+        for x, sent_data in enumerate(send_mass_sms(datatuple, **kwargs)):
         # Setting SMS statuses
-        for x, sent_data in enumerate(mass_sent_data):
             recipients = recipients_lists[x]
             for n, (remote_id, status, status_text) in enumerate(sent_data):
                 recipients[n].set_processed(remote_id, status,
                                             status_text, save=True)
-        return len(mass_sent_data)
+                if status in settings.SUCCESS_STATUSES:
+                    result_count += 1
+        return sum(map(len, recipients_lists)), result_count
 class SmsRecipient(models.Model):
         Retrieve and set statuses of SMS with given statuses (defaults to sent
         or unknown). Note that it skips recipients with empty remote_id.
-        Returns count of fetched statuses.
+        Returns tuple of total and fetched statuses count.
         time =
         if not recipients:
             elif obj.remote_id:
-        fetched_statuses = get_sms_statuses([r.remote_id for r in fetch_recipients])
-        for n, (status, status_text) in enumerate(fetched_statuses):
+        remote_ids = [r.remote_id for r in fetch_recipients]
+        result_count = 0
+        for n, (status, status_text) in enumerate(get_sms_statuses(remote_ids)):
             fetch_recipients[n].set_status(status, status_text, time=time, save=True)
-        return len(fetched_statuses)
+            result_count += 1
+        return len(fetch_recipients), result_count