From c1596b5beb56117fcbd88d0206e738af5ccfc33f Mon Sep 17 00:00:00 2001 From: Daniel W Bond Date: Fri, 1 May 2015 15:27:09 -0400 Subject: [PATCH] broke out moderation into a separate app --- bookshare/mod/__init__.py | 0 bookshare/mod/admin.py | 3 ++ bookshare/mod/models.py | 3 ++ .../templates/email_ratio_mod.html} | 0 bookshare/mod/templates/flag_mod.html | 46 +++++++++++++++++++ bookshare/mod/templates/listing_num_mod.html | 46 +++++++++++++++++++ bookshare/mod/templates/mod.html | 46 +++++++++++++++++++ bookshare/mod/tests.py | 3 ++ bookshare/mod/urls.py | 17 +++++++ bookshare/mod/views.py | 30 ++++++++++++ bookshare/settings/settings.py | 1 + bookshare/settings/urls.py | 5 +- bookshare/settings/views.py | 10 +--- 13 files changed, 199 insertions(+), 11 deletions(-) create mode 100644 bookshare/mod/__init__.py create mode 100644 bookshare/mod/admin.py create mode 100644 bookshare/mod/models.py rename bookshare/{templates/mod.html => mod/templates/email_ratio_mod.html} (100%) create mode 100644 bookshare/mod/templates/flag_mod.html create mode 100644 bookshare/mod/templates/listing_num_mod.html create mode 100644 bookshare/mod/templates/mod.html create mode 100644 bookshare/mod/tests.py create mode 100644 bookshare/mod/urls.py create mode 100644 bookshare/mod/views.py diff --git a/bookshare/mod/__init__.py b/bookshare/mod/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bookshare/mod/admin.py b/bookshare/mod/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/bookshare/mod/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/bookshare/mod/models.py b/bookshare/mod/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/bookshare/mod/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/bookshare/templates/mod.html b/bookshare/mod/templates/email_ratio_mod.html similarity index 100% rename from bookshare/templates/mod.html rename to bookshare/mod/templates/email_ratio_mod.html diff --git a/bookshare/mod/templates/flag_mod.html b/bookshare/mod/templates/flag_mod.html new file mode 100644 index 0000000..91bb701 --- /dev/null +++ b/bookshare/mod/templates/flag_mod.html @@ -0,0 +1,46 @@ +{% extends 'layouts/base.html' %} + +{% block title %} +SRCT Bookshare • Mod +{% endblock title %} + +{% block content %} + +
+
+

Listings by number of Flags

+
+
+ +
+
+ + + + + + + + + {% for listing in listings %} + + + + + + + {% empty %} + Nothing Here! + {% endfor %} + +

Number

Title

Poster

Action

{{ listing.num_flags }} + {{ listing.title }} + + {{ listing.poster.user.get_full_name }} + + Delete +
+
+
+ +{% endblock content %} diff --git a/bookshare/mod/templates/listing_num_mod.html b/bookshare/mod/templates/listing_num_mod.html new file mode 100644 index 0000000..91bb701 --- /dev/null +++ b/bookshare/mod/templates/listing_num_mod.html @@ -0,0 +1,46 @@ +{% extends 'layouts/base.html' %} + +{% block title %} +SRCT Bookshare • Mod +{% endblock title %} + +{% block content %} + +
+
+

Listings by number of Flags

+
+
+ +
+
+ + + + + + + + + {% for listing in listings %} + + + + + + + {% empty %} + Nothing Here! + {% endfor %} + +

Number

Title

Poster

Action

{{ listing.num_flags }} + {{ listing.title }} + + {{ listing.poster.user.get_full_name }} + + Delete +
+
+
+ +{% endblock content %} diff --git a/bookshare/mod/templates/mod.html b/bookshare/mod/templates/mod.html new file mode 100644 index 0000000..91bb701 --- /dev/null +++ b/bookshare/mod/templates/mod.html @@ -0,0 +1,46 @@ +{% extends 'layouts/base.html' %} + +{% block title %} +SRCT Bookshare • Mod +{% endblock title %} + +{% block content %} + +
+
+

Listings by number of Flags

+
+
+ +
+
+ + + + + + + + + {% for listing in listings %} + + + + + + + {% empty %} + Nothing Here! + {% endfor %} + +

Number

Title

Poster

Action

{{ listing.num_flags }} + {{ listing.title }} + + {{ listing.poster.user.get_full_name }} + + Delete +
+
+
+ +{% endblock content %} diff --git a/bookshare/mod/tests.py b/bookshare/mod/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/bookshare/mod/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/bookshare/mod/urls.py b/bookshare/mod/urls.py new file mode 100644 index 0000000..d2b2055 --- /dev/null +++ b/bookshare/mod/urls.py @@ -0,0 +1,17 @@ +# core django imports +from django.conf.urls import patterns, url +from django.views.decorators.cache import cache_page +# imports from your apps +from .views import ModLandingView, FlagModView, ListingNumModView,\ + UserEmailRatioModView + +urlpatterns = patterns('', + url(r'^$', cache_page(60 * 15)(ModLandingView.as_view()), name='mod_page'), + + url(r'^flags/$', FlagModView.as_view(), name='flag_mod'), + + url(r'^listing-nums/$', ListingNumModView.as_view(), name='listing_nums'), + + url(r'^email-ratio/$', UserEmailRatioModView.as_view(), name='email_ratio'), + +) diff --git a/bookshare/mod/views.py b/bookshare/mod/views.py new file mode 100644 index 0000000..08be8e6 --- /dev/null +++ b/bookshare/mod/views.py @@ -0,0 +1,30 @@ +# core django imports +from django.views.generic import TemplateView, ListView +from django.db.models import Sum +# third party imports +from braces.views import LoginRequiredMixin, SuperuserRequiredMixin +# imports from your apps +from trades.models import Listing + + +class ModLandingView(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView): + template_name = 'mod.html' + +class FlagModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView): + queryset = Listing.objects.annotate(num_flags=Count('flag')).order_by('-num_flags')[:20] + context_object_name = 'listings' + template_name = 'flag_mod.html' + login_url = 'login' + +class ListingNumModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView): + queryset = Listing.objects.all()[:20] + context_object_name = 'users' + template_name = 'listing_num_mod.html' + login_url = 'login' + +class UserEmailRatioModView(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView): + template_name = 'email_ratio_mod.html' + + def get_context_data(self, **kwargs): + context = super(UserEmailRatioView, self).get_context_data(**kwargs) + return context diff --git a/bookshare/settings/settings.py b/bookshare/settings/settings.py index 0f0fe30..d58c87f 100644 --- a/bookshare/settings/settings.py +++ b/bookshare/settings/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = ( 'trades', 'core', 'lookouts', + 'mod', # packages 'randomslugfield', 'django_gravatar', diff --git a/bookshare/settings/urls.py b/bookshare/settings/urls.py index f6ed2e4..1e03030 100644 --- a/bookshare/settings/urls.py +++ b/bookshare/settings/urls.py @@ -6,7 +6,7 @@ from django.conf import settings from django.contrib import admin from django.views.decorators.cache import cache_page # imports from your apps -from .views import HomepageView, ChartsView, ModView +from .views import HomepageView, ChartsView admin.autodiscover() @@ -20,6 +20,7 @@ urlpatterns = patterns('', url(r'^share/', include('trades.urls')), url(r'^student/', include('core.urls')), url(r'^lookouts/', include('lookouts.urls')), + url(r'^mod/', include('mod.urls')), # search url(r'^search/', include('haystack.urls'), name='search'), @@ -30,8 +31,6 @@ urlpatterns = patterns('', url(r'^$', HomepageView.as_view(), name='homepage'), url(r'^charts/?$', cache_page(60 * 10)(ChartsView.as_view()), name='charts'), - url(r'^mod/?$', ModView.as_view(), name='mod'), - # static pages url(r'^about/?$', cache_page(60 * 15)(TemplateView.as_view(template_name='about.html')), diff --git a/bookshare/settings/views.py b/bookshare/settings/views.py index ea996f9..1c2a41a 100644 --- a/bookshare/settings/views.py +++ b/bookshare/settings/views.py @@ -1,10 +1,10 @@ # standard library imports from collections import Counter # core django imports -from django.views.generic import TemplateView, ListView +from django.views.generic import TemplateView from django.db.models import Sum, Count # third party imports -from braces.views import LoginRequiredMixin, SuperuserRequiredMixin +from braces.views import LoginRequiredMixin # imports from your apps from lookouts.models import Lookout from trades.models import Listing, Bid @@ -55,9 +55,3 @@ class ChartsView(LoginRequiredMixin, TemplateView): context['total_students'] = Student.objects.count() context['total_proceeds'] = total_proceeds 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' -- GitLab