def download(request, key, format, page_size="A4"): wallet = get_object_or_404(Wallet, key=key) page_size_prefix = "" if page_size == "US": page_size_prefix = "us-" fn = '/static/%s/tips-%s%s.%s' % (format, page_size_prefix, wallet.key, format) i = 0 while not os.path.exists("%s/%s" % (settings.PROJECT_DIR, fn)): if i == 0: result = celery_generate_pdf.delay(wallet) time.sleep(25) if i > 0: ctx = {'result': result.ready(), 'info': result.info} return render_to_response("not_yet.html", context_instance=RequestContext( request, ctx)) i += 1 return HttpResponseRedirect(fn)
def wallet(request, key): site = request.META.get('HTTP_HOST', '').lower() template_mod = "" # time.sleep(0.25) wallet = get_object_or_404(Wallet, key=key) #custom = request.GET.get("c") ctx = { 'wallet': wallet, 'json_rates': json.dumps(CURRENCY_RATES), 'json_messages': json.dumps(MESSAGES), 'json_signs': json.dumps(CURRENCY_SIGNS) } if wallet.atime: # if already paid and activated return private(request, key, wallet) # Check if it was paid if wallet.bcaddr and not wallet.atime: balance = BITCOIND.getbalance(wallet.get_account(), 0) if balance and balance >= wallet.invoice_btc: wallet.atime = datetime.datetime.now() wallet.activated = True wallet.balance = balance * 1e8 # get our fees if wallet.price: fee = wallet.divide_by * wallet.quantity # pure tips fee = fee / 100 * wallet.price fee = fee / wallet.rate if wallet.template == "005-premium.odt": fee += Decimal("0.0001") if wallet.print_and_post: pap_total = 2 + wallet.quantity / 9.0 * 1 pap_total = pap_total / wallet.rate pap_total = round(pap_total, 8) wallet.save() if wallet.email: send_mail( 'new BCTIP wallet', 'Congratulations!\n\nYour new BCTip wallet is available at: https://www.bctip.org/w/%s/' % (wallet.key), '*****@*****.**', [wallet.email], fail_silently=True) # wallet.get_absolute_url() return HttpResponseRedirect( reverse('wallet', kwargs={'key': wallet.key})) if request.POST: form = WalletForm(request.POST) if form.is_valid(): wallet.bcaddr_from = form.cleaned_data['bcaddr_from'] wallet.divide_by = form.cleaned_data['divide_by'] wallet.quantity = form.cleaned_data['quantity'] wallet.price = form.cleaned_data['price'] wallet.message = form.cleaned_data['message'] wallet.template = form.cleaned_data['template'] wallet.divide_currency = form.cleaned_data['divide_currency'] # request.form.cleaned_data['target_language'] wallet.target_language = request.LANGUAGE_CODE wallet.email = form.cleaned_data['email'] wallet.expiration = form.cleaned_data['expiration'] total_usd = wallet.divide_by * Decimal( wallet.quantity) # pure tips # tips and price for service total_usd = total_usd + total_usd / Decimal(100) * wallet.price if form.cleaned_data['print_and_post']: wallet.print_and_post = True pap_total = 2 + wallet.quantity / 9.0 * 1 # 2 + 1 for each sheet total_usd += Decimal(pap_total) a = Address(wallet=wallet) a.address1 = form.cleaned_data['address1'] a.address2 = form.cleaned_data['address2'] a.city = form.cleaned_data['city'] a.state = form.cleaned_data['state'] a.country = form.cleaned_data['country'] a.postal_code = form.cleaned_data['postal_code'] a.save() # ัั-ัะพ! wallet.invoice = total_usd/wallet.rate / \ Decimal( CURRENCY_RATES[wallet.divide_currency])*Decimal(1e8) # usd->btc wallet.fee = Decimal("%.8f" % get_est_fee()) wallet.invoice += Decimal(wallet.quantity) * \ Decimal("%.8f" % round(get_est_fee()/3,8)) * Decimal(1e8) # premium template extra if wallet.template == "005-premium.odt": wallet.invoice += Decimal(0.0001) * Decimal(1e8) wallet.bcaddr = BITCOIND.getnewaddress(wallet.get_account()) # wallet.bcaddr_segwit = BITCOIND.addwitnessaddress(wallet.bcaddr) isvalid = BITCOIND.validateaddress(wallet.bcaddr_from)['isvalid'] wallet.save() generate_tips(wallet) celery_generate_pdf.delay(wallet) response = HttpResponseRedirect( reverse('wallet', kwargs={'key': wallet.key})) if wallet.email: email = pickle.dumps(wallet.email, protocol=0) response.set_cookie('email', email) response.set_cookie('bcaddr_from', wallet.bcaddr_from) return response else: initial = { 'divide_currency': 'USD', 'divide_by': 5, 'quantity': 10, 'price': "5", "template": '001-original', "message": _('Thank you for your service!') } email = request.COOKIES.get('email') if email: try: email = pickle.loads(email) except: pass initial['email'] = email bcaddr_from = request.COOKIES.get('bcaddr_from') if bcaddr_from: initial['bcaddr_from'] = bcaddr_from form = WalletForm(initial=initial) ctx['form'] = form ctx['est_fee'] = Decimal("%.8f" % round(get_est_fee() / 3, 8)) if wallet.bcaddr and not wallet.atime: return arender(request, 'wallet-new-unpaid%s.html' % template_mod, ctx) else: return arender(request, 'wallet-new%s.html' % template_mod, ctx)