diff --git a/core/middleware.py b/core/middleware.py deleted file mode 100644 index 2bfb213..0000000 --- a/core/middleware.py +++ /dev/null @@ -1,28 +0,0 @@ -from django.shortcuts import HttpResponseRedirect, reverse -from core.models import UserShippingAddress - - -class EnforceShippingAddressCreationMiddleware(object): - def __init__(self, get_response): - self.get_response = get_response - - def __call__(self, request): - - # If current user is authenticated, get their shipping information and current page - # If current page is not them editing their address or logging out, redirect them - if request.user.is_authenticated: - profile = UserShippingAddress.objects.filter(user=request.user).first() - is_profile_absent = profile is None - - allowed_paths = [ - reverse('edit_shipping'), - reverse('logout') - ] - on_allowed_path = request.path not in allowed_paths - - if is_profile_absent and on_allowed_path: - return HttpResponseRedirect(reverse('edit_shipping')) - - response = self.get_response(request) - - return response diff --git a/core/models.py b/core/models.py index 54bec96..4fea52c 100644 --- a/core/models.py +++ b/core/models.py @@ -13,7 +13,3 @@ class UserShippingAddress(models.Model): def __str__(self): return self.user.username - - -# Enforce unique email addresses -# User._meta.get_field('email')._unique = True diff --git a/sales/tasks.py b/sales/tasks.py index 6171300..2746086 100644 --- a/sales/tasks.py +++ b/sales/tasks.py @@ -102,7 +102,7 @@ def notify_seller_of_shipment_receipt(): else: return False -@periodic_task(crontab(minute='*/2')) +@periodic_task(crontab(minute='*/5')) def notify_seller_of_funds_received(): item_sales = ItemSale.objects.filter(seller_notified=False, buyer_notified=True).filter(payment_received=True) for sale in item_sales: @@ -119,7 +119,7 @@ def notify_seller_of_funds_received(): else: return False -@periodic_task(crontab(minute='*/12')) +@periodic_task(crontab(minute='*/30')) def pay_sellers_on_sold_items(): aw = AuctionWallet() if aw.connected is False: @@ -142,7 +142,6 @@ def pay_sellers_on_sold_items(): txs = aw.wallet.accounts[sale.escrow_account_index].transfer( sale.item.payout_address, sale.agreed_price_xmr, relay=True ) - print(txs) if txs: sale.seller_paid = True sale.escrow_complete = True @@ -154,9 +153,36 @@ def pay_sellers_on_sold_items(): print('unable to make payment: ', e) return False -@periodic_task(crontab(minute='*/5')) +@periodic_task(crontab(hour='*/6')) +def pay_platform_on_sold_items(): + aw = AuctionWallet() + if aw.connected is False: + return False + + aof = settings.PLATFORM_WALLET_ADDRESS + if aof is None: + aof = aw.wallet.accounts[0].address() + + item_sales = ItemSale.objects.filter(escrow_complete=True, seller_paid=True, item_received=True).filter(platform_paid=False) + for sale in item_sales: + try: + txs = aw.wallet.accounts[sale.escrow_account_index].sweep_all(aof) + if txs: + sale.platform_paid = True + sale.sale_finalized = True + sale.save() + return True + except Exception as e: + print('unable to sweep funds: ', e) + return False + + +@periodic_task(crontab(minute='*/3')) def poll_for_buyer_escrow_payments(): aw = AuctionWallet() + if aw.connected is False: + return False + item_sales = ItemSale.objects.filter(payment_received=False) for sale in item_sales: sale_account = aw.wallet.accounts[sale.escrow_account_index] diff --git a/sales/views.py b/sales/views.py index 822e357..0ae70eb 100644 --- a/sales/views.py +++ b/sales/views.py @@ -39,6 +39,8 @@ def get_sale(request, bid_id): def confirm_shipment(request, sale_id): sale = ItemSale.objects.get(id=sale_id) + # TODO - dont allow shipment if we dont have an address + # Only proceed if current user is the seller if request.user == sale.item.owner: sale.item_shipped = True diff --git a/web/templates/home.html b/web/templates/home.html index 963fa03..54c68c2 100644 --- a/web/templates/home.html +++ b/web/templates/home.html @@ -6,8 +6,8 @@ {% if request.user.is_authenticated %}
This item is currently pending sale. Bidding is temporarily closed.
{% endif %} -Seller: {{ item.owner }}
+Whereabouts: Whereabouts
Creation: {{ item.list_date | date:"d M Y H:i:s" }}
Last Updated: {{ item.last_updated | date:"d M Y H:i:s" }}
Description: {{ item.description }}
diff --git a/web/templates/items/list_items.html b/web/templates/items/list_items.html index 4028387..10d7193 100644 --- a/web/templates/items/list_items.html +++ b/web/templates/items/list_items.html @@ -10,7 +10,7 @@ID | -Seller | +Whereabouts | Name | List Date | Asking Price (XMR) | @@ -18,7 +18,7 @@ {% for item in items %}
---|---|---|---|---|---|
#{{ item.id }} | -{{ item.owner }} | +Whereabouts | {{ item.name }} | {{ item.list_date | date:"d M, Y H:i:s" }} | {{ item.ask_price_xmr }} | diff --git a/web/templates/sales/get_sale.html b/web/templates/sales/get_sale.html index 4fb788b..3877dc0 100644 --- a/web/templates/sales/get_sale.html +++ b/web/templates/sales/get_sale.html @@ -33,7 +33,7 @@