Commits

Victor Gavro committed db83ce3

improved admin, added translation to status_message on admin page, added colored status

Comments (0)

Files changed (3)

   self.message_user(request, _('%s SMS messages sent') % len(queryset))
 sms_send_queued.short_description = _('Send SMS to queued recipients')
 
+class SmsRecipientInline(admin.TabularInline):
+  model = SmsRecipient
+
+class SmsAdmin(admin.ModelAdmin):
+  list_display = ('__unicode__','sender','recipients_count','recipients_success_count')
+  actions = [sms_send_queued,]
+  inlines = (
+    SmsRecipientInline,
+  )
+  ordering = ('-id',)
+
 def sms_recipient_get_status(self, request, queryset):
   count = SmsRecipient.get_statuses(recipients=queryset)
   self.message_user(request,_('%s SMS statuses fetched') % count)
   self.message_user(request,_('%s SMS messages sent') % len(queryset))
 sms_recipient_resend.short_description = _('Resend SMS to recipient')
 
-def sms_start_text(obj):
-  return unicode(obj)
-sms_start_text.short_description = _('SMS text')
-def sms_recipients_count(obj):
-  return obj.recipients.all().count()
-sms_recipients_count.short_description = _('Total recipients')
-def sms_success_count(obj):
-  return obj.recipients.filter(status__in = settings.SUCCESS_STATUSES).count()
-sms_success_count.short_description = _('Successed recipients')
-
-class SmsRecipientInline(admin.TabularInline):
-  model = SmsRecipient
-
-class SmsAdmin(admin.ModelAdmin):
-  list_display = (sms_start_text,'sender',sms_recipients_count,sms_success_count)
-  actions = [sms_send_queued,]
-  inlines = (
-    SmsRecipientInline,
-  )
-  ordering = ('-id',)
-
 class SmsRecipientAdmin(admin.ModelAdmin):
   actions = [sms_recipient_get_status,sms_recipient_resend]
-  list_display = ('phone','sms','status','status_text','status_time','sent_time','queued_time')
+  list_display = ('phone','sms','status_colored','status_text_translated','status_time','sent_time','queued_time')
   list_filter = ('status',)
   ordering = ('-queued_time','-sent_time','-status_time')
 

smsgate/models.py

     for n,(remote_id,status,status_text) in enumerate(sent_data):
       recipients[n].set_processed(remote_id,status,status_text,save=True)
 
+  def recipients_count(self):
+    return self.recipients.all().count()
+  recipients_count.short_description = _('Total recipients')
+
+  def recipients_success_count(self):
+    return self.recipients.filter(status__in = settings.SUCCESS_STATUSES).count()
+  recipients_success_count.short_description = _('Successed recipients')
+
+
   @classmethod
   def create(cls,text,recipients_list,sender=settings.SENDER,send=settings.SEND_ON_SAVE):
     if not recipients_list:
       status,status_text = get_sms_statuses((self.remote_id,))[0]
       self.set_status(status,status_text,save=save)
 
+  def status_color(self):
+    return settings.STATUS_COLORS[self.status]
+
+  def status_colored(self):
+    return u'<span style="color: %s;">%s</span>' % (self.status_color(),self.get_status_display())
+  status_colored.short_description = _('Status')
+  status_colored.allow_tags = True
+  status_colored.admin_order_field = 'status'
+
+  def status_text_translated(self):
+    return _(self.status_text)
+  status_text_translated.short_description = _('Status message')
+
   @classmethod
   def get_statuses(cls,statuses=(STATUS_SENT,STATUS_UNKNOWN),set_status=True,set_expired=True,recipients=None):
     time = datetime.now()

smsgate/settings.py

 ADMINS_PHONES = _get('ADMINS_PHONES',())
 MANAGERS_PHONES = _get('MANAGERS_PHONES',())
 
+STATUS_COLORS = _get('STATUS_COLORS',{
+  STATUS_QUEUED: 'blue',
+  STATUS_CANCELED: 'red',
+  STATUS_SENT: 'yellow',
+  STATUS_UNSENT: 'red',
+  STATUS_UNKNOWN: 'red',
+  STATUS_REMOTE_QUEUED: 'blue',
+  STATUS_DELIVERED: 'green',
+  STATUS_UNDELIVERED: 'red',
+  STATUS_EXPIRED: 'red',
+})
+
 SUCCESS_STATUSES = (STATUS_SENT,STATUS_DELIVERED)