Commit 7c525957 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added notifications for listing actions

parent 044bc57c
......@@ -44,7 +44,19 @@ SRCT Bookshare • {{ listing.title }}
</div>
{% endif %}
<div class="page-header" id="banner">
{% if messages %}
{% for message in messages %}
<div class="row">
<div class="col-md-12">
<div class="alert alert-info alert-dismissable text-center" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">&times;</span></button>
<strong>{{ message }}</strong>
</div>
</div>
</div>
{% endfor %}
{% endif %}
{% if listing.cancelled %}
<div class="row">
<div class="col-lg-12">
......@@ -82,7 +94,6 @@ SRCT Bookshare &bull; {{ listing.title }}
</div>
</div>
{% endif %}
</div>
<div class="row">
<div class="col-xs-8">
......
......@@ -11,6 +11,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context
from django.contrib import messages
# third party imports
import requests
from PIL import Image
......@@ -67,6 +68,16 @@ def can_rate(rater, listing):
return True
class ListingActionMixin(object):
@property
def success_msg(self):
return NotImplemented
def form_valid(self, form):
messages.info(self.request, self.success_msg)
return super(ListingActionMixin, self).form_valid(form)
class ListListings(LoginRequiredMixin, ListView):
model = Listing
context_object_name = 'listings'
......@@ -277,13 +288,15 @@ class EditBid(LoginRequiredMixin, UpdateView):
# can only be edited by the bidder
class EditListing(LoginRequiredMixin, UpdateView):
class EditListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
model = Listing
template_name = 'listing_edit.html'
context_object_name = 'listing'
#form_class = EditListingForm
login_url = 'login'
success_msg = "Your listing was successfully updated!"
fields = ['title', 'author', 'isbn', 'year', 'edition', 'condition',
'access_code', 'description', 'price', 'photo', ]
template_suffix_name = '_edit'
......@@ -300,7 +313,7 @@ class EditListing(LoginRequiredMixin, UpdateView):
return context
class SellListing(LoginRequiredMixin, UpdateView):
class SellListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
model = Listing
fields = ['email_message', 'winning_bid', ]
template_suffix_name = '_sell'
......@@ -308,12 +321,12 @@ class SellListing(LoginRequiredMixin, UpdateView):
template_name = 'listing_sell.html'
login_url = 'login'
success_msg = "Your email was successfully sent!"
def form_valid(self, form):
# filling out fields
today = date.today()
self.obj = self.get_object()
print self.obj
print form.instance.winning_bid
form.instance.sold = True
form.instance.date_closed = today
......@@ -333,9 +346,10 @@ class SellListing(LoginRequiredMixin, UpdateView):
subject, from_email, to, cc = ('Your bid has been selected on Bookshare!',
'no-reply@bookshare.srct.io',
form.instance.winning_bid.bidder.user.email,
self.obj.seller.user.email)
#your-test-email@example.com')
#form.instance.winning_bid.bidder.user.email,
#self.obj.seller.user.email)
'success@simulator.amazonses.com',
'success@simulator.amazonses.com')
text_content = text_email.render(email_context)
html_content = html_email.render(email_context)
msg = EmailMultiAlternatives(subject, text_content,
......@@ -367,7 +381,7 @@ class SellListing(LoginRequiredMixin, UpdateView):
return context
class UnSellListing(LoginRequiredMixin, UpdateView):
class UnSellListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
model = Listing
fields = []
template_suffix_name = '_unsell'
......@@ -375,6 +389,8 @@ class UnSellListing(LoginRequiredMixin, UpdateView):
template_name = 'listing_unsell.html'
login_url = 'login'
success_msg = "Your sale has been successfully cancelled!"
def form_valid(self, form):
form.instance.sold = False
form.instance.date_closed = None
......@@ -420,7 +436,7 @@ class CancelListing(LoginRequiredMixin, UpdateView):
return context
class ReopenListing(LoginRequiredMixin, UpdateView):
class ReopenListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
model = Listing
fields = []
template_suffix_name = '_reopen'
......@@ -428,6 +444,8 @@ class ReopenListing(LoginRequiredMixin, UpdateView):
template_name = 'listing_reopen.html'
login_url = 'login'
success_msg = "Your listing was successfully reopened!"
def form_valid(self, form):
form.instance.cancelled = False
form.instance.date_closed = None
......
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