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

added support for superuser flagging moderation

parent d158f664
...@@ -6,7 +6,7 @@ from django.conf import settings ...@@ -6,7 +6,7 @@ from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
# imports from your apps # imports from your apps
from .views import HomepageView, ChartsView from .views import HomepageView, ChartsView, ModView
admin.autodiscover() admin.autodiscover()
...@@ -25,11 +25,13 @@ urlpatterns = patterns('', ...@@ -25,11 +25,13 @@ urlpatterns = patterns('',
url(r'^search/', include('haystack.urls'), name='search'), url(r'^search/', include('haystack.urls'), name='search'),
# site-wide pages # site-wide pages
# this page is weird for cacheing... no special url, but different content # homepage is weird for cacheing... no special url, but different content
# for each user # for each user
url(r'^$', HomepageView.as_view(), name='homepage'), url(r'^$', HomepageView.as_view(), name='homepage'),
url(r'^charts/?$', cache_page(60 * 10)(ChartsView.as_view()), name='charts'), url(r'^charts/?$', cache_page(60 * 10)(ChartsView.as_view()), name='charts'),
url(r'^mod/?$', ModView.as_view(), name='mod'),
# static pages # static pages
url(r'^about/?$', url(r'^about/?$',
cache_page(60 * 15)(TemplateView.as_view(template_name='about.html')), cache_page(60 * 15)(TemplateView.as_view(template_name='about.html')),
......
# standard library imports # standard library imports
from collections import Counter from collections import Counter
# core django imports # core django imports
from django.views.generic import TemplateView from django.views.generic import TemplateView, ListView
from django.db.models import Sum from django.db.models import Sum, Count
# third party imports # third party imports
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin, SuperuserRequiredMixin
# imports from your apps # imports from your apps
from lookouts.models import Lookout from lookouts.models import Lookout
from trades.models import Listing, Bid from trades.models import Listing, Bid
...@@ -55,3 +55,9 @@ class ChartsView(LoginRequiredMixin, TemplateView): ...@@ -55,3 +55,9 @@ class ChartsView(LoginRequiredMixin, TemplateView):
context['total_students'] = Student.objects.count() context['total_students'] = Student.objects.count()
context['total_proceeds'] = total_proceeds context['total_proceeds'] = total_proceeds
return context return context
class ModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView):
queryset = Listing.objects.annotate(num_flags=Count('flag')).order_by('-num_flags')[:20]
context_object_name = 'listings'
template_name = 'mod.html'
login_url = 'login'
{% extends 'layouts/base.html' %}
{% block title %}
SRCT Bookshare • Mod
{% endblock title %}
{% block content %}
<div class="row">
<div class="col-md-10 col-md-offset-1 text-center">
<h1>Listings by number of Flags</h1>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<table class="table table-bordered table-hover table-condensed text-center">
<thead>
<td class="col-md-1"><h4><strong>Number</strong></h4></td>
<td class="col-md-6"><h4><strong>Title</strong></h4></td>
<td class="col-md-3"><h4><strong>Poster</strong></h4></td>
<td class="col-md-2"><h4><strong>Action</strong></h4></td>
</thead>
<tbody>
{% for listing in listings %}
<tr>
<td>{{ listing.num_flags }}</td>
<td><a href="{{ listing.get_absolute_url }}" target="_blank">
<strong>{{ listing.title }}</strong>
</a></td>
<td><a href="{{ listing.poster.get_absolute_url }}" target="_blank">
{{ listing.poster.user.get_full_name }}
</a></td>
<td><a href="{% url 'delete_listing' listing.slug %}">
<span class="label label-danger"><strong>Delete</strong></span>
</a></td>
</tr>
{% empty %}
Nothing Here!
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock content %}
{% extends 'layouts/base.html' %}
{% block title %}
SRCT Bookshare &bull; {{ flag.listing.title }} &bull; Delete Listing
{% endblock %}
{% block content %}
<hr />
<div class="row text-center">
<form action="" method="post">{% csrf_token %}
<h3>Are you <em>ABSOLUTELY</em> certain you want to <em>PERMANENTLY</em> delete {{ listing.poster.user.get_full_name }}'s listing <em>{{ listing.title }}</em>?</h3>
<input type="submit" value="THERE'S NO GOING BACK AND PEOPLE WILL BE MAD" class="btn btn-danger btn-sm" />
<input type="submit" value="Never Mind" class="btn btn-default btn-sm" onclick="history.back()" />
</form>
</div>
<hr />
{% endblock %}
...@@ -5,7 +5,7 @@ from django.views.decorators.cache import cache_page ...@@ -5,7 +5,7 @@ from django.views.decorators.cache import cache_page
from .views import ListListings, CreateListing, ListingPage,\ from .views import ListListings, CreateListing, ListingPage,\
CreateFlag, DeleteFlag, EditListing, ExchangeListing,\ CreateFlag, DeleteFlag, EditListing, ExchangeListing,\
UnExchangeListing, CancelListing, ReopenListing, CreateRating,\ UnExchangeListing, CancelListing, ReopenListing, CreateRating,\
EditRating, DeleteRating, EditBid EditRating, DeleteRating, EditBid, DeleteListing
urlpatterns = patterns('', urlpatterns = patterns('',
...@@ -18,6 +18,9 @@ urlpatterns = patterns('', ...@@ -18,6 +18,9 @@ urlpatterns = patterns('',
url(r'^listing/(?P<slug>[\w-]+)/$', url(r'^listing/(?P<slug>[\w-]+)/$',
ListingPage.as_view(), name='detail_listing'), ListingPage.as_view(), name='detail_listing'),
url(r'^listing/(?P<slug>[\w-]+)/delete/$',
DeleteListing.as_view(), name='delete_listing'),
url(r'^listing/(?P<listing_slug>[\w-]+)/bid/(?P<slug>[\w-]+)/$', url(r'^listing/(?P<listing_slug>[\w-]+)/bid/(?P<slug>[\w-]+)/$',
EditBid.as_view(), name='edit_bid'), EditBid.as_view(), name='edit_bid'),
......
...@@ -15,7 +15,7 @@ from django.utils.safestring import mark_safe ...@@ -15,7 +15,7 @@ from django.utils.safestring import mark_safe
# third party imports # third party imports
import requests import requests
from PIL import Image from PIL import Image
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin, SuperuserRequiredMixin
from braces.views import FormValidMessageMixin from braces.views import FormValidMessageMixin
from ratelimit.decorators import ratelimit from ratelimit.decorators import ratelimit
# imports from your apps # imports from your apps
...@@ -170,6 +170,16 @@ class DetailListing(DetailView): ...@@ -170,6 +170,16 @@ class DetailListing(DetailView):
return context return context
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('mod')
class CreateBid(CreateView): class CreateBid(CreateView):
model = Bid model = Bid
fields = ['listing', 'price', 'text', ] fields = ['listing', 'price', 'text', ]
......
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