Пример #1
0
def send(request):
    if request.method == 'POST':
        form = SendForm(request.POST)

        if form.is_valid():
            message = form.cleaned_data['message']
            comment = form.cleaned_data['comment']
            phone_n = form.cleaned_data['phone_n']

            item = QueueItem(phone_n=phone_n,
                             message=message,
                             comment=comment,
                             partner=Partner.objects.get(user=request.user.id),
                             status_message="ADDED TO QUEUE")
            item.save()

            result = SendSms.delay(item)

            SmsLog.objects.create(item=item, text='Added: %s; phone_n: %s; message: %s; task_id: %s' %
                                                  (request.user.id, phone_n, message, result.task_id))

            return response_json({'status': 0, 'id': item.id})
        else:
            return response_json({'status': 1, 'message': 'form is invalid', 'form_errors': form.errors})
    else:
        return HttpResponse(status=405) # method not allowed
Пример #2
0
def wallet(request, uuid):

    try:
        instawallet=InstaWallet.objects.get(uuid=uuid)
    except:
        return HttpResponseRedirect('/404')

    if request.method == 'POST': # If the form has been submitted...
        form = SendForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # check if 
            if len(form.cleaned_data["address_to"])>30 \
                and len(form.cleaned_data["address_to"])<37:
                try:
                    instawallet.wallet.send_to_address(form.cleaned_data["address_to"], form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to bitcoin address "+form.cleaned_data["address_to"]))
                except:
                    messages.add_message(request, messages.ERROR, sys.exc_info()[0])
            else:
                otherwallets=InstaWallet.objects.filter(uuid__startswith=form.cleaned_data["address_to"])
                if len(otherwallets)==1:
                    instawallet.wallet.send_to_wallet(otherwallets[0].wallet, form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to another instawallet "+form.cleaned_data["address_to"]))
                else:
                    messages.add_message(request, messages.ERROR, _(u"Address not an valid bitcoin address or wallet uuid not found."))
    else:
        form = SendForm() # An unbound form

    return render_to_response("instawallet.html", {
        "instawallet": instawallet,
        "form": form,
        }, context_instance=RequestContext(request))
Пример #3
0
def send(request):
    if request.method == 'POST':
        form = SendForm(request.POST)

        if form.is_valid():
            message = form.cleaned_data['message']
            comment = form.cleaned_data['comment']
            phone_n = form.cleaned_data['phone_n']

            item = QueueItem(phone_n=phone_n,
                             message=message,
                             comment=comment,
                             partner=request.user.get_profile(),
                             status_message="ADDED TO QUEUE")
            item.save()
            
            result = SendSms.delay(item)

            SmsLog.objects.create(item=item, text='Added: %s; phone_n: %s; message: %s; task_id: %s' %
                                                  (request.user.id, phone_n, message, result.task_id))

            return response_json({'status': 0, 'id': item.id})
        else:
            return response_json({'status': 1, 'message': 'form is invalid', 'form_errors': form.errors})
    else:
        return HttpResponse(status=405) # method not allowed
Пример #4
0
def wallet(request, uuid):

    try:
        instawallet = InstaWallet.objects.get(uuid=uuid)
    except:
        return HttpResponseRedirect('/404')

    if request.method == 'POST':  # If the form has been submitted...
        form = SendForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # check if
            if len(form.cleaned_data["address_to"])>30 \
                and len(form.cleaned_data["address_to"])<37:
                try:
                    instawallet.wallet.send_to_address(
                        form.cleaned_data["address_to"],
                        form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to bitcoin address "+form.cleaned_data["address_to"]))
                except:
                    messages.add_message(request, messages.ERROR,
                                         sys.exc_info()[0])
            else:
                otherwallets = InstaWallet.objects.filter(
                    uuid__startswith=form.cleaned_data["address_to"])
                if len(otherwallets) == 1:
                    instawallet.wallet.send_to_wallet(
                        otherwallets[0].wallet, form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to another instawallet "+form.cleaned_data["address_to"]))
                else:
                    messages.add_message(
                        request, messages.ERROR,
                        _(u"Address not an valid bitcoin address or wallet uuid not found."
                          ))
    else:
        form = SendForm()  # An unbound form

    return render_to_response("instawallet.html", {
        "instawallet": instawallet,
        "form": form,
    },
                              context_instance=RequestContext(request))
Пример #5
0
def home(request):
    if request.method == 'GET':
        initial={
            'mails':'[email protected],[email protected],[email protected]',
            'tmail':1,
        }
        form = SendForm(initial=initial)
    else:
        form = SendForm(request.POST)
        if form.is_valid():
            send = form.save()
            total,success = send.do()
            msg = '%d 封邮件正在等待发送' % (total)
            messages.success(request,msg)
            return redirect('home')

    ctx = {'form':form}
    ctx['objs'] = m.Tmail.objects.all()
    return render(request,'home.html',ctx)