change email file structure and improve sale view/workflow

pull/3/head
lalanza808 5 years ago
parent 14b27fffac
commit 8e72ca630b

@ -6,24 +6,28 @@ from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.urls import reverse
from core.monero import AuctionWallet
from core.models import UserShippingAddress
from sales.models import ItemSale
class EmailTemplate:
def __init__(self, item, role):
def __init__(self, item, scenario, role):
context = {
'sale': item,
'site_name': settings.SITE_NAME,
'site_url': settings.SITE_URL,
'sale_path': reverse('get_sale', args=[item.bid.id])
'sale_path': reverse('get_sale', args=[item.bid.id]),
'shipping_address': UserShippingAddress.objects.filter(
user=item.bid.bidder
).first()
}
subject = render_to_string(
template_name=f'sales/notify/{role}/subject.txt',
template_name=f'sales/notify/{scenario}/{role}/subject.txt',
context=context,
request=None
)
body = render_to_string(
template_name=f'sales/notify/{role}/body.txt',
template_name=f'sales/notify/{scenario}/{role}/body.txt',
context=context,
request=None
)
@ -37,6 +41,7 @@ def notify_buyer_of_pending_sale():
for sale in item_sales:
email_template = EmailTemplate(
item=sale,
scenario='sale_created',
role='buyer'
)
sent = send_mail(
@ -58,6 +63,7 @@ def notify_seller_of_funds_received():
for sale in item_sales:
email_template = EmailTemplate(
item=sale,
scenario='funds_received',
role='seller'
)
sent = send_mail(

@ -4,6 +4,7 @@ from qrcode import make as qrcode_make
from django.shortcuts import render, HttpResponseRedirect, reverse
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from core.models import UserShippingAddress
from bids.models import ItemBid
from sales.models import ItemSale
@ -24,7 +25,10 @@ def get_sale(request, bid_id):
context = {
'sale': sale,
'qrcode': b64encode(_address_qr.getvalue()).decode()
'qrcode': b64encode(_address_qr.getvalue()).decode(),
'shipping_address': UserShippingAddress.objects.filter(
user=bid.bidder
).first()
}
return render(request, 'sales/get_sale.html', context)

@ -6,12 +6,15 @@
<section id="main" class="wrapper">
<div class="container">
<header class="minor">
<h2>Sale #{{ sale.id }}</h2>
<h2>Sale #{{ sale.id }} - {{ sale.item.name }}</h2>
</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">
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=200 class="sale-qrcode">
@ -23,15 +26,48 @@
<li><a href="https://www.monerujo.io/" target="_blank">Monerujo</a></li>
<li><a href="https://mymonero.com/" target="_blank">MyMonero</a></li>
</ul>
{% elif sale.payment_received %}
<p class="sale-info">Congratulations {{ sale.bid.bidder.username }},</p>
<p class="sale-info">Your funds have been confirmed!</p>
<p class="sale-info">
The seller has been notified of the proof of payment and has been provided with your shipping address.
Please make sure it is correct and will result in successful package delivery.
You can edit the address here: <a href="{% url 'edit_shipping' %}">Edit Shipping Address</a>
</p>
<p class="sale-info"><strong>Address 1</strong>: {{ shipping_address.address1 }}</p>
<p class="sale-info"><strong>Address 2</strong>: {{ shipping_address.address2 }}</p>
<p class="sale-info"><strong>City</strong>: {{ shipping_address.city }}</p>
<p class="sale-info"><strong>State</strong>: {{ shipping_address.state }}</p>
<p class="sale-info"><strong>Country</strong>: {{ shipping_address.country }}</p>
<p class="sale-info"><strong>Zip</strong>: {{ shipping_address.zip }}</p>
{% 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">
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>
{% elif sale.payment_received %}
<p class="sale-info">Congratulations {{ sale.item.owner.username }},</p>
<p class="sale-info">
The bidder for your item has sent the proper amount of funds to the escrow wallet address.
You may now proceed with shipping the item they agreed to purchase from you.
Here is the physical address you will need to mail it to:
</p>
<p class="sale-info"><strong>Address 1</strong>: {{ shipping_address.address1 }}</p>
<p class="sale-info"><strong>Address 2</strong>: {{ shipping_address.address2 }}</p>
<p class="sale-info"><strong>City</strong>: {{ shipping_address.city }}</p>
<p class="sale-info"><strong>State</strong>: {{ shipping_address.state }}</p>
<p class="sale-info"><strong>Country</strong>: {{ shipping_address.country }}</p>
<p class="sale-info"><strong>Zip</strong>: {{ shipping_address.zip }}</p>
{% endif %}
{% endif %}
{% if site_meta.debug %}

@ -1,8 +1,8 @@
Congratulations {{ sale.item.owner }},
The bidder for your item, "{{ sale.item.name }}" (#{{ sale.item.id }}), has sent the proper amount of funds to the escrow address. You may now proceed with shipping the item.
The bidder for your item, "{{ sale.item.name }}" (#{{ sale.item.id }}), has sent the proper amount of funds to the escrow address. You may now proceed with shipping the item to them.
I'll need to figure out a way to get the shipment address to you. I'll think about that. You can see more information about the sale at the following URL:
You will need to view the sale page on the site to get their address - we don't want to show it here for email privacy reasons and because it might change. Go here to view it:
https://{{ site_url }}{{ sale_path }}