This is the first stage of my project of implenting admin/moderator functiona-

lity. At this point, I have finished all the of basic work with the models! I
still need to do some tightening of their documentation, but they seem to be
working well.

Working with Models
========================================

--\ mediagoblin/db/models.py
--| Added in the Report model and table. This model is strictly a parent
----| Added in the CommentReport model which holds information about a report
    | filed against a comment. This class inherits from Report.
----| Added in the MediaReport model which holds information about a report f-
    | -iled against a media entry. This class inherits from Report.
--| Added in a UserBan model and table. This model is in a one to one relatio-
  | -nship with User. This object acts as a marker for whether a user is banned
  | or not.
--| Added in a Group model. These objects are in a many-to-many relationship
  | with User to explain which privileges a User has.
----| Added in GroupUserAssociation which is a table used to hold this many to
    | many relationship  between Group & User.

--\ mediagoblin/db/migrations.py
--| Added in the migrations for all of the additions to models
--| Added UserBan_v0
--| Added Report_v0
----| Added CommentReport_v0
----| Added MediaReport_v0
--| Added Group_v0
----| Added GroupUserAssociation_v0

Working with Templates, Views, and Routing
===============================================

>>> Reporting a Comment or a MediaEntry

--\ mediagoblin/user_pages/views.py
--| Added in the function file_a_report to allow user to file reports against
  | MediaEntries or Comments. Handles GET and POST requests.
--| Added in the function file_a_comment_report which uses file_a_report but
  | also catches appropriate information for comment_ids. I may be able to do
  | this more eloquently with decorators.

--\ mediagoblin/user_pages/routing.py
--| Added in route 'mediagoblin.user_pages.media_home.report_media'
  | (linked to address /u/<user>/m/<media>/report/ )
--| Added in route ''mediagoblin.user_pages.media_home.report_comment'
  | (linked to address /u/<user>/m/<media>/c/<comment>/report/ )

--\ mediagoblin/templates/mediagoblin/user_pages/report.html
--| I created this file to handle the filing of a report.

--\ mediagoblin/templates/mediagoblin/user_pages/media.html
--| Modified this file to add in links allowing users to report either media
  | or comments.

--\ mediagoblin/user_pages/lib.py
--| Added in build_report_form which processes data as either a CommentReport or
  | a MediaReport depending on which parameters are present

--\ mediagoblin/user_pages/forms.py
--| Added in CommentReportForm
--| Added in MediaReportForm
--| note: ReportForm is vestigial to an earlier strategy I used and I'll remove it
  | promptly

--\ mediagoblin/decorators.py
--| Added in 'get_media_comment_by_id' for use in mediagoblin/user_pages/views.py

>>> New Admin Panels

--\ mediagoblin/admin/views.py
--| Added in the function admin_users_panel
--| Added in the function admin_reports_panel

--\ mediagoblin/admin/routing.py
--| Added in route 'mediagoblin.admin.users'
  | (linked to address '/a/users')
--| Added in route 'mediagoblin.admin.reports'
  | (linked to address '/a/reports/')

--\ mediagoblin/templates/admin/user.html
--| Created this file as a template for monitoring users

--\ mediagoblin/templates/admin/report.html
--| Created this file as a template for monitoring reports filed against media or
  | comments
This commit is contained in:
tilly-Q
2013-06-24 16:35:31 -07:00
parent 25aad338d4
commit 30a9fe7c1c
13 changed files with 548 additions and 10 deletions

View File

@@ -49,3 +49,19 @@ class MediaCollectForm(wtforms.Form):
description=_("""You can use
<a href="http://daringfireball.net/projects/markdown/basics">
Markdown</a> for formatting."""))
class CommentReportForm(wtforms.Form):
report_reason = wtforms.TextAreaField('Reason for Reporting')
comment_id = wtforms.IntegerField()
reporter_id = wtforms.IntegerField()
class MediaReportForm(wtforms.Form):
report_reason = wtforms.TextAreaField('Reason for Reporting')
media_entry_id = wtforms.IntegerField()
reporter_id = wtforms.IntegerField()
class ReportForm(wtforms.Form):
report_reason = wtforms.TextAreaField('Reason for Reporting')
media_entry_id = wtforms.IntegerField()
reporter_id = wtforms.IntegerField()
comment_id = wtforms.IntegerField()

View File

@@ -19,7 +19,8 @@ from mediagoblin.tools.template import render_template
from mediagoblin.tools.translate import pass_to_ugettext as _
from mediagoblin import mg_globals
from mediagoblin.db.base import Session
from mediagoblin.db.models import CollectionItem
from mediagoblin.db.models import CollectionItem, MediaReport, CommentReport
from mediagoblin.user_pages import forms as user_forms
def send_comment_email(user, comment, media, request):
@@ -75,3 +76,31 @@ def add_media_to_collection(collection, media, note=None, commit=True):
if commit:
Session.commit()
def build_report_form(form_dict):
"""
:param form_dict should be an ImmutableMultiDict object which is what is
returned from 'request.form.' The Object should have valid keys
matching the fields in either MediaReportForm or CommentReportForm
:returns either of MediaReport or a CommentReport object that has not been saved.
In case of an improper form_dict, returns None
"""
if 'comment_id' in form_dict.keys():
report_form = user_forms.CommentReportForm(form_dict)
elif 'media_entry_id' in form_dict.keys():
report_form = user_forms.MediaReportForm(form_dict)
else:
return None
if report_form.validate() and 'comment_id' in form_dict.keys():
report_model = CommentReport()
report_model.comment_id = report_form.comment_id.data
elif report_form.validate() and 'media_entry_id' in form_dict.keys():
report_model = MediaReport()
report_model.media_entry_id = report_form.media_entry_id.data
else:
return None
report_model.report_content = report_form.report_reason.data or u''
report_model.reporter_id = report_form.reporter_id.data
return report_model

View File

@@ -23,6 +23,10 @@ add_route('mediagoblin.user_pages.media_home',
'/u/<string:user>/m/<string:media>/',
'mediagoblin.user_pages.views:media_home')
add_route('mediagoblin.user_pages.media_home.report_media',
'/u/<string:user>/m/<string:media>/report/',
'mediagoblin.user_pages.views:file_a_report')
add_route('mediagoblin.user_pages.media_confirm_delete',
'/u/<string:user>/m/<int:media_id>/confirm-delete/',
'mediagoblin.user_pages.views:media_confirm_delete')
@@ -40,6 +44,10 @@ add_route('mediagoblin.user_pages.media_home.view_comment',
'/u/<string:user>/m/<string:media>/c/<int:comment>/',
'mediagoblin.user_pages.views:media_home')
add_route('mediagoblin.user_pages.media_home.report_comment',
'/u/<string:user>/m/<string:media>/c/<int:comment>/report/',
'mediagoblin.user_pages.views:file_a_comment_report')
# User's tags gallery
add_route('mediagoblin.user_pages.user_tag_gallery',
'/u/<string:user>/tag/<string:tag>/',

View File

@@ -19,19 +19,21 @@ import datetime
from mediagoblin import messages, mg_globals
from mediagoblin.db.models import (MediaEntry, MediaTag, Collection,
CollectionItem, User)
CollectionItem, User, MediaComment,
CommentReport, MediaReport)
from mediagoblin.tools.response import render_to_response, render_404, \
redirect, redirect_obj
from mediagoblin.tools.translate import pass_to_ugettext as _
from mediagoblin.tools.pagination import Pagination
from mediagoblin.user_pages import forms as user_forms
from mediagoblin.user_pages.lib import (send_comment_email,
from mediagoblin.user_pages.lib import (send_comment_email, build_report_form,
add_media_to_collection)
from mediagoblin.decorators import (uses_pagination, get_user_media_entry,
get_media_entry_by_id,
require_active_login, user_may_delete_media, user_may_alter_collection,
get_user_collection, get_user_collection_item, active_user_from_url)
get_user_collection, get_user_collection_item, active_user_from_url,
get_media_comment_by_id)
from werkzeug.contrib.atom import AtomFeed
@@ -616,3 +618,28 @@ def processing_panel(request):
'processing_entries': processing_entries,
'failed_entries': failed_entries,
'processed_entries': processed_entries})
@require_active_login
@get_user_media_entry
def file_a_report(request, media, comment=None):
if request.method == "POST":
report_form = build_report_form(request.form)
report_form.save()
return redirect(
request,
'index')
if comment is not None:
context = {'media': media,
'comment':comment}
else:
context = {'media': media}
return render_to_response(
request,
'mediagoblin/user_pages/report.html',
context)
@require_active_login
@get_user_media_entry
@get_media_comment_by_id
def file_a_comment_report(request, media, comment):
return file_a_report(request, comment=comment)