def multi_send(request, et_id): et = EMailTemplate.get_by_id(int(et_id)) if et is None: raise Http404 if not et.valid: raise Http404 if request.method == 'POST': form = EMailMultiForm(request.POST) if form.is_valid(): el = form.cleaned_data['emails'] els = list(el.split()) els_c = len(els) logging.info('list size %d'%(els_c)) if els_c > 0: ej = EMailJob() ej.setData(els,et.data) ej.save() plan_send_multimail(els,ej.key().id()) return redirect('../..') else: form = EMailMultiForm() return render_to_response('admin/emailtemplate_multisend.html', RequestContext(request, { 'form': form, 'et':et }) )
def plan_multimail(request): logging.info(request.POST) recipients = request.POST.getlist('recipients') ej_id = request.POST['ej_id'] if (ej_id is None): return HttpResponse('error') if (recipients is None) or (len(recipients)==0): return HttpResponse('error') if len(recipients)==1: plan_send_mail(recipients[0],ej_id) else: sp = len(recipients)/2 plan_send_multimail(recipients[:sp],ej_id) plan_send_multimail(recipients[sp:],ej_id) return HttpResponse('ok')