aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortilly-Q <nattilypigeonfowl@gmail.com>2013-07-29 15:14:39 -0400
committertilly-Q <nattilypigeonfowl@gmail.com>2013-07-29 15:14:39 -0400
commitf26c21cd5b7998c903fa67aaf164c07743fee651 (patch)
treecc1d073eee35ef991f072c20b50dae5ab4cf5299
parent3aa3871b909500ae9198d63814dd79fd28921f93 (diff)
downloadmediagoblin-f26c21cd5b7998c903fa67aaf164c07743fee651.tar.lz
mediagoblin-f26c21cd5b7998c903fa67aaf164c07743fee651.tar.xz
mediagoblin-f26c21cd5b7998c903fa67aaf164c07743fee651.zip
This is a very small commit. All that I have done here is to clean up my code
a bit. I made it so that mediagoblin.user_pages.report recieves the report form as part of it's context. I also made sure I used {% trans %} tags effect- -ively.
-rw-r--r--mediagoblin/moderation/tools.py2
-rw-r--r--mediagoblin/templates/mediagoblin/moderation/report.html22
-rw-r--r--mediagoblin/templates/mediagoblin/user_pages/report.html74
-rw-r--r--mediagoblin/user_pages/forms.py6
-rw-r--r--mediagoblin/user_pages/lib.py42
-rw-r--r--mediagoblin/user_pages/views.py33
6 files changed, 98 insertions, 81 deletions
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 }}</a>
</div>
<div class=clear></div>
- <p>❖ Reported media by <a href="">
- {{ report.reported_user.username }}</a></p>
+ <p>
+ {% trans user_name=report.reported_user.username,
+ user_url=request.urlgen(
+ 'mediagoblin.moderation.users_detail',
+ user=report.reporter.username) %}
+ ❖ Reported media by <a href="{{ user_url }}">{{ user_name }}</a>
+ {% endtrans %}
+ </p>
<div class=clear></div>
{% else %}
- <h2>{% trans user_url="request.urlgen(
+ <h2>{% 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
- <a href="{{ user_url }}">
- {{ user_name }}</a>
- HAS BEEN DELETED{% endtrans %}
+ CONTENT BY
+ <a href="{{ user_url }}"> {{ user_name }}</a>
+ HAS BEEN DELETED
+ {% endtrans %}
</h2>
{% 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 <http://www.gnu.org/licenses/>.
#}
{%- extends "mediagoblin/base.html" %}
-
-{%- block mediagoblin_content %}
-<h2>File a Report</h2>
+{%- import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
+{%- block mediagoblin_content -%}
+{% trans %}<h2>File a Report</h2>{% endtrans %}
<form action="" method=POST >
{% if comment is defined %}
- <h4>{% trans %}Reporting this Comment {% endtrans %}</h3>
- {% set comment_author = comment.get_author %}
+ <h3>{% trans %}Reporting this Comment{% endtrans %}</h3>
+ {%- set comment_author = comment.get_author %}
+ {%- set comment_author_url = request.urlgen(
+ 'mediagoblin.user_pages.user_home',
+ user=comment_author.username) %}
+ {%- set comment_url = request.urlgen(
+ 'mediagoblin.user_pages.media_home.view_comment',
+ comment=comment.id,
+ user=media.get_uploader.username,
+ media=media.slug_or_id) %}
<div id="comment-{{ comment.id }}"
class="comment_wrapper">
<div class="comment_author">
- <img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
- <a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
- user=comment_author.username) }}"
+ <img
+ src="{{ request.staticdirect('/images/icon_comment.png') }}" />
+ <a href="{{ comment_author_url }}"
class="comment_authorlink">
{{- comment_author.username -}}
</a>
- <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
- comment=comment.id,
- user=media.get_uploader.username,
- media=media.slug_or_id) }}#comment"
+ <a href="{{ comment_url }}"
class="comment_whenlink">
- <span title='{{- comment.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
+ <span
+ title='{{- comment.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
+
{%- trans formatted_time=timesince(comment.created) -%}
{{ formatted_time }} ago
{%- endtrans -%}
@@ -49,27 +56,28 @@
{%- endautoescape %}
</div>
</div>
- <input type=hidden name=comment_id value="{{ comment.id }}" />
{% elif media is defined %}
- <h3>{% trans %}Reporting this Media Entry {% endtrans %}</h3>
- {% trans %}published by {% endtrans %}<a href="{{ request.urlgen('mediagoblin.user_pages.user_home', user=media.get_uploader.username) }}" class="comment_authorlink">{{ media.get_uploader.username }}</a>
- <div class="media_thumbnail">
- <a href="request.urlgen('mediagoblin.user_pages.media_home'),
- user=media.get_uploader.username,
- media=media.slug_or_id)"><img src="{{ media.thumb_url}}"/></a></td></tr>
- <a href="request.urlgen('mediagoblin.user_pages.media_home'),
- user=media.get_uploader.username,
- media=media.slug_or_id)" class=thumb_entry_title>{{ media.title }}</a>
- </div>
- <div class=clear></div>
- <input type=hidden name=media_entry_id value="{{ media.id }}" />
- {% endif %}
- <div class=form_field_input>
- <label class=form_field_label >{% trans %}Reason for reporting:{% endtrans %}</label>
- <textarea name=report_reason></textarea>
- </div>
- <input type=hidden name=reporter_id value="{{ request.user.id }}" />
- <input type=submit />
+ <h3>{% trans %}Reporting this Media Entry{% endtrans %}</h3>
+ <div class="media_thumbnail">
+ <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
+ user=media.get_uploader.username,
+ media=media.slug_or_id) }}">
+ <img src="{{ media.thumb_url }}"/></a>
+ <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
+ user=media.get_uploader.username,
+ media=media.slug_or_id) }}"
+ class=thumb_entry_title>{{ media.title }}</a>
+ </div>
+ <div class=clear></div>
+ {%- trans user_url = request.urlgen('mediagoblin.user_pages.user_home', user=media.get_uploader.username),
+ username = media.get_uploader.username %}
+ ❖ Published by <a href="{{ user_url }}"
+ class="comment_authorlink">{{ username }}</a>
+ {% endtrans %}
+ {%- endif %}
+
+ {{- wtforms_util.render_divs(form) }}
{{ csrf_token }}
+ <input type=submit value="{% trans %}File Report {% endtrans %}" />
</form>
{% 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)
- 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
+ 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
- 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,