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

submitting bids on listing page complete

parent ea635736
......@@ -54,12 +54,17 @@ class BidForm( forms.ModelForm ):
Fieldset("",
'bidder',
'listing',
HTML("<div class='col-md-4'>"),
AppendedPrependedText('price','$', '.00', placeholder="whole numbers"),
HTML("</div><div class='col-md-4'>"),
'text',
FormActions(Submit('submit', 'Submit', css_class='btn-primary'))
HTML("</div><div class='col-md-4'>"),
FormActions(Submit('submit', 'Submit', css_class='btn-primary')),
HTML("</div>"),
),
)
super(BidForm, self).__init__(*args, **kwargs)
self.fields['text'].label = "Comments"
class Meta:
model = Bid
......
......@@ -103,10 +103,35 @@ SRCT Bookshare &bull; {{ listing.title }}
</div>
</div>
{% if request.user == listing.seller.user %}
{% if request.user == listing.seller.user and not listing.sold %}
<div class="row">
<div class="col-md-12">
<h3><span class="label label-default"><a href="{% url 'update_listing' listing.slug %}">Manage</a></span></h3>
<h3><span class="label label-default"><a href="{% url 'update_listing' listing.slug %}">Manage</a></span>
<span class="label label-default"><a href="{% url 'close_listing' listing.slug %}">Mark Sold</a></span></h3>
</div>
</div>
{% endif %}
{% if request.user == listing.seller.user %}
{% else %}
<div class="row text-center">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="panel panel-default" style="margin-top:10px;">
<div class="panel-heading">
<h4 class="panel-title">
<strong>Submit Your Bid</strong>
</h4>
</div>
<div class="panel-body">
{% if listing.active and not listing.sold %}
{% crispy my_form %}
{% else %}
<div class="col-lg-12">
<h5 class="text-center">You cannot bid on an inactive listing.</h5>
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}
......@@ -132,10 +157,10 @@ SRCT Bookshare &bull; {{ listing.title }}
<div class="row">
<div class="col-lg-3">
<a href="{{ bid.bidder.get_absolute_url }}">
<h4><a href="{{ bid.bidder.get_absolute_url }}">
{{ bid.bidder.user.first_name }}
{{ bid.bidder.user.last_name }}
</a>
</a></h4>
</div>
<div class="col-lg-2">
......@@ -166,22 +191,10 @@ SRCT Bookshare &bull; {{ listing.title }}
</div>
{% endif %}
<div class="row">
<div class="col-lg-12">
{% if listing.active and not listing.sold %}
{% crispy my_form %}
{% else %}
<h5 class="text-center">You cannot bid on an inactive listing.</h5>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
......
from django.conf.urls import patterns, include, url
from trades.views import ListListings, CreateListing, DetailListing, UpdateListing, CloseListing
from trades.views import ListListings, CreateListing, ListingPage, UpdateListing, CloseListing
from trades.models import Listing
urlpatterns = patterns('',
......@@ -21,11 +21,7 @@ urlpatterns = patterns('',
name='create_listing'),
url(r'^listing/(?P<slug>[\w-]+)/$',
DetailListing.as_view(
model=Listing,
# slug_field='slug__exact',
context_object_name='listing',
template_name='detail_listing.html'),
ListingPage.as_view(),
name='detail_listing'),
url(r'^listing/(?P<slug>[\w-]+)/update/$',
......
......@@ -7,6 +7,7 @@ from braces.views import LoginRequiredMixin
from django.contrib.auth.models import User
from django.http import Http404
from django.forms.widgets import HiddenInput
from django.core.urlresolvers import reverse
import math
import pyisbn
......@@ -47,10 +48,10 @@ class ListListings(LoginRequiredMixin, ListView):
class DetailListing(DetailView):
model = Listing
context_object_name = 'listing'
template_name = 'detail_listing.html'
login_url = '/'
# further need to incorporate much of the logic below somewhere
# - bid count
# - bid's age, then if 'old'
# - whether it's the person who posted the bid or someone else
......@@ -59,21 +60,27 @@ class DetailListing(DetailView):
me = User.objects.get(username=self.request.user.username)
# make the form available to the template on get
form = BidForm(initial={'bidder' : me})
# set the bidder and the listing
form = BidForm(initial={'bidder' : me, 'listing' : self.get_object()})
form.fields['bidder'].widget = HiddenInput()
form.fields['listing'].widget = HiddenInput()
context['my_form'] = form
# bids, filter by listing name of the current listing, order by date created
context['bids'] = Bid.objects.filter(listing=self.get_object()).order_by('-created')
context['bid_count'] = len(Bid.objects.filter(listing=self.get_object))
return context
class CreateBid(CreateView):
model = Bid
template_name = 'detail_listing'
form_class = BidForm
template_name = 'detail_listing.html'
login_url = '/'
def get_success_url(self):
return reverse('detail_listing', kwargs={'slug':self.object.listing.slug})
# ...to make this single view
class ListingPage(LoginRequiredMixin, View):
......
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