improving sale view content and adding escrow address qr code

pull/3/head
lalanza808 5 years ago
parent 8b54a01fe5
commit 6106ce3e86

@ -1,3 +1,6 @@
from io import BytesIO
from base64 import b64encode
from qrcode import make as qrcode_make
from django.shortcuts import render, HttpResponseRedirect, reverse from django.shortcuts import render, HttpResponseRedirect, reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib import messages from django.contrib import messages
@ -5,6 +8,7 @@ from bids.models import ItemBid
from sales.models import ItemSale from sales.models import ItemSale
@login_required @login_required
def get_sale(request, bid_id): def get_sale(request, bid_id):
bid = ItemBid.objects.get(id=bid_id) bid = ItemBid.objects.get(id=bid_id)
@ -15,8 +19,12 @@ def get_sale(request, bid_id):
messages.error(request, "You can't view a sale you are not involved in.") messages.error(request, "You can't view a sale you are not involved in.")
return HttpResponseRedirect(reverse('home')) return HttpResponseRedirect(reverse('home'))
_address_qr = BytesIO()
address_qr = qrcode_make(sale.escrow_address).save(_address_qr)
context = { context = {
'sale': sale 'sale': sale,
'qrcode': b64encode(_address_qr.getvalue()).decode()
} }
return render(request, 'sales/get_sale.html', context) return render(request, 'sales/get_sale.html', context)

@ -5,8 +5,27 @@
<section id="main" class="wrapper"> <section id="main" class="wrapper">
<div class="container"> <div class="container">
<header class="minor"> <header class="minor">
<h2>Sale Info</h2> <h2>Sale #{{ sale.id }}</h2>
</header> </header>
{% if request.user == sale.bid.bidder %}
{% if sale.payment_received == False %}
<p class="sale-info">Hello {{ sale.bid.bidder.username }},</p>
<p class="sale-info">The seller accepted your bid and the sale process was initiated. Please send funds to the below Monero escrow address (or use the QR code).</p>
<p class="sale-info"><strong>Expected Payment (XMR)</strong>: {{ sale.expected_payment_xmr }}</p>
<p class="sale-info"><strong>Escrow Address</strong>: {{ sale.escrow_address }}</p>
<img src="data:image/png;base64,{{ qrcode }}" width=300>
{% endif %}
{% endif %}
{% if request.user == sale.item.owner %}
{% if sale.payment_received == False %}
<p class="sale-info">Hello {{ sale.item.owner.username }},</p>
<p class="sale-info">You accepted bid #{{ sale.bid.id }} on your item "<a href="{% url 'get_item' sale.item.id %}">{{ sale.item.name }}</a>" (#{{ sale.item.id }}). A new sale has been initiated.</p>
<p class="sale-info">We are waiting for the buyer to send funds to the escrow address. No action is needed from you at this time, but you will be notified you when there is.</p>
<p class="sale-info">Congratulations on the sale!</p>
{% endif %}
{% endif %}
{% if site_meta.debug %}
<hr>
<section> <section>
<p class="sale-info"><strong>Item</strong>: {{ sale.item }}</p> <p class="sale-info"><strong>Item</strong>: {{ sale.item }}</p>
<p class="sale-info"><strong>Payout Address</strong>: {{ sale.item.payout_address }}</p> <p class="sale-info"><strong>Payout Address</strong>: {{ sale.item.payout_address }}</p>
@ -30,6 +49,7 @@
<p class="sale-info"><strong>Platform Paid</strong>: {{ sale.platform_paid }}</p> <p class="sale-info"><strong>Platform Paid</strong>: {{ sale.platform_paid }}</p>
<p class="sale-info"><strong>Sale Finalized</strong>: {{ sale.sale_finalized }}</p> <p class="sale-info"><strong>Sale Finalized</strong>: {{ sale.sale_finalized }}</p>
</section> </section>
{% endif %}
</div> </div>
</section> </section>