Commits

Victor Gavro committed c8f1b02

Added NotImplemented exceptions, improved docstings

Comments (0)

Files changed (3)

smsgate/__init__.py

 from django.utils.translation import ugettext_noop as _
 
 backend = import_module(settings.BACKEND)
+if not hasattr(backend, 'send_sms'):
+    raise ImproperlyConfigured('Module %s doesn\'t implement send_sms' %
+                               settings.backend)
 
 
 def _get_callback_url(callback):
         if settings.CALLBACK_URL:
             return settings.CALLBACK_URL
         else:
-            raise ImproperlyConfigured
+            raise ImproperlyConfigured('You didn\'t set SMSGATE_CALLBACK_URL'
+                                       'in your settings')
     return callback
 
 
     '''
     Send SMS messages through gateway.
     Given a datatuple of (text, phones, remote_id) (remote_id is optional).
-    Returns the tuple of results.
+    Yields result for each SMS.
 
-    See smsgate.send_sms function for details.
+    If fail_silently is True, exception is suppressed and generation stops.
+    For rest see smsgate.send_sms docstring.
     '''
     if len(datatuple) == 0:
         return
     SMSGATE_CALLBACK_URL. By default callback is False.
     (Note that on some servers callback url must be set on serverside).
 
-    If fail_silently is True, all exceptions are suppressed and unknown status
+    If fail_silently is True, exception is suppressed and unknown status
     returned on fail.
     '''
     callback_url = _get_callback_url(callback)
 def get_sms_statuses(remote_ids, fail_silently=False):
     '''
     Retrieve SMS statuses from gateway.
-    Returns tuple of (status, status_text), corresponding to tuple of given
-    remote_ids.
+    Yields (status, status_text), corresponding to tuple of given remote_ids.
 
-    If fail_silently is True, all exceptions are suppressed.
+    If fail_silently is True, exception is suppressed and generation stops.
     '''
+    if not hasattr(backend, 'get_sms_statuses'):
+        raise NotImplementedError('Module %s doesn\'t support retrieving SMS '
+                                  'statuses' % settings.backend)
     if len(remote_ids) == 0:
         return
     try:

smsgate/models.py

           **kwargs
         )
         for n, (remote_id, status, status_text) in enumerate(sent_data):
-            recipients[n].set_processed(remote_id, status, status_text,
-                                        save=True)
+            recipients[n].set_processed(remote_id, status, status_text)
         return len(sent_data)
 
     def recipients_count(self):
         # Setting SMS statuses
             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)
+                recipients[n].set_processed(remote_id, status, status_text)
                 if status in settings.SUCCESS_STATUSES:
                     result_count += 1
         return sum(map(len, recipients_lists)), result_count
         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)
+            fetch_recipients[n].set_status(status, status_text, time=time)
             result_count += 1
         return len(fetch_recipients), result_count
     '''
     if request.META['REMOTE_ADDR'] not in settings.CALLBACK_IPS:
         return HttpResponse(status=403)
+    if not hasattr(backend, 'sms_callback'):
+        raise NotImplementedError('Module %s does not support sms_callback' %
+                                  settings.backend)
     for remote_id, status, status_text in backend.sms_callback(request):
-        SmsRecipient.objects.get(remote_id=remote_id).set_status(status, status_text, save=True)
+        SmsRecipient.objects.get(remote_id=remote_id).set_status(status, status_text)
     return HttpResponse(status=200)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.