I've moved on to one of the last phases of my work! Now I'm just checking off

items from my last to-do list. The biggest change in this commit is that I made
the moderation reports panel sortable via get request. I also added in page nu-
mbers so that more than 10 reports can be viewed. I'm hoping to go from here to
make a search page. Aside from that, there were only a few other changes I made
this time. I fixed two bugs in my code. I copy-ed and pasted function
mediagoblin.user_pages.views:media_preview_comment which I must've deleted ear-
-lier in a merge. And I moved some of the javascript I was using in the modera-
-tion templates into it's own seperate .js file.

===============================================================================
    Made the moderation reports panel view sortable
===============================================================================
--\ mediagoblin/moderation/forms.py
--\ mediagoblin/moderation/views.py
--\ mediagoblin/templates/mediagoblin/moderation/report_panel.html
--\ mediagoblin/templates/mediagoblin/moderation/user.html
--|  Made `<user> report history` into a link that automatically shows all open
  | and closed reports on <user>.

===============================================================================
    Grabbed some code from master that I accidentally deleted in a merge
===============================================================================
--\ mediagoblin/user_pages/views.py

===============================================================================
    Moved javascript away from templates into its own file
===============================================================================
--\ mediagoblin/static/js/setup_report_forms.js
--\ mediagoblin/templates/mediagoblin/moderation/report.html
--\ mediagoblin/templates/mediagoblin/moderation/user.html

===============================================================================
    Cleared trailing white space
===============================================================================
--\ mediagoblin/templates/mediagoblin/moderation/media_panel.html
--\ mediagoblin/moderation/tools.py
--\ mediagoblin/templates/mediagoblin/meta/terms_of_service.html
--\ mediagoblin/templates/mediagoblin/moderation/report_panel.html
--\ mediagoblin/templates/mediagoblin/user_pages/media.html
--\ mediagoblin/tests/test_modelmethods.py

===============================================================================
    Small fixes
===============================================================================
--\ mediagoblin/templates/mediagoblin/moderation/report.html
--|  Fixed a link so that it points to the correct user page

--\ mediagoblin/templates/mediagoblin/user_pages/media.html
--|  Fixed a bug that crashed this page when a guest visitted it (because
  | request.user is None)
This commit is contained in:
tilly-Q 2013-09-03 11:57:10 -04:00
parent 1bb367f613
commit dc31cd1b65
12 changed files with 351 additions and 204 deletions

View File

@ -67,3 +67,23 @@ class ReportResolutionForm(wtforms.Form):
validators=[wtforms.validators.optional()]) validators=[wtforms.validators.optional()])
resolution_content = wtforms.TextAreaField() resolution_content = wtforms.TextAreaField()
class ReportPanelSortingForm(wtforms.Form):
active_p = wtforms.IntegerField(
_(u'Page'),
validators=[wtforms.validators.optional()])
active_reported_user = wtforms.IntegerField(
_(u'Reported User'),
validators=[wtforms.validators.optional()])
active_reporter = wtforms.IntegerField(
_(u'Reporter'),
validators=[wtforms.validators.optional()])
closed_p = wtforms.IntegerField(
_(u'Page'),
validators=[wtforms.validators.optional()])
closed_reported_user = wtforms.IntegerField(
_(u'Reported User'),
validators=[wtforms.validators.optional()])
closed_reporter = wtforms.IntegerField(
_(u'Reporter'),
validators=[wtforms.validators.optional()])

View File

@ -26,6 +26,7 @@ from mediagoblin.moderation import forms as moderation_forms
from mediagoblin.moderation.tools import (take_punitive_actions, \ from mediagoblin.moderation.tools import (take_punitive_actions, \
take_away_privileges, give_privileges, ban_user, unban_user) take_away_privileges, give_privileges, ban_user, unban_user)
from datetime import datetime from datetime import datetime
from math import ceil
@require_admin_or_moderator_login @require_admin_or_moderator_login
def moderation_media_processing_panel(request): def moderation_media_processing_panel(request):
@ -91,19 +92,47 @@ def moderation_reports_panel(request):
Show the global panel for monitoring reports filed against comments or Show the global panel for monitoring reports filed against comments or
media entries for this instance. media entries for this instance.
''' '''
report_list = ReportBase.query.filter(
ReportBase.discriminator!="archived_report").order_by(
ReportBase.created.desc()).limit(10)
closed_report_list = ReportBase.query.filter(
ReportBase.discriminator=="archived_report").order_by(
ReportBase.created.desc()).limit(10)
form = moderation_forms.ReportPanelSortingForm(request.args)
active_settings = {'start_page':1, 'filters':{}}
closed_settings = {'start_page':1, 'filters':{}}
if form.validate():
active_settings['start_page'] = form.active_p.data or 1
active_settings['filters']['reported_user_id'] = form.active_reported_user.data
active_settings['filters']['reporter_id'] = form.active_reporter.data
closed_settings['start_page'] = form.closed_p.data or 1
closed_settings['filters']['reported_user_id'] = form.closed_reported_user.data
closed_settings['filters']['reporter_id'] = form.closed_reporter.data
active_settings['filters']=dict((k, v) for k, v in active_settings['filters'].iteritems() if v)
closed_settings['filters']=dict((k, v) for k, v in closed_settings['filters'].iteritems() if v)
active_filter = [
getattr(ReportBase,key)==val \
for key,val in active_settings['filters'].viewitems()]
closed_filter = [
getattr(ReportBase,key)==val \
for key,val in active_settings['filters'].viewitems()]
all_active = ReportBase.query.filter(
ReportBase.discriminator!="archived_report").filter(
*active_filter)
all_closed = ReportBase.query.filter(
ReportBase.discriminator=="archived_report").filter(
*closed_filter)
report_list = all_active.order_by(
ReportBase.created.desc()).offset((active_settings['start_page']-1)*10).limit(10)
closed_report_list = all_closed.order_by(
ReportBase.created.desc()).offset((closed_settings['start_page']-1)*10).limit(10)
active_settings['last_page'] = int(ceil(all_active.count()/10.))
closed_settings['last_page'] = int(ceil(all_closed.count()/10.))
# Render to response # Render to response
return render_to_response( return render_to_response(
request, request,
'mediagoblin/moderation/report_panel.html', 'mediagoblin/moderation/report_panel.html',
{'report_list':report_list, {'report_list':report_list,
'closed_report_list':closed_report_list}) 'closed_report_list':closed_report_list,
'active_settings':active_settings,
'closed_settings':closed_settings})
@require_admin_or_moderator_login @require_admin_or_moderator_login
def moderation_reports_detail(request): def moderation_reports_detail(request):

View File

@ -0,0 +1,67 @@
/**
* GNU MediaGoblin -- federated, autonomous media hosting
* Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function init_report_resolution_form() {
hidden_input_names = {
'takeaway':['take_away_privileges'],
'userban':['user_banned_until','why_user_was_banned'],
'sendmessage':['message_to_user']
}
init_user_banned_form();
$('form#resolution_form').hide()
$('#open_resolution_form').click(function() {
$('form#resolution_form').toggle();
$.each(hidden_input_names, function(key, list){
$.each(list, function(index, name){
$('label[for='+name+']').hide();
$('#'+name).hide();
});
});
});
$('#action_to_resolve').change(function() {
$('ul#action_to_resolve li input:checked').each(function() {
$.each(hidden_input_names[$(this).val()], function(index, name){
$('label[for='+name+']').show();
$('#'+name).show();
});
});
$('ul#action_to_resolve li input:not(:checked)').each(function() {
$.each(hidden_input_names[$(this).val()], function(index, name){
$('label[for='+name+']').hide();
$('#'+name).hide();
});
});
});
$("#submit_this_report").click(function(){
submit_user_banned_form()
});
}
function submit_user_banned_form() {
if ($("#user_banned_until").val() == 'YYYY-MM-DD'){
$("#user_banned_until").val("");
}
}
function init_user_banned_form() {
$('#user_banned_until').val("YYYY-MM-DD")
$("#user_banned_until").focus(function() {
$(this).val("");
$(this).unbind('focus');
});
}

View File

@ -21,6 +21,7 @@
{% trans %}Media processing panel{% endtrans %} &mdash; {{ super() }} {% trans %}Media processing panel{% endtrans %} &mdash; {{ super() }}
{%- endblock %} {%- endblock %}
{% block mediagoblin_content %} {% block mediagoblin_content %}
<h1>{% trans %}Media processing panel{% endtrans %}</h1> <h1>{% trans %}Media processing panel{% endtrans %}</h1>

View File

@ -17,6 +17,9 @@
#} #}
{%- extends "mediagoblin/base.html" %} {%- extends "mediagoblin/base.html" %}
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
{%- block mediagoblin_head %}
<script src="{{ request.staticdirect('/js/setup_report_forms.js') }}"></script>
{% endblock %}
{%- block mediagoblin_content %} {%- block mediagoblin_content %}
{% if not report %} {% if not report %}
@ -79,7 +82,7 @@
{% trans user_name=report.reported_user.username, {% trans user_name=report.reported_user.username,
user_url=request.urlgen( user_url=request.urlgen(
'mediagoblin.moderation.users_detail', 'mediagoblin.moderation.users_detail',
user=report.reporter.username) %} user=report.reported_user.username) %}
❖ Reported media by <a href="{{ user_url }}">{{ user_name }}</a> ❖ Reported media by <a href="{{ user_url }}">{{ user_name }}</a>
{% endtrans %} {% endtrans %}
</p> </p>
@ -129,50 +132,9 @@
{{ csrf_token }} {{ csrf_token }}
<input type=submit id="submit_this_report" value="Resolve This Report"/> <input type=submit id="submit_this_report" value="Resolve This Report"/>
</form> </form>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
hidden_input_names = { init_report_resolution_form();
'takeaway':['take_away_privileges'],
'userban':['user_banned_until','why_user_was_banned'],
'sendmessage':['message_to_user']
}
$('form#resolution_form').hide()
$('#user_banned_until').val("YYYY-MM-DD")
$('#open_resolution_form').click(function() {
$('form#resolution_form').toggle();
$.each(hidden_input_names, function(key, list){
$.each(list, function(index, name){
$('label[for='+name+']').hide();
$('#'+name).hide();
});
});
});
$('#action_to_resolve').change(function() {
$('ul#action_to_resolve li input:checked').each(function() {
$.each(hidden_input_names[$(this).val()], function(index, name){
$('label[for='+name+']').show();
$('#'+name).show();
});
});
$('ul#action_to_resolve li input:not(:checked)').each(function() {
$.each(hidden_input_names[$(this).val()], function(index, name){
$('label[for='+name+']').hide();
$('#'+name).hide();
});
});
});
$("#user_banned_until").focus(function() {
$(this).val("");
$(this).unbind('focus');
});
$("#submit_this_report").click(function(){
if ($("#user_banned_until").val() == 'YYYY-MM-DD'){
$("#user_banned_until").val("");
}
});
}); });
</script> </script>
{% elif not (report.reported_user.has_privilege('admin')) %} {% elif not (report.reported_user.has_privilege('admin')) %}

View File

@ -32,7 +32,37 @@
</p> </p>
<h2>{% trans %}Active Reports Filed{% endtrans %}</h2> <h2>{% trans %}Active Reports Filed{% endtrans %}</h2>
{% if not active_settings.last_page == 1 %}
{% if 'active_p='~active_settings.start_page in request.query_string %}
{% set query_string = request.query_string %}{% else %}
{% set query_string =
'active_p='~active_settings.start_page~"&"+request.query_string %}
{% endif %}
<div class="right_align">
{% set first_vis = active_settings.start_page-3 %}
{% set last_vis = active_settings.start_page+3 %}
{% set curr_page = active_settings.start_page %}
{% if 1 == curr_page %}<b>1</b>{% else %}
<a href ="?{{ query_string.replace(
'active_p='~active_settings.start_page,
'active_p='~1) }}">
{{ 1 }}</a>{% endif %}
{% if first_vis > 1 %}...{% endif %}
{% for p in range(first_vis,last_vis+1) %}
{% if p > 1 and p < active_settings.last_page %}
<a href="?{{ query_string.replace(
'active_p='~active_settings.start_page,
'active_p='~p) }}">
{{ p }}</a>
{% endif %}
{% endfor %}
{% if last_vis < active_settings.last_page %}...{% endif %}
<a href ="?{{ query_string.replace(
'active_p='~active_settings.start_page,
'active_p='~active_settings.last_page) }}">
{{ active_settings.last_page }}</a>
</div>
{% endif %}
{% if report_list.count() %} {% if report_list.count() %}
<table class="admin_panel processing"> <table class="admin_panel processing">
<tr> <tr>
@ -84,6 +114,35 @@
<p><em>{% trans %}No open reports found.{% endtrans %}</em></p> <p><em>{% trans %}No open reports found.{% endtrans %}</em></p>
{% endif %} {% endif %}
<h2>{% trans %}Closed Reports{% endtrans %}</h2> <h2>{% trans %}Closed Reports{% endtrans %}</h2>
{% if not closed_settings.last_page == 1 %}
{% if 'closed_p='~closed_settings.start_page in request.query_string %}
{% set query_string = request.query_string %}{% else %}
{% set query_string =
'closed_p='~closed_settings.start_page~"&"+request.query_string %}
{% endif %}
<div class="right_align">
{% set first_vis = closed_settings.start_page-3 %}
{% set last_vis = closed_settings.start_page+3 %}
<a href ="?{{ query_string.replace(
'closed_p='~closed_settings.start_page,
'closed_p='~1) }}">
{{ 1 }}</a>
{% if first_vis > 1 %}...{% endif %}
{% for p in range(first_vis,last_vis+1) %}
{% if p > 1 and p < closed_settings.last_page %}
<a href="?{{ query_string.replace(
'closed_p='~closed_settings.start_page,
'closed_p='~p) }}">
{{ p }}</a>
{% endif %}
{% endfor %}
{% if last_vis < closed_settings.last_page %}...{% endif %}
<a href ="?{{ query_string.replace(
'closed_p='~closed_settings.start_page,
'closed_p='~closed_settings.last_page) }}">
{{ closed_settings.last_page }}</a>
</div>
{% endif %}
{% if closed_report_list.count() %} {% if closed_report_list.count() %}
<table class="media_panel processing"> <table class="media_panel processing">
<tr> <tr>

View File

@ -28,6 +28,9 @@
{%- endif -%} {%- endif -%}
{% endblock %} {% endblock %}
{%- block mediagoblin_head %}
<script src="{{ request.staticdirect('/js/setup_report_forms.js') }}"></script>
{% endblock %}
{% block mediagoblin_content -%} {% block mediagoblin_content -%}
{# If no user... #} {# If no user... #}
@ -127,7 +130,8 @@
{% else %} {% else %}
{%- trans %}No active reports filed on {% endtrans -%} {{ user.username }} {%- trans %}No active reports filed on {% endtrans -%} {{ user.username }}
{% endif %} {% endif %}
<a class="right_align">{{ user.username }}'s report history</a> <a href="{{ request.urlgen('mediagoblin.moderation.reports') }}?active_reported_user={{user.id}}&closed_reported_user={{user.id}}"
class="right_align">{{ user.username }}'s report history</a>
<span class=clear></span> <span class=clear></span>
<h2>{{ user.username }}'s Privileges</h2> <h2>{{ user.username }}'s Privileges</h2>
<form method=POST action="{{ request.urlgen( <form method=POST action="{{ request.urlgen(
@ -188,16 +192,8 @@ $(document).ready(function(){
$('.submit_button').click(function(){ $('.submit_button').click(function(){
$('#hidden_privilege_name').val($(this).attr('id')); $('#hidden_privilege_name').val($(this).attr('id'));
}); });
$('#user_banned_until').val("YYYY-MM-DD") init_user_banned_form();
$("#user_banned_until").focus(function() { $('.ban_user_submit').click(function(){submit_user_banned_form()});
$(this).val("");
$(this).unbind('focus');
});
$("#ban_user_submit").click(function(){
if ($("#user_banned_until").val() == 'YYYY-MM-DD'){
$("#user_banned_until").val("");
}
});
}); });
</script> </script>
{% endblock %} {% endblock %}

View File

@ -86,7 +86,7 @@
{% autoescape False %} {% autoescape False %}
<p>{{ media.description_html }}</p> <p>{{ media.description_html }}</p>
{% endautoescape %} {% endautoescape %}
{% if comments and request.user.has_privilege('commenter') %} {% if comments and request.user and request.user.has_privilege('commenter') %}
{% if app_config['allow_comments'] %} {% if app_config['allow_comments'] %}
<a <a
{% if not request.user %} {% if not request.user %}

View File

@ -199,6 +199,19 @@ def media_post_comment(request, media):
return redirect_obj(request, media) return redirect_obj(request, media)
def media_preview_comment(request):
"""Runs a comment through markdown so it can be previewed."""
# If this isn't an ajax request, render_404
if not request.is_xhr:
return render_404(request)
comment = unicode(request.form['comment_content'])
cleancomment = { "content":cleaned_markdown_conversion(comment)}
return Response(json.dumps(cleancomment))
@user_not_banned @user_not_banned
@get_media_entry_by_id @get_media_entry_by_id
@require_active_login @require_active_login