Commit 090aa035 authored by Daniel W Bond's avatar Daniel W Bond

route to more limited template if not logged in

parent 34ed7ccf
{% extends 'layouts/base.html' %}
{% block title %}
SRCT Bookshare • {{ listing.title }}
{% endblock title %}
{% block social_metadata %}
<meta property="og:title" content="{{ listing.title }}"/>
<meta property="og:type" content="book"/>
<meta property="og.url" content="{{ request.build_absolute_uri }}"/>
<meta property="og.image" content="{{ listing.photo.url }}"/>
<meta property="books:author" content="{{ listing.author }}"/>
<meta property="books:isbn" content="{{ listing.isbn }}"/>
{% if listing.year %}
<meta property="books:release_date" content="{{ listing.year }}"/>
{% endif %}
{% endblock social_metadata %}
{% block content %}
{% load humanize %}
{% if flag_count > 4 %}
{% block javascript %}
<script type="text/javascript">
$(window).load(function(){
$('#myModal').modal('show');
});
</script>
{% endblock javascript %}
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<h3 class="modal-title"><strong class="text-danger"><i class="fa fa-exclamation-triangle fa-fw"></i> Warning:</strong> This listing has been flagged!</h3>
</div>
<div class="modal-body text-center">
{% for flag in flags %}
<h4><strong>{{ flag.reason }}</strong> {{ flag.created|date:"M d, 'y P" }} <small>({{ flag.created|naturaltime }})</small></h4>
{% endfor %}
</div>
<div class="modal-footer">
<div class="text-center"><!-- not sure why this doesn't work in the above div... -->
<!-- also, why is the dismissing not working... >__> -->
<button type="button" class="btn btn-danger" data-dismiss="modal">Proceed</button>
<a href="javascript:history.back()"><button type="button" class="btn btn-default">Get Me Out of Here</button></a>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% if listing.cancelled %}
<div class="row">
<div class="col-lg-12">
<div class="alert alert-danger text-center">
<strong>This listing has been cancelled.</strong>
</div>
</div>
</div>
{% elif listing.exchanged %}
<div class="row">
<div class="col-lg-12">
<div class="alert alert-danger text-center">
<strong>This listing has been exchanged.</strong>
</div>
</div>
</div>
{% elif not listing.active %}
<div class="row">
<div class="col-lg-12">
<div class="alert alert-warning text-center alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">&times;</button>
Heads up, this listing is <strong>over a month old</strong> and we haven't seen the student who posted it around recently either. It may no longer be valid!
</div>
</div>
</div>
{% endif %}
{% load trades_extras %}
<div class="row">
<div class="col-xs-8">
<h1>
<em><strong>{{ listing.title }}</strong></em>
</h1>
</div>
<div class="col-xs-4 text-right">
<h1 class="price">
{% if listing.exchanged %}
<small>Final</small> <strong>${{ listing.final_price }}</strong>
{% else %}
<small>Asking</small> <strong>${{ listing.price }}</strong>
{% endif %}
</h1>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<h4>
<small>by</small> {{ listing.author }}
{% if listing.year %}
({{ listing.year|bc }})
{% endif %}
</h4>
</div>
<div class="col-xs-6 text-right">
<h4><small>Listed</small> {{ listing.created|date:"M d, 'y P" }} <small>({{ listing.created|naturaltime }})</small></h4>
</div>
</div>
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-6">
<h4><small>ISBN</small> {{ listing.isbn }}</h4>
</div>
<div class="col-md-2 col-sm-6 col-xs-6 small-text-right">
<h4>
{% if listing.edition %}
{{ listing.edition|ordinal }}<small> edition</small>
{% endif %}
</h4>
</div>
<div class="col-md-3 col-sm-6 col-xs-6">
{% if listing.course_abbr %}
<h4><small>Course</small> {{ listing.course_abbr }}</h4>
{% else %}
{% endif %}
</div>
<div class="col-md-4 col-sm-6 col-xs-6 text-right">
</div>
</div>
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-6">
<h4><small>Condition</small> {{ listing.condition }}</h4>
</div>
<div class="col-md-4 col-sm-6 col-xs-6 small-text-right">
<h4><small>Access Code</small> {{ listing.access_code }}</h4>
</div>
<div class="col-md-5 text-right small-text-center">
</div>
</div>
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="text-center">
<a href="{{ listing.photo.url }}">
<img src="{{ listing.photo.url }}"
alt="User submitted textbook photo" class="img-thumbnail" />
</a>
</div>
</div>
<div class="col-md-9 col-sm-6 col-xs-12">
{% if listing.description %}
<h4><small>Description/Comments</small>
{{ listing.description }}
{% else %}
{% endif %}
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<a href="{% url 'login' %}" class="btn btn-primary btn-block">See the full page by logging in with your Mason username and password!</a>
</div>
</div>
{% endblock content %}
......@@ -138,12 +138,24 @@ class CreateListing(LoginRequiredMixin, FormValidMessageMixin, CreateView):
return super(CreateListing, self).post(request, *args, **kwargs)
# These next two views are tied together...
class DetailListing(DetailView):
class DeleteListing(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
model = Listing
context_object_name = 'listing'
template_name = 'delete_listing.html'
login_url = 'login'
def get_success_url(self):
return reverse('flag_mod')
# These next three views are tied together...
class DetailListing(LoginRequiredMixin, DetailView):
model = Listing
context_object_name = 'listing'
template_name = 'detail_listing.html'
login_url = 'login'
def get_context_data(self, **kwargs):
context = super(DetailListing, self).get_context_data(**kwargs)
me = Student.objects.get(user=self.request.user)
......@@ -170,22 +182,25 @@ class DetailListing(DetailView):
return context
class DeleteListing(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
class DetailListingNoAuth(DetailView):
model = Listing
context_object_name = 'listing'
template_name = 'delete_listing.html'
login_url = 'login'
def get_success_url(self):
return reverse('flag_mod')
template_name = 'detail_listing_no_auth.html'
def get_context_data(self, **kwargs):
context = super(DetailListingNoAuth, self).get_context_data(**kwargs)
context['flag_count'] = Flag.objects.filter(listing=self.get_object()).count()
context['flags'] = Flag.objects.filter(listing=self.get_object()).order_by('-created')
return context
class CreateBid(CreateView):
class CreateBid(LoginRequiredMixin, CreateView):
model = Bid
fields = ['listing', 'price', 'text', ]
context_object_name = 'bid'
template_name = 'detail_listing.html'
login_url = 'login'
def form_valid(self, form):
me = Student.objects.get(user=self.request.user)
......@@ -198,22 +213,28 @@ class CreateBid(CreateView):
# ...to make this single view
class ListingPage(LoginRequiredMixin, View):
login_url = 'login'
class ListingPage(View):
# see this page for an explanation
# https://docs.djangoproject.com/en/1.7/topics/class-based-views/mixins/#an-alternative-better-solution
def get(self, request, *args, **kwargs):
view = DetailListing.as_view()
return view(request, *args, **kwargs)
if self.request.user.is_authenticated():
view = DetailListing.as_view()
return view(request, *args, **kwargs)
else:
view = DetailListingNoAuth.as_view()
return view(request, *args, **kwargs)
@ratelimit(key='user', rate='5/m', method='POST', block=True)
# rate limit is higher for bids
@ratelimit(key='user', rate='100/d', method='POST', block=True)
def post(self, request, *args, **kwargs):
view = CreateBid.as_view()
return view(request, *args, **kwargs)
if self.request.user.is_authenticated():
view = CreateBid.as_view()
return view(request, *args, **kwargs)
else:
pass
# and we return to our regularly schedule programming
......
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