def send_sms(self, request, queryset): form = None if 'apply' in request.POST: form = SendSmsForm(request.POST) if form.is_valid(): vumi = VumiSmsApi() message = form.cleaned_data["message"] if queryset.count() <= settings.MIN_VUMI_CELERY_SEND: successful, fail = vumi.send_all(queryset, message) async = False else: #Use celery task bulk_send_all.delay(queryset, message) successful = 0 fail = [] async = True return render_to_response( 'admin/auth/sms_result.html', { 'redirect': request.get_full_path(), 'success_num': successful, 'fail': fail, 'async': async }, ) if not form: form = SendSmsForm( initial={ '_selected_action': request.POST.getlist( admin.ACTION_CHECKBOX_NAME, ), } ) return render_to_response( 'admin/auth/send_sms.html', { 'sms_form': form, 'learners': queryset }, context_instance=template.RequestContext(request) )
def bulk_send_all(queryset, message): vumi_api = VumiSmsApi() successful, fail = vumi_api.send_all(queryset, message) subject = 'Vumi SMS Send' message = "\n".join([ "Message: " + message, "Time: " + str(datetime.now()), "Successful sends: " + str(successful), "Failures: " + ", ".join(fail) ]) mail_managers( subject=subject, message=message, fail_silently=False ) return successful, fail
def send_sms(msisdn, message, password, autologin): vumi_api = VumiSmsApi() sms, sent = vumi_api.send(msisdn, message, password, autologin)