Commit 881fa9cb authored by Daniel W Bond's avatar Daniel W Bond
Browse files

used braces validation messages instead of custom mixin

parent 8fded4ee
...@@ -17,6 +17,8 @@ from django.utils.safestring import mark_safe ...@@ -17,6 +17,8 @@ from django.utils.safestring import mark_safe
import requests import requests
from PIL import Image from PIL import Image
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin
from braces.views import FormValidMessageMixin
from ratelimit.mixins import RatelimitMixin
# imports from your apps # imports from your apps
from .models import Listing, Bid, Flag, Rating from .models import Listing, Bid, Flag, Rating
from .forms import ListingForm, BidForm, FlagForm, SellListingForm,\ from .forms import ListingForm, BidForm, FlagForm, SellListingForm,\
...@@ -70,16 +72,6 @@ def can_rate(rater, listing): ...@@ -70,16 +72,6 @@ def can_rate(rater, listing):
return True return True
class ListingActionMixin(object):
@property
def success_msg(self):
return NotImplemented
def form_valid(self, form):
messages.info(self.request, mark_safe(self.success_msg))
return super(ListingActionMixin, self).form_valid(form)
class ListListings(LoginRequiredMixin, ListView): class ListListings(LoginRequiredMixin, ListView):
model = Listing model = Listing
context_object_name = 'listings' context_object_name = 'listings'
...@@ -89,7 +81,7 @@ class ListListings(LoginRequiredMixin, ListView): ...@@ -89,7 +81,7 @@ class ListListings(LoginRequiredMixin, ListView):
login_url = 'login' login_url = 'login'
class CreateListing(LoginRequiredMixin, ListingActionMixin, CreateView): class CreateListing(LoginRequiredMixin, FormValidMessageMixin, CreateView):
model = Listing model = Listing
fields = ['isbn', 'title', 'author', 'edition', 'year', 'course_abbr', fields = ['isbn', 'title', 'author', 'edition', 'year', 'course_abbr',
'condition', 'access_code', 'price', 'photo', 'description'] 'condition', 'access_code', 'price', 'photo', 'description']
...@@ -99,8 +91,8 @@ class CreateListing(LoginRequiredMixin, ListingActionMixin, CreateView): ...@@ -99,8 +91,8 @@ class CreateListing(LoginRequiredMixin, ListingActionMixin, CreateView):
login_url = 'login' login_url = 'login'
# eventually figure out how to use {% url 'create_listing' %} # eventually figure out how to use {% url 'create_listing' %}
success_msg = """Your listing was successfully created! form_valid_message = mark_safe("""Your listing was successfully created!
<a href="/share/new/">Create another here!</a>""" <a href="/share/new/">Create another here!</a>""")
def form_valid(self, form): def form_valid(self, form):
me = Student.objects.get(user=self.request.user) me = Student.objects.get(user=self.request.user)
...@@ -294,14 +286,14 @@ class EditBid(LoginRequiredMixin, UpdateView): ...@@ -294,14 +286,14 @@ class EditBid(LoginRequiredMixin, UpdateView):
# can only be edited by the bidder # can only be edited by the bidder
class EditListing(LoginRequiredMixin, ListingActionMixin, UpdateView): class EditListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
model = Listing model = Listing
template_name = 'listing_edit.html' template_name = 'listing_edit.html'
context_object_name = 'listing' context_object_name = 'listing'
#form_class = EditListingForm #form_class = EditListingForm
login_url = 'login' login_url = 'login'
success_msg = "Your listing was successfully updated!" form_valid_message = "Your listing was successfully updated!"
fields = ['title', 'author', 'isbn', 'year', 'edition', 'condition', fields = ['title', 'author', 'isbn', 'year', 'edition', 'condition',
'access_code', 'description', 'price', 'photo', ] 'access_code', 'description', 'price', 'photo', ]
...@@ -319,7 +311,7 @@ class EditListing(LoginRequiredMixin, ListingActionMixin, UpdateView): ...@@ -319,7 +311,7 @@ class EditListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
return context return context
class SellListing(LoginRequiredMixin, ListingActionMixin, UpdateView): class SellListing(LoginRequiredMixin, RatelimitMixin, FormValidMessageMixin, UpdateView):
model = Listing model = Listing
fields = ['email_message', 'winning_bid', ] fields = ['email_message', 'winning_bid', ]
template_suffix_name = '_sell' template_suffix_name = '_sell'
...@@ -327,7 +319,12 @@ class SellListing(LoginRequiredMixin, ListingActionMixin, UpdateView): ...@@ -327,7 +319,12 @@ class SellListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
template_name = 'listing_sell.html' template_name = 'listing_sell.html'
login_url = 'login' login_url = 'login'
success_msg = "Your email was successfully sent!" ratelimit_key = 'user'
ratelimit_rate = '1/d'
ratelimit_block = False
ratelimit_method = 'POST'
form_valid_message = "Your email was successfully sent!"
def form_valid(self, form): def form_valid(self, form):
# filling out fields # filling out fields
...@@ -387,7 +384,7 @@ class SellListing(LoginRequiredMixin, ListingActionMixin, UpdateView): ...@@ -387,7 +384,7 @@ class SellListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
return context return context
class UnSellListing(LoginRequiredMixin, ListingActionMixin, UpdateView): class UnSellListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
model = Listing model = Listing
fields = ['email_message', ] fields = ['email_message', ]
template_suffix_name = '_unsell' template_suffix_name = '_unsell'
...@@ -395,7 +392,7 @@ class UnSellListing(LoginRequiredMixin, ListingActionMixin, UpdateView): ...@@ -395,7 +392,7 @@ class UnSellListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
template_name = 'listing_unsell.html' template_name = 'listing_unsell.html'
login_url = 'login' login_url = 'login'
success_msg = """Your sale has been successfully cancelled, form_valid_message = """Your sale has been successfully cancelled,
and your email successfully sent!""" and your email successfully sent!"""
def form_valid(self, form): def form_valid(self, form):
...@@ -447,7 +444,7 @@ class UnSellListing(LoginRequiredMixin, ListingActionMixin, UpdateView): ...@@ -447,7 +444,7 @@ class UnSellListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
return context return context
class CancelListing(LoginRequiredMixin, UpdateView): class CancelListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
model = Listing model = Listing
fields = [] fields = []
template_suffix_name = '_cancel' template_suffix_name = '_cancel'
...@@ -455,6 +452,8 @@ class CancelListing(LoginRequiredMixin, UpdateView): ...@@ -455,6 +452,8 @@ class CancelListing(LoginRequiredMixin, UpdateView):
template_name = 'listing_cancel.html' template_name = 'listing_cancel.html'
login_url = 'login' login_url = 'login'
form_valid_message = "Your listing was successfully cancelled!"
def form_valid(self, form): def form_valid(self, form):
today = date.today() today = date.today()
...@@ -474,7 +473,7 @@ class CancelListing(LoginRequiredMixin, UpdateView): ...@@ -474,7 +473,7 @@ class CancelListing(LoginRequiredMixin, UpdateView):
return context return context
class ReopenListing(LoginRequiredMixin, ListingActionMixin, UpdateView): class ReopenListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
model = Listing model = Listing
fields = [] fields = []
template_suffix_name = '_reopen' template_suffix_name = '_reopen'
...@@ -482,7 +481,7 @@ class ReopenListing(LoginRequiredMixin, ListingActionMixin, UpdateView): ...@@ -482,7 +481,7 @@ class ReopenListing(LoginRequiredMixin, ListingActionMixin, UpdateView):
template_name = 'listing_reopen.html' template_name = 'listing_reopen.html'
login_url = 'login' login_url = 'login'
success_msg = "Your listing was successfully reopened!" form_valid_message = "Your listing was successfully reopened!"
def form_valid(self, form): def form_valid(self, form):
form.instance.cancelled = False form.instance.cancelled = False
...@@ -599,5 +598,3 @@ class DeleteRating(LoginRequiredMixin, DeleteView): ...@@ -599,5 +598,3 @@ class DeleteRating(LoginRequiredMixin, DeleteView):
return HttpResponseForbidden() return HttpResponseForbidden()
return context return context
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