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:
parent
3aa3871b90
commit
f26c21cd5b
@ -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(
|
||||
|
@ -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:
|
||||
|
@ -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 %}
|
||||
|
@ -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('')
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user