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.
This commit is contained in:
tilly-Q 2013-07-29 15:14:39 -04:00
parent 3aa3871b90
commit f26c21cd5b
6 changed files with 99 additions and 82 deletions

View File

@ -107,7 +107,7 @@ def take_punitive_actions(request, form, report, user):
archive.result=form.resolution_content.data archive.result=form.resolution_content.data
# Session.add(archive) Session.add(archive)
Session.commit() Session.commit()
if message_body: if message_body:
send_email( send_email(

View File

@ -75,18 +75,24 @@
{{ media_entry.title }}</a> {{ media_entry.title }}</a>
</div> </div>
<div class=clear></div> <div class=clear></div>
<p>❖ Reported media by <a href=""> <p>
{{ report.reported_user.username }}</a></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> <div class=clear></div>
{% else %} {% else %}
<h2>{% trans user_url="request.urlgen( <h2>{% trans user_url=request.urlgen(
'mediagoblin.moderation.users_detail', 'mediagoblin.moderation.users_detail',
user=report.reporter.username)", user=report.reporter.username),
user_name=report.reported_user.username %} user_name=report.reported_user.username %}
CONTENT BY CONTENT BY
<a href="{{ user_url }}"> <a href="{{ user_url }}"> {{ user_name }}</a>
{{ user_name }}</a> HAS BEEN DELETED
HAS BEEN DELETED{% endtrans %} {% endtrans %}
</h2> </h2>
{% endif %} {% endif %}
Reason for report: Reason for report:

View File

@ -16,28 +16,35 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
{%- extends "mediagoblin/base.html" %} {%- extends "mediagoblin/base.html" %}
{%- import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
{%- block mediagoblin_content %} {%- block mediagoblin_content -%}
<h2>File a Report</h2> {% trans %}<h2>File a Report</h2>{% endtrans %}
<form action="" method=POST > <form action="" method=POST >
{% if comment is defined %} {% if comment is defined %}
<h4>{% trans %}Reporting this Comment {% endtrans %}</h3> <h3>{% trans %}Reporting this Comment{% endtrans %}</h3>
{% set comment_author = comment.get_author %} {%- 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 }}" <div id="comment-{{ comment.id }}"
class="comment_wrapper"> class="comment_wrapper">
<div class="comment_author"> <div class="comment_author">
<img src="{{ request.staticdirect('/images/icon_comment.png') }}" /> <img
<a href="{{ request.urlgen('mediagoblin.user_pages.user_home', src="{{ request.staticdirect('/images/icon_comment.png') }}" />
user=comment_author.username) }}" <a href="{{ comment_author_url }}"
class="comment_authorlink"> class="comment_authorlink">
{{- comment_author.username -}} {{- comment_author.username -}}
</a> </a>
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment', <a href="{{ comment_url }}"
comment=comment.id,
user=media.get_uploader.username,
media=media.slug_or_id) }}#comment"
class="comment_whenlink"> 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) -%} {%- trans formatted_time=timesince(comment.created) -%}
{{ formatted_time }} ago {{ formatted_time }} ago
{%- endtrans -%} {%- endtrans -%}
@ -49,27 +56,28 @@
{%- endautoescape %} {%- endautoescape %}
</div> </div>
</div> </div>
<input type=hidden name=comment_id value="{{ comment.id }}" />
{% elif media is defined %} {% elif media is defined %}
<h3>{% trans %}Reporting this Media Entry {% endtrans %}</h3> <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">
<div class="media_thumbnail"> <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
<a href="request.urlgen('mediagoblin.user_pages.media_home'), user=media.get_uploader.username,
user=media.get_uploader.username, media=media.slug_or_id) }}">
media=media.slug_or_id)"><img src="{{ media.thumb_url}}"/></a></td></tr> <img src="{{ media.thumb_url }}"/></a>
<a href="request.urlgen('mediagoblin.user_pages.media_home'), <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
user=media.get_uploader.username, user=media.get_uploader.username,
media=media.slug_or_id)" class=thumb_entry_title>{{ media.title }}</a> media=media.slug_or_id) }}"
</div> class=thumb_entry_title>{{ media.title }}</a>
<div class=clear></div> </div>
<input type=hidden name=media_entry_id value="{{ media.id }}" /> <div class=clear></div>
{% endif %} {%- trans user_url = request.urlgen('mediagoblin.user_pages.user_home', user=media.get_uploader.username),
<div class=form_field_input> username = media.get_uploader.username %}
<label class=form_field_label >{% trans %}Reason for reporting:{% endtrans %}</label> ❖ Published by <a href="{{ user_url }}"
<textarea name=report_reason></textarea> class="comment_authorlink">{{ username }}</a>
</div> {% endtrans %}
<input type=hidden name=reporter_id value="{{ request.user.id }}" /> {%- endif %}
<input type=submit />
{{- wtforms_util.render_divs(form) }}
{{ csrf_token }} {{ csrf_token }}
<input type=submit value="{% trans %}File Report {% endtrans %}" />
</form> </form>
{% endblock %} {% endblock %}

View File

@ -54,12 +54,10 @@ class CommentReportForm(wtforms.Form):
report_reason = wtforms.TextAreaField( report_reason = wtforms.TextAreaField(
_('Reason for Reporting'), _('Reason for Reporting'),
[wtforms.validators.Required()]) [wtforms.validators.Required()])
comment_id = wtforms.IntegerField() reporter_id = wtforms.HiddenField('')
reporter_id = wtforms.IntegerField()
class MediaReportForm(wtforms.Form): class MediaReportForm(wtforms.Form):
report_reason = wtforms.TextAreaField( report_reason = wtforms.TextAreaField(
_('Reason for Reporting'), _('Reason for Reporting'),
[wtforms.validators.Required()]) [wtforms.validators.Required()])
media_entry_id = wtforms.IntegerField() reporter_id = wtforms.HiddenField('')
reporter_id = wtforms.IntegerField()

View File

@ -78,39 +78,33 @@ def add_media_to_collection(collection, media, note=None, commit=True):
if commit: if commit:
Session.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. report) into either a MediaReport or CommentReport object.
:param form_dict should be an ImmutableMultiDict object as is returned from :param report_form should be a MediaReportForm or a CommentReportForm
'request.form.' The Object should have valid keys matching the fields object
in either MediaReportForm or CommentReportForm :param
:returns either of MediaReport or a CommentReport object that has not been :returns either of MediaReport or a CommentReport object that has not been
saved. In case of an improper form_dict, returns None saved. In case of an improper form_dict, returns None
""" """
if 'comment_id' in form_dict.keys():
report_form = user_forms.CommentReportForm(form_dict) if report_form.validate() and comment is not None:
elif 'media_entry_id' in form_dict.keys(): report_object = CommentReport()
report_form = user_forms.MediaReportForm(form_dict) 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: else:
return None return None
if report_form.validate() and 'comment_id' in form_dict.keys(): report_object.report_content = report_form.report_reason.data
report_model = CommentReport() report_object.reporter_id = report_form.reporter_id.data
report_model.comment_id = report_form.comment_id.data return report_object
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

View File

@ -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.translate import pass_to_ugettext as _
from mediagoblin.tools.pagination import Pagination from mediagoblin.tools.pagination import Pagination
from mediagoblin.user_pages import forms as user_forms 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) add_media_to_collection)
from mediagoblin.decorators import (uses_pagination, get_user_media_entry, from mediagoblin.decorators import (uses_pagination, get_user_media_entry,
@ -625,19 +625,30 @@ def processing_panel(request):
@get_user_media_entry @get_user_media_entry
@user_has_privilege(u'reporter') @user_has_privilege(u'reporter')
def file_a_report(request, media, comment=None): 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: if comment is not None:
form = user_forms.CommentReportForm(request.form)
form.reporter_id.data = request.user.id
context = {'media': media, context = {'media': media,
'comment':comment} 'comment':comment,
'form':form}
else: 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( return render_to_response(
request, request,