From 8e72ca630b99491c0a6239c966a440eb4fb3df1f Mon Sep 17 00:00:00 2001 From: lalanza808 Date: Mon, 6 Jan 2020 21:54:04 -0800 Subject: [PATCH] change email file structure and improve sale view/workflow --- sales/tasks.py | 14 ++++-- sales/views.py | 6 ++- web/templates/sales/get_sale.html | 46 +++++++++++++++++-- .../{ => funds_received}/seller/body.txt | 4 +- .../{ => funds_received}/seller/subject.txt | 0 .../notify/{ => sale_created}/buyer/body.txt | 0 .../{ => sale_created}/buyer/subject.txt | 0 7 files changed, 58 insertions(+), 12 deletions(-) rename web/templates/sales/notify/{ => funds_received}/seller/body.txt (51%) rename web/templates/sales/notify/{ => funds_received}/seller/subject.txt (100%) rename web/templates/sales/notify/{ => sale_created}/buyer/body.txt (100%) rename web/templates/sales/notify/{ => sale_created}/buyer/subject.txt (100%) diff --git a/sales/tasks.py b/sales/tasks.py index 51fd89f..d129ac2 100644 --- a/sales/tasks.py +++ b/sales/tasks.py @@ -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( diff --git a/sales/views.py b/sales/views.py index 355e72c..17f9871 100644 --- a/sales/views.py +++ b/sales/views.py @@ -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) diff --git a/web/templates/sales/get_sale.html b/web/templates/sales/get_sale.html index 750e444..13bbf5b 100644 --- a/web/templates/sales/get_sale.html +++ b/web/templates/sales/get_sale.html @@ -6,12 +6,15 @@
-

Sale #{{ sale.id }}

+

Sale #{{ sale.id }} - {{ sale.item.name }}

{% if request.user == sale.bid.bidder %} {% if sale.payment_received == False %}

Hello {{ sale.bid.bidder.username }},

-

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).

+

+ 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). +

Expected Payment (XMR): {{ sale.expected_payment_xmr }}

Escrow Address: {{ sale.escrow_address }}

@@ -23,15 +26,48 @@
  • Monerujo
  • MyMonero
  • - + {% elif sale.payment_received %} +

    Congratulations {{ sale.bid.bidder.username }},

    +

    Your funds have been confirmed!

    +

    + 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: Edit Shipping Address +

    +

    Address 1: {{ shipping_address.address1 }}

    +

    Address 2: {{ shipping_address.address2 }}

    +

    City: {{ shipping_address.city }}

    +

    State: {{ shipping_address.state }}

    +

    Country: {{ shipping_address.country }}

    +

    Zip: {{ shipping_address.zip }}

    {% endif %} {% endif %} + {% if request.user == sale.item.owner %} {% if sale.payment_received == False %}

    Hello {{ sale.item.owner.username }},

    -

    You accepted bid #{{ sale.bid.id }} on your item "{{ sale.item.name }}" (#{{ sale.item.id }}). A new sale has been initiated.

    -

    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.

    +

    + You accepted bid #{{ sale.bid.id }} on your item "{{ sale.item.name }}" (#{{ sale.item.id }}). + A new sale has been initiated. +

    +

    + 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. +

    Congratulations on the sale!

    + {% elif sale.payment_received %} +

    Congratulations {{ sale.item.owner.username }},

    +

    + 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: +

    +

    Address 1: {{ shipping_address.address1 }}

    +

    Address 2: {{ shipping_address.address2 }}

    +

    City: {{ shipping_address.city }}

    +

    State: {{ shipping_address.state }}

    +

    Country: {{ shipping_address.country }}

    +

    Zip: {{ shipping_address.zip }}

    {% endif %} {% endif %} {% if site_meta.debug %} diff --git a/web/templates/sales/notify/seller/body.txt b/web/templates/sales/notify/funds_received/seller/body.txt similarity index 51% rename from web/templates/sales/notify/seller/body.txt rename to web/templates/sales/notify/funds_received/seller/body.txt index b21334d..18dded5 100644 --- a/web/templates/sales/notify/seller/body.txt +++ b/web/templates/sales/notify/funds_received/seller/body.txt @@ -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 }} diff --git a/web/templates/sales/notify/seller/subject.txt b/web/templates/sales/notify/funds_received/seller/subject.txt similarity index 100% rename from web/templates/sales/notify/seller/subject.txt rename to web/templates/sales/notify/funds_received/seller/subject.txt diff --git a/web/templates/sales/notify/buyer/body.txt b/web/templates/sales/notify/sale_created/buyer/body.txt similarity index 100% rename from web/templates/sales/notify/buyer/body.txt rename to web/templates/sales/notify/sale_created/buyer/body.txt diff --git a/web/templates/sales/notify/buyer/subject.txt b/web/templates/sales/notify/sale_created/buyer/subject.txt similarity index 100% rename from web/templates/sales/notify/buyer/subject.txt rename to web/templates/sales/notify/sale_created/buyer/subject.txt