add return address for bids in case a sale proceeds

pull/3/head
lalanza808 5 years ago
parent d00202554c
commit b14655573e

@ -5,7 +5,8 @@ from bids.models import ItemBid
class CreateItemBidForm(forms.ModelForm): class CreateItemBidForm(forms.ModelForm):
class Meta: class Meta:
model = ItemBid model = ItemBid
fields = ['bid_price_xmr'] fields = ['bid_price_xmr', 'return_address']
labels = { labels = {
'bid_price_xmr': 'Bid Price (XMR)' 'bid_price_xmr': 'Bid Price (XMR)',
'return_address': 'Return Wallet Address'
} }

@ -1,5 +1,6 @@
# Generated by Django 2.2.7 on 2019-12-13 05:46 # Generated by Django 2.2.7 on 2019-12-13 05:46
import core.validators
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -25,6 +26,7 @@ class Migration(migrations.Migration):
('accepted', models.BooleanField(default=False)), ('accepted', models.BooleanField(default=False)),
('bidder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidder', to=settings.AUTH_USER_MODEL)), ('bidder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidder', to=settings.AUTH_USER_MODEL)),
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bids', to='items.Item')), ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bids', to='items.Item')),
('return_address', models.CharField(max_length=100, validators=[core.validators.address_is_valid_monero])),
], ],
), ),
] ]

@ -1,6 +1,7 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from items.models import Item from items.models import Item
from core.validators import address_is_valid_monero
class ItemBid(models.Model): class ItemBid(models.Model):
@ -10,6 +11,7 @@ class ItemBid(models.Model):
last_updated = models.DateTimeField(auto_now=True) last_updated = models.DateTimeField(auto_now=True)
bid_price_xmr = models.FloatField() bid_price_xmr = models.FloatField()
accepted = models.BooleanField(default=False) accepted = models.BooleanField(default=False)
return_address = models.CharField(max_length=100, validators=[address_is_valid_monero])
def __str__(self): def __str__(self):
return f"{self.id} - {self.item.name} - {self.bidder} > {self.item.owner}" return f"{self.id} - {self.item.name} - {self.bidder} > {self.item.owner}"

@ -56,6 +56,12 @@ def create_bid(request, item_id):
bid.item = item bid.item = item
bid.save() bid.save()
return HttpResponseRedirect(reverse('get_item', args=[item_id])) return HttpResponseRedirect(reverse('get_item', args=[item_id]))
else:
form_errors = form.errors.get_json_data()
for err in form_errors:
err_data = form_errors[err][0]
messages.error(request, f'{err}: {err_data["message"]}')
return HttpResponseRedirect(reverse('create_bid', args=[item_id]))
else: else:
context = { context = {
'form': CreateItemBidForm(), 'form': CreateItemBidForm(),
@ -84,6 +90,12 @@ def edit_bid(request, bid_id):
if form.is_valid(): if form.is_valid():
form.save() form.save()
return HttpResponseRedirect(reverse('get_item', args=[bid.item.id])) return HttpResponseRedirect(reverse('get_item', args=[bid.item.id]))
else:
form_errors = form.errors.get_json_data()
for err in form_errors:
err_data = form_errors[err][0]
messages.error(request, f'{err}: {err_data["message"]}')
return HttpResponseRedirect(reverse('create_bid', args=[bid.item.id]))
else: else:
context = { context = {
'form': CreateItemBidForm(instance=bid), 'form': CreateItemBidForm(instance=bid),