diff --git a/mediagoblin/moderation/tools.py b/mediagoblin/moderation/tools.py
index 9a3b1c2e..25e5dc63 100644
--- a/mediagoblin/moderation/tools.py
+++ b/mediagoblin/moderation/tools.py
@@ -107,7 +107,7 @@ def take_punitive_actions(request, form, report, user):
archive.result=form.resolution_content.data
-# Session.add(archive)
+ Session.add(archive)
Session.commit()
if message_body:
send_email(
diff --git a/mediagoblin/templates/mediagoblin/moderation/report.html b/mediagoblin/templates/mediagoblin/moderation/report.html
index 44067771..b912c712 100644
--- a/mediagoblin/templates/mediagoblin/moderation/report.html
+++ b/mediagoblin/templates/mediagoblin/moderation/report.html
@@ -75,18 +75,24 @@
{{ media_entry.title }}
- ❖ Reported media by
- {{ report.reported_user.username }}
+
+ {% trans user_name=report.reported_user.username,
+ user_url=request.urlgen(
+ 'mediagoblin.moderation.users_detail',
+ user=report.reporter.username) %}
+ ❖ Reported media by {{ user_name }}
+ {% endtrans %}
+
{% else %}
- {% trans user_url="request.urlgen(
+ {% trans user_url=request.urlgen(
'mediagoblin.moderation.users_detail',
- user=report.reporter.username)",
+ user=report.reporter.username),
user_name=report.reported_user.username %}
- CONTENT BY
-
- {{ user_name }}
- HAS BEEN DELETED{% endtrans %}
+ CONTENT BY
+ {{ user_name }}
+ HAS BEEN DELETED
+ {% endtrans %}
{% endif %}
Reason for report:
diff --git a/mediagoblin/templates/mediagoblin/user_pages/report.html b/mediagoblin/templates/mediagoblin/user_pages/report.html
index 9431efc0..cd5e6f59 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/report.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/report.html
@@ -16,28 +16,35 @@
# along with this program. If not, see .
#}
{%- extends "mediagoblin/base.html" %}
-
-{%- block mediagoblin_content %}
-File a Report
+{%- import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
+{%- block mediagoblin_content -%}
+{% trans %}File a Report
{% endtrans %}
{% endblock %}
diff --git a/mediagoblin/user_pages/forms.py b/mediagoblin/user_pages/forms.py
index 260fe02b..d83338e9 100644
--- a/mediagoblin/user_pages/forms.py
+++ b/mediagoblin/user_pages/forms.py
@@ -54,12 +54,10 @@ class CommentReportForm(wtforms.Form):
report_reason = wtforms.TextAreaField(
_('Reason for Reporting'),
[wtforms.validators.Required()])
- comment_id = wtforms.IntegerField()
- reporter_id = wtforms.IntegerField()
+ reporter_id = wtforms.HiddenField('')
class MediaReportForm(wtforms.Form):
report_reason = wtforms.TextAreaField(
_('Reason for Reporting'),
[wtforms.validators.Required()])
- media_entry_id = wtforms.IntegerField()
- reporter_id = wtforms.IntegerField()
+ reporter_id = wtforms.HiddenField('')
diff --git a/mediagoblin/user_pages/lib.py b/mediagoblin/user_pages/lib.py
index cf7b604d..7f03fcd3 100644
--- a/mediagoblin/user_pages/lib.py
+++ b/mediagoblin/user_pages/lib.py
@@ -78,39 +78,33 @@ def add_media_to_collection(collection, media, note=None, commit=True):
if commit:
Session.commit()
-def build_report_table(form_dict):
+def build_report_object(report_form, media_entry=None, comment=None):
"""
- This function is used to convert a form dictionary (from a User filing a
+ This function is used to convert a form object (from a User filing a
report) into either a MediaReport or CommentReport object.
- :param form_dict should be an ImmutableMultiDict object as is returned from
- 'request.form.' The Object should have valid keys matching the fields
- in either MediaReportForm or CommentReportForm
+ :param report_form should be a MediaReportForm or a CommentReportForm
+ object
+ :param
: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)
+
+ if report_form.validate() and comment is not None:
+ report_object = CommentReport()
+ report_object.comment_id = comment.id
+ report_object.reported_user_id = MediaComment.query.get(
+ comment.id).get_author.id
+ elif report_form.validate() and media_entry is not None:
+ report_object = MediaReport()
+ report_object.media_entry_id = media_entry.id
+ report_object.reported_user_id = MediaEntry.query.get(
+ media_entry.id).get_uploader.id
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
- report_model.reported_user_id = MediaComment.query.get(
- report_model.comment_id).get_author.id
- 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
- report_model.reported_user_id = MediaEntry.query.get(
- report_model.media_entry_id).get_uploader.id
- 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
+ report_object.report_content = report_form.report_reason.data
+ report_object.reporter_id = report_form.reporter_id.data
+ return report_object
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index c1638276..1a78bcc7 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -26,7 +26,7 @@ from mediagoblin.tools.response import render_to_response, render_404, \
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, build_report_table,
+from mediagoblin.user_pages.lib import (send_comment_email, build_report_object,
add_media_to_collection)
from mediagoblin.decorators import (uses_pagination, get_user_media_entry,
@@ -625,19 +625,30 @@ def processing_panel(request):
@get_user_media_entry
@user_has_privilege(u'reporter')
def file_a_report(request, media, comment=None):
- if request.method == "POST":
- report_table = build_report_table(request.form)
- report_table.save()
-
- return redirect(
- request,
- 'index')
-
if comment is not None:
+ form = user_forms.CommentReportForm(request.form)
+ form.reporter_id.data = request.user.id
context = {'media': media,
- 'comment':comment}
+ 'comment':comment,
+ 'form':form}
else:
- context = {'media': media}
+ form = user_forms.MediaReportForm(request.form)
+ form.reporter_id.data = request.user.id
+ context = {'media': media,
+ 'form':form}
+
+ if request.method == "POST":
+ report_table = build_report_object(form,
+ media_entry=media,
+ comment=comment)
+
+ # if the object was built successfully, report_table will not be None
+ if report_table:
+ report_table.save()
+ return redirect(
+ request,
+ 'index')
+
return render_to_response(
request,