Commits

Victor Gavro committed a1b45cb

Added permissions (closes #2), small fix

Comments (0)

Files changed (3)

             count = instances[0].sms.send()
         messages.info(request, _('SMS sent to %s recipients') % count)
 
+    def get_actions(self, request):
+        actions = super(SmsAdmin, self).get_actions(request)
+        if not request.user.has_perm('smsgate.send_sms'):
+            del actions['sms_send_queued']
+        return actions
+
 
 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 statuses fetched') % len(queryset))
 sms_recipient_get_status.short_description = _('Retrieve SMS current status')
 
 
     list_filter = ('status',)
     ordering = ('-queued_time', '-sent_time', '-status_time')
 
+    def get_actions(self, request):
+        actions = super(SmsRecipientAdmin, self).get_actions(request)
+        if not request.user.has_perm('smsgate.send_sms'):
+            del actions['sms_recipient_resend']
+        if not request.user.has_perm('smsgate.get_sms_status'):
+            del actions['sms_recipient_get_status']
+        return actions
+
 
 admin.site.register(Sms, SmsAdmin)
 admin.site.register(SmsRecipient, SmsRecipientAdmin)

smsgate/models.py

     you may be more interested with SmsRecipient class.
     '''
     text = models.TextField(_('SMS text'))
-    sender = models.CharField(_('Sender'), max_length=32, default=settings.SENDER)
+    sender = models.CharField(
+        _('Sender'), max_length=32, default=settings.SENDER
+    )
 
     def __unicode__(self):
         if len(self.text) > 16:
     class Meta:
         verbose_name = _('SMS message')
         verbose_name_plural = _('SMS messages')
+        permissions = (
+            ('send_sms', 'Can send SMS'),
+        )
 
     def send(self, statuses=(STATUS_QUEUED,), recipients=None, **kwargs):
         '''
         (STATUS_UNDELIVERED, _('Undelivered')),
         (STATUS_EXPIRED, _('Expired')),
     )
-    phone = models.CharField(_('Phone number'), max_length=12,
-                             validators=[phone_validator,])
-    remote_id = models.CharField(_('Remote id'), max_length=32, editable=False)
-    status = models.SmallIntegerField(_('Status'), choices=STATUS_CHOICES,
-                                      default=STATUS_QUEUED)
-    queued_time = models.DateTimeField(_('Queued time'), default=datetime.now,
-                                       editable=False)
-    status_time = models.DateTimeField(_('Status renew time'), null=True,
-                                       blank=True, editable=False)
-    sent_time = models.DateTimeField(_('Sent time'), null=True, blank=True,
-                                     editable=False)
-    status_text = models.CharField(_('Status message'), max_length=64,
-                                   null=True, blank=True, editable=False)
+    phone = models.CharField(
+        _('Phone number'), max_length=12, validators=[phone_validator,],
+    )
+    remote_id = models.CharField(
+        _('Remote id'), max_length=32, editable=False,
+    )
+    status = models.SmallIntegerField(
+        _('Status'), choices=STATUS_CHOICES, default=STATUS_QUEUED,
+    )
+    queued_time = models.DateTimeField(
+        _('Queued time'), default=datetime.now, editable=False,
+    )
+    status_time = models.DateTimeField(
+        _('Status renew time'), null=True, blank=True, editable=False,
+    )
+    sent_time = models.DateTimeField(
+        _('Sent time'), null=True, blank=True, editable=False,
+    )
+    status_text = models.CharField(
+        _('Status message'), max_length=64, null=True, blank=True,
+        editable=False,
+    )
     # You may use credits field to store data for billing system
     credits = models.IntegerField(_('Credits'), default=1)
     sms = models.ForeignKey(Sms, related_name='recipients')
         verbose_name_plural = _('SMS recipients')
         unique_together = (('phone', 'sms'),)
         ordering = (('-queued_time'),)
+        permissions = (
+            ('get_sms_status', 'Can retrieve SMS status'),
+        )
 
     def __unicode__(self):
         return u'%s(%s)' % (self.phone, self.get_status_display())

smsgate_test/test.db

Binary file modified.