Commits

Matthew Schinckel committed f49d484

cleanup line lengths.

Comments (0)

Files changed (2)

 from sms.models import Gateway, Message, Reply
 
 class GatewayAdmin(admin.ModelAdmin):
-    pass
+    list_display = ('name', 'base_url')
 
 class MessageAdmin(admin.ModelAdmin):
-    pass
+    list_display = (
+        'recipient_number', 
+        'status', 
+        'sender', 
+        'local_send_time',
+        'billed',
+        'gateway',
+        'gateway_charge',
+        'billee'
+    )
+    list_filter = (
+        'status',
+        'billed',
+        'gateway'
+    )
+    search_fields = (
+        'recipient_number',
+        'content',
+    )
+    raw_id_fields = ('sender', 'content_type')
 
 class ReplyAdmin(admin.ModelAdmin):
-    pass
+    list_display = ()
     
 admin.site.register(Gateway, GatewayAdmin)
 admin.site.register(Message, MessageAdmin)

sms/models/gateway.py

     that can be used to send and receive messages.
     """
     
-    name = models.CharField(max_length=128)
+    name = models.CharField(max_length=128, unique=True)
+    
+    # These fields are used in the request to send a message via a gateway.
     base_url = models.URLField()
-    settings = jsonfield.fields.JSONField(null=True, blank=True,
+    settings = jsonfield.fields.JSONField(default={},
         help_text=_(u'A JSON Dictionary of key-value pairs that will be '
             'used for every message. Authorisation credentials should go '
             'in here, for example.'
     recipient_keyword = models.CharField(max_length=128,
         help_text=_(u'The keyword that is used in the request to identify the recipient number.')
     )
-    content_keyword = models.CharField(max_length=128)
-    uuid_keyword = models.CharField(max_length=128, null=True, blank=True)
-    charge_keyword = models.CharField(max_length=128, null=True, blank=True)
+    content_keyword = models.CharField(max_length=128,
+        help_text=_(u'The keyword that is used in the request to identify the message content.')
+    )
+    uuid_keyword = models.CharField(max_length=128, null=True, blank=True,
+        help_text=_(u'The keyword used in the request for our message reference id.')
+    )
     
-    status_mapping = jsonfield.JSONField(null=True, blank=True)
+    # These fields are used to parse the response for status/charge info
+    success_format = models.CharField(max_length=256, null=True, blank=True,
+        help_text=_(u'A regular expression that parses the response'))
+    error_format = models.CharField(max_length=256, null=True, blank=True,
+        help_text=_(u'A regular expression that parses an error response')
+    )
+    status_mapping = jsonfield.JSONField(default={},
+        help_text=_(u"A mapping of returned status codes to our status choices.")
+    )
     
-    status_msg_id = models.CharField(max_length=128, null=True, blank=True)
-    status_status = models.CharField(max_length=128, null=True, blank=True)
-    status_error_code = models.CharField(max_length=128, null=True, blank=True)
-    status_date = models.CharField(max_length=128, null=True, blank=True)
-    status_date_format = models.CharField(max_length=128, null=True, blank=True)
+    
+    charge_keyword = models.CharField(max_length=128, null=True, blank=True,
+        help_text=_(u'Used in status updates: data matching this field indicates '
+            'how many \'credits\' this message cost in the gateway'
+        )
+    )
+    
+    status_msg_id = models.CharField(max_length=128, null=True, blank=True,
+        help_text=_(u'The field that contains our message reference id '
+            '(see uuid_keyword, above).'
+        )
+    )
+    status_status = models.CharField(max_length=128, null=True, blank=True,
+        help_text=_(u'The field that contains the status code, used by status_mapping.')
+    )
+    status_error_code = models.CharField(max_length=128, null=True, blank=True,
+        help_text=_(u'The field that contains the error code. May be the same value '
+            'as status_status, if no seperate error code field is used.'
+        )
+    )
+    status_date = models.CharField(max_length=128, null=True, blank=True,
+        help_text=_(u'The field that contains the status update date-string. '
+            'See status_date_format: that is used by this field for parsing.'
+        )
+    )
+    status_date_format = models.CharField(max_length=128, null=True, blank=True,
+        help_text=_(u'Python datetime formatting code representing the format '
+            'this gateway uses for delivery time reporting. Leaving this '
+            'blank means that a unix-style timestamp is used.'
+        )
+    )
     
     reply_content = models.CharField(max_length=128, null=True, blank=True)
     reply_sender = models.CharField(max_length=128, null=True, blank=True)
     reply_date = models.CharField(max_length=128, null=True, blank=True)
     reply_date_format = models.CharField(max_length=128, null=True, blank=True,
-        default="%Y-%m-%d %H:%M:%S")
-    
-    success_format = models.CharField(max_length=256, null=True, blank=True,
-        help_text=_(u'A regular expression that parses the response'))
-    
+        default="%Y-%m-%d %H:%M:%S",
+    )
+        
 #     check_number_url = models.CharField(max_length=256, null=True, blank=True,
 #         help_text=_(u'The URL that can be used to check availability of sending to a number'))
 #     check_number_field = models.CharField(max_length=65, null=True, blank=True,
         message.gateway = self
         # Build up a URL-encoded request.
         raw_data = {}
-        raw_data.update(**self.settings)
+        if self.settings:
+            raw_data.update(**self.settings)
         if message.recipient_number:
             raw_data[self.recipient_keyword] = message.recipient_number
         else:
             raise ValueError("A recipient_number must be supplied")
         # We need to see if this message needs to be sent as unicode.
         # Could be smart and try to see if it is a short enough message.
-        # Or look for a preference that says if this person may send unicode
+        # Or look for a preference that says if this user may send unicode
         # messages?
-        # try:
-        #     str(message.content)
-        # except UnicodeEncodeError:
-        #     raw_data[self.content_keyword] = "".join(["%04x" % ord(x) for x in message.content])
-        #     raw_data["unicode"] = 1
-        # else:
-        raw_data[self.content_keyword] = unicodedata.normalize('NFKD', unicode(message.content)).encode('ascii', 'ignore')
+        raw_data[self.content_keyword] = unicodedata.normalize(
+            'NFKD', 
+            unicode(message.content)
+        ).encode('ascii', 'ignore')
         if self.uuid_keyword:
             assert message.uuid, "Message must have a valid UUID. Has it been saved?"
             raw_data[self.uuid_keyword] = message.uuid
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.