This should be my final code update before I am ready for review! Basically, in

this update I finished the search/sort function on the Reports Panel. I also
finished the Terms of Service and made the decision to remove the meta portion
of the site I had planned to create. I decided that the features involved were
just unnecessary at this point. I also dropped the User status column and added
a migration to establish default privileges (and create the privilege foundat-
-ions. I fixed a few small errors that were left over as well, in the implemen-
tation and in the tests. Next, I just need to await code review and work on the
documentation for these new features. I also need to supervise a new merge to
master.

===============================================================================
    Dropped the vestigial 'status' column
===============================================================================
--\ mediagoblin/db/migrations.py
--\ mediagoblin/db/models.py
--| Also added in comments describing the current situation with the `is_admin`
  | and `email_verified` columns, where they are 100% vestigial but cannot be
  | dropped.

===============================================================================
            Wrote necessary migrations to set up Privilege
    foundations and give users the necessary privileges on an older
     implementation of mediagoblin that is migrating into this update
===============================================================================
--\ mediagoblin/db/migrations.py

===============================================================================
    Deleted the meta pages
===============================================================================
--\ Deleted mediagoblin/meta/__init__.py
--\ Deleted mediagoblin/meta/routing.py
--\ Deleted mediagoblin/meta/views.py
--\ Deleted mediagoblin/templates/mediagoblin/meta/code_of_conduct.html
--\ Deleted mediagoblin/templates/mediagoblin/meta/reports_details.html
--\ Deleted mediagoblin/templates/mediagoblin/meta/reports_panel.html
    ----------------------------------------------------------------
        Moved the terms of service to /terms_of_service
    ----------------------------------------------------------------
    --\ Moved mediagoblin/templates/mediagoblin/meta/terms_of_service.html
        -> mediagoblin/templates/mediagoblin/terms_of_service.html
    --| I decided that terms of service were really the only necessary part of my
      | planned "meta" pages, so I moved it instead to its own singular page
    --\ mediagoblin/routing.py
    --\ mediagoblin/static/css/base.css
    --\ mediagoblin/templates/mediagoblin/base.html
    --\ mediagoblin/views.py

===============================================================================
          Simplified & Finished the Reports Panel Searching
===============================================================================
--\ mediagoblin/moderation/forms.py
--\ mediagoblin/moderation/tools.py
--\ mediagoblin/moderation/views.py
--\ mediagoblin/templates/mediagoblin/moderation/report_panel.html
--\ mediagoblin/templates/mediagoblin/moderation/user.html

===============================================================================
                  Fixed Small Errors
===============================================================================
--\ mediagoblin/templates/mediagoblin/user_pages/user.html
--\ mediagoblin/tests/test_moderation.py
--\ mediagoblin/tests/tools.py

===============================================================================
This commit is contained in:
tilly-Q
2013-09-10 13:16:22 -04:00
parent 25625107b6
commit 6acf4ee60e
21 changed files with 184 additions and 245 deletions

View File

@@ -130,27 +130,12 @@ class ReportPanelSortingForm(wtforms.Form):
This form is used for sorting and filtering through different reports in
the mediagoblin.moderation.reports_panel view.
Parameters that start with 'active_' refer to a sort/filter for the active
reports.
Parameters that start with 'closed_' refer to a sort/filter for the closed
reports.
"""
active_p = wtforms.IntegerField(
_(u'Page'),
validators=[wtforms.validators.optional()])
active_reported_user = wtforms.IntegerField(
_(u'Reported User'),
validators=[wtforms.validators.optional()])
active_reporter = wtforms.IntegerField(
_(u'Reporter'),
validators=[wtforms.validators.optional()])
closed_p = wtforms.IntegerField(
_(u'Page'),
validators=[wtforms.validators.optional()])
closed_reported_user = wtforms.IntegerField(
_(u'Reported User'),
reported_user = wtforms.IntegerField(
validators=[wtforms.validators.optional()])
closed_reporter = wtforms.IntegerField(
_(u'Reporter'),
reporter = wtforms.IntegerField(
validators=[wtforms.validators.optional()])

View File

@@ -229,5 +229,21 @@ def unban_user(user_id):
user_ban.first().delete()
return True
def parse_report_panel_settings(form):
"""
This function parses the url arguments to which are used to filter reports
in the reports panel view. More filters can be added to make a usuable
search function.
:returns A dictionary of sqlalchemy-usable filters.
"""
filters = {}
if form.validate():
filters['reported_user_id'] = form.reported_user.data
filters['reporter_id'] = form.reporter.data
filters = dict((k, v)
for k, v in filters.iteritems() if v)
return filters

View File

@@ -24,7 +24,9 @@ from mediagoblin.decorators import (require_admin_or_moderator_login, \
from mediagoblin.tools.response import render_to_response, redirect
from mediagoblin.moderation import forms as moderation_forms
from mediagoblin.moderation.tools import (take_punitive_actions, \
take_away_privileges, give_privileges, ban_user, unban_user)
take_away_privileges, give_privileges, ban_user, unban_user, \
parse_report_panel_settings)
from werkzeug.datastructures import ImmutableMultiDict
from datetime import datetime
from math import ceil
@@ -92,37 +94,35 @@ def moderation_reports_panel(request):
Show the global panel for monitoring reports filed against comments or
media entries for this instance.
'''
filters = []
active_settings, closed_settings = {'current_page':1}, {'current_page':1}
form = moderation_forms.ReportPanelSortingForm(request.args)
active_settings = {'start_page':1, 'filters':{}}
closed_settings = {'start_page':1, 'filters':{}}
if form.validate():
active_settings['start_page'] = form.active_p.data or 1
active_settings['filters']['reported_user_id'] = form.active_reported_user.data
active_settings['filters']['reporter_id'] = form.active_reporter.data
closed_settings['start_page'] = form.closed_p.data or 1
closed_settings['filters']['reported_user_id'] = form.closed_reported_user.data
closed_settings['filters']['reporter_id'] = form.closed_reporter.data
active_settings['filters']=dict((k, v) for k, v in active_settings['filters'].iteritems() if v)
closed_settings['filters']=dict((k, v) for k, v in closed_settings['filters'].iteritems() if v)
active_filter = [
getattr(ReportBase,key)==val \
for key,val in active_settings['filters'].viewitems()]
closed_filter = [
getattr(ReportBase,key)==val \
for key,val in active_settings['filters'].viewitems()]
if len(request.args) > 0:
form = moderation_forms.ReportPanelSortingForm(request.args)
if form.validate():
filters = parse_report_panel_settings(form)
active_settings['current_page'] = form.active_p.data or 1
closed_settings['current_page'] = form.closed_p.data or 1
filters = [
getattr(ReportBase,key)==val
for key,val in filters.viewitems()]
all_active = ReportBase.query.filter(
ReportBase.discriminator!="archived_report").filter(
*active_filter)
*filters)
all_closed = ReportBase.query.filter(
ReportBase.discriminator=="archived_report").filter(
*closed_filter)
*filters)
# report_list and closed_report_list are the two lists of up to 10
# items which are actually passed to the user in this request
report_list = all_active.order_by(
ReportBase.created.desc()).offset((active_settings['start_page']-1)*10).limit(10)
ReportBase.created.desc()).offset(
(active_settings['current_page']-1)*10).limit(10)
closed_report_list = all_closed.order_by(
ReportBase.created.desc()).offset((closed_settings['start_page']-1)*10).limit(10)
ReportBase.created.desc()).offset(
(closed_settings['current_page']-1)*10).limit(10)
active_settings['last_page'] = int(ceil(all_active.count()/10.))
closed_settings['last_page'] = int(ceil(all_closed.count()/10.))
# Render to response