Commit fb02c023 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added ability to edit bids

parent d73192f6
......@@ -129,6 +129,8 @@ class Bid(TimeStampedModel):
validators=[MaxValueValidator(1000)],)
text = models.CharField(blank=True, max_length=2000,)
slug = RandomSlugField(length=6)
def __unicode__(self):
return '%s\'s bid for $%s' % (self.bidder, str(self.price))
......
{% extends 'layouts/base.html' %}
{% block title %}
SRCT Bookshare • {{ listing.title }} • Edit Bid
{% endblock %}
{% block content %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-12 text-center">
<h1><strong>SRCT</strong>&#8203;BOOKSHARE</h1>
<p class="lead text-center"><strong>Edit Bid for <em>{{ bid.listing.title }}</em></strong></p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update" class="btn btn-primary" />
<input type="cancel" value="Never Mind" class="btn btn-default" onclick="history.back()"/>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -301,6 +301,9 @@ SRCT Bookshare &bull; {{ listing.title }}
</div>
<div class="col-md-2 col-sm-6 col-xs-6 text-center">
{% if not listing.sold or not listing.cancelled and bid.bidder.user == request.user %}
<h4><a href="{% url 'edit_bid' listing.slug bid.slug %}"<span class="label label-default">Edit</span></a></h4>
{% endif %}
{% if bid == listing.winning_bid %}
<h4><small><span class="label label-success">Winning Bid</span></small> <strong>${{ bid.price }}</strong></h4>
{% else %}
......
......@@ -4,7 +4,7 @@ from django.conf.urls import patterns, url
from .views import ListListings, CreateListing, ListingPage,\
CreateFlag, DeleteFlag, EditListing, SellListing,\
UnSellListing, CancelListing, ReopenListing, CreateRating,\
EditRating, DeleteRating
EditRating, DeleteRating, EditBid
urlpatterns = patterns('',
......@@ -17,6 +17,9 @@ urlpatterns = patterns('',
url(r'^listing/(?P<slug>[\w-]+)/$',
ListingPage.as_view(), name='detail_listing'),
url(r'^listing/(?P<listing_slug>[\w-]+)/bid/(?P<slug>[\w-]+)/$',
EditBid.as_view(), name='edit_bid'),
url(r'^listing/(?P<slug>[\w-]+)/flag/$',
CreateFlag.as_view(), name='create_flag'),
......
......@@ -292,11 +292,37 @@ class DeleteBid(LoginRequiredMixin, DeleteView):
# can be deleted by either creator or person for lister
class EditBid(LoginRequiredMixin, UpdateView):
class EditBid(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
model = Bid
template_name = 'bid_edit.html'
context_object_name = 'bid'
#form_class = EditBidForm
login_url = 'login'
form_valid_message = "Your listing was successfully updated!"
fields = ['price', 'text', ]
success_url = '/'
# can only be edited by the bidder
def get_success_url(self):
return reverse('detail_listing',
kwargs={'slug': self.object.listing.slug })
def get_context_data(self, **kwargs):
context = super(EditBid, self).get_context_data(**kwargs)
me = Student.objects.get(user=self.request.user)
bidding_student = self.get_object().bidder
if not(bidding_student == me):
return HttpResponseForbidden()
if bid.listing.sold or bid.listing.cancelled:
raise Http404
return context
class EditListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment