Commits

Matthew Schinckel committed 24daedb

Added support for number checking. Not really tested much.

Comments (0)

Files changed (3)

 
 class GatewayAdmin(admin.ModelAdmin):
     list_display = ('name', 'base_url')
+    
+    fieldsets = (
+        (None, {'fields': [
+            'name',
+            'base_url',
+            'settings',
+        ]}),
+        ('Sending parameters', {'fields': [
+            'recipient_keyword',
+            'content_keyword',
+            'uuid_keyword',
+        ]}),
+        ('Response handling', {'fields': [
+            ('success_format', 'status_mapping'),
+            'error_format',
+            'charge_keyword',
+        ]}),
+        ('Status callback handling', {'fields': [
+            ('status_msg_id', 'status_status'),
+            ('status_date', 'status_date_format'),
+        ]}),
+        ('Reply handling', {'fields': [
+            'reply_content',
+            'reply_sender',
+            ('reply_date', 'reply_date_format'),
+        ]}),
+        ('Check number handling', {'fields': [
+            ('check_number_url','check_number_field',),
+            ('check_number_response_format', 'check_number_status_mapping'),
+        ]}),
+        ('Balance inquriy', {'fields': [
+            ('query_balance_url', 'query_balance_params'),
+            'query_balance_response_format',
+        ]})
+    )
 
 class MessageAdmin(admin.ModelAdmin):
     list_display = (

sms/migrations/0005_auto__add_field_gateway_check_number_url__add_field_gateway_check_numb.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding field 'Gateway.check_number_url'
+        db.add_column('sms_gateway', 'check_number_url', self.gf('django.db.models.fields.CharField')(max_length=256, null=True, blank=True), keep_default=False)
+
+        # Adding field 'Gateway.check_number_field'
+        db.add_column('sms_gateway', 'check_number_field', self.gf('django.db.models.fields.CharField')(max_length=65, null=True, blank=True), keep_default=False)
+
+        # Adding field 'Gateway.check_number_response_format'
+        db.add_column('sms_gateway', 'check_number_response_format', self.gf('django.db.models.fields.CharField')(max_length=256, null=True, blank=True), keep_default=False)
+
+        # Adding field 'Gateway.check_number_status_mapping'
+        db.add_column('sms_gateway', 'check_number_status_mapping', self.gf('jsonfield.fields.JSONField')(null=True, blank=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Gateway.check_number_url'
+        db.delete_column('sms_gateway', 'check_number_url')
+
+        # Deleting field 'Gateway.check_number_field'
+        db.delete_column('sms_gateway', 'check_number_field')
+
+        # Deleting field 'Gateway.check_number_response_format'
+        db.delete_column('sms_gateway', 'check_number_response_format')
+
+        # Deleting field 'Gateway.check_number_status_mapping'
+        db.delete_column('sms_gateway', 'check_number_status_mapping')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'rank': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '5'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '128'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '128', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'sms.gateway': {
+            'Meta': {'object_name': 'Gateway'},
+            'base_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'charge_keyword': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'check_number_field': ('django.db.models.fields.CharField', [], {'max_length': '65', 'null': 'True', 'blank': 'True'}),
+            'check_number_response_format': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'check_number_status_mapping': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}),
+            'check_number_url': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'content_keyword': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'error_format': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
+            'query_balance_params': ('jsonfield.fields.JSONField', [], {'default': '[]'}),
+            'query_balance_response_format': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'query_balance_url': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'recipient_keyword': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'reply_content': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'reply_date': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'reply_date_format': ('django.db.models.fields.CharField', [], {'default': "'%Y-%m-%d %H:%M:%S'", 'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'reply_sender': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'settings': ('jsonfield.fields.JSONField', [], {'default': '{}'}),
+            'status_date': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'status_date_format': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'status_error_code': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'status_mapping': ('jsonfield.fields.JSONField', [], {'default': '{}'}),
+            'status_msg_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'status_status': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'success_format': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'uuid_keyword': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'})
+        },
+        'sms.message': {
+            'Meta': {'ordering': "('send_date',)", 'object_name': 'Message'},
+            'billed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'delivery_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'gateway': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sms.Gateway']", 'null': 'True', 'blank': 'True'}),
+            'gateway_charge': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '10', 'decimal_places': '5', 'blank': 'True'}),
+            'gateway_message_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'recipient_number': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'reply_callback': ('picklefield.fields.PickledObjectField', [], {'null': 'True', 'blank': 'True'}),
+            'send_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'sender': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sent_sms_messages'", 'to': "orm['auth.User']"}),
+            'status': ('django.db.models.fields.CharField', [], {'default': "'Unsent'", 'max_length': '16'}),
+            'status_message': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'uuid': ('uuidfield.fields.UUIDField', [], {'max_length': '36', 'auto': 'True', 'null': 'True', 'blank': 'True'})
+        },
+        'sms.messageset': {
+            'Meta': {'object_name': 'MessageSet'},
+            'data': ('jsonfield.fields.JSONField', [], {'default': '{}'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'uuid': ('uuidfield.fields.UUIDField', [], {'max_length': '36', 'auto': 'True', 'null': 'True', 'blank': 'True'})
+        },
+        'sms.reply': {
+            'Meta': {'object_name': 'Reply'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'date': ('django.db.models.fields.DateTimeField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'message': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'replies'", 'to': "orm['sms.Message']"})
+        }
+    }
+
+    complete_apps = ['sms']

sms/models/gateway.py

         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,
-#         help_text=_(u'The keyword that contains the number to check'))
-#     check_number_response_format = models.CharField(max_length=256, null=True, blank=True,
-#         help_text=_(u'A regular expression that parses the response. Keys: status, charge'))
-#     check_number_status_mapping = jsonfield.JSONField(null=True, blank=True)
+    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,
+        help_text=_(u'The keyword that contains the number to check'))
+    check_number_response_format = models.CharField(max_length=256, null=True, blank=True,
+        help_text=_(u'A regular expression that parses the response. Keys: status, charge'))
+    check_number_status_mapping = jsonfield.JSONField(null=True, blank=True)
     
     query_balance_url = models.CharField(max_length=256, null=True, blank=True,
         help_text=_(u'The url path that queries for balance'))
             status = self.check_number_status_mapping.get(parsed_response.get('status', None), None)
             charge = self.check_number_status_mapping.get(parsed_response.get('charge', None), None)
         
-        # Now what?
+            return {
+                'number': number,
+                'status': status,
+                'charge': charge
+            }
     
     def query_balance(self):
         if not self.query_balance_url: