Reports page

This commit is contained in:
Chinua Shaw 2012-11-05 14:39:08 -05:00
parent 1776157d68
commit 66571b4f30
3 changed files with 101 additions and 2 deletions
djangobb_forum
templates/djangobb_forum
urls.pyviews.py

View file

@ -0,0 +1,73 @@
{% extends 'djangobb_forum/base.html' %}
{% load forum_extras %}
{% load i18n %}
{% block content %}
<div class="box">
<h2>New Reports</h2>
<form method="post" action="?action=zap">
{% csrf_token %}
<table>
<tr>
<th scope="col" class="sortable" style="width:20%">Reported By</th>
<th scope="col" class="sortable" style="width:40%">Reason</th>
<th scope="col" class="sortable" style="width:30%">Post</th>
<th scope="col" class="sortable" style="width:10%">Zap</th>
</tr>
{% for report in new_reports %}
<tr>
<td>
{{ report.reported_by }}
<br>
{{ report.created }}
</td><td>
{{ report.reason }}
</td><td>
<a href="{{report.post.get_absolute_url}}"> {{ report.post }} </a>
<br><br>
Posted By:<a href="{% url profile_detail report.post.user.username %}"> {{ report.post.user }} </a>
</td><td>
<input type="submit" name="zap_id[{{ report.id }}]" value=" Zap ">
</td></tr>
{% endfor %}
</table>
</form>
</div>
<br><br>
<div class ="box">
<h2>Recently Zapped Reports</h2>
<form method="post" action="?action=zap">
{% csrf_token %}
<table>
<tr>
<th scope="col" class="sortable" style="width:20%">Reported By</th>
<th scope="col" class="sortable" style="width:40%">Reason</th>
<th scope="col" class="sortable" style="width:25%">Post</th>
<th scope="col" class="sortable" style="width:15%">Zapped</th>
</tr>
{% for report in zapped_reports %}
<tr>
<td>
{{ report.reported_by }}
<br>
{{ report.created }}
</td><td>
{{ report.reason }}
</td><td>
<a href="{{report.post.get_absolute_url}}"> {{ report.post }} </a>
<br><br>
Posted By:<a href="{% url profile_detail report.post.user.username %}"> {{ report.post.user }} </a>
</td><td>
<input type="submit" name="zap_id[{{ report.id }}]" value=" Unzap ">
<br>
Zapped By: {{ report.zapped_by }}
</td></tr>
{% endfor %}
</table>
</form>
</div>
{% endblock %}
{% block controls %}
{% endblock %}

View file

@ -17,7 +17,6 @@ urlpatterns = patterns('',
url('^moderate/(?P<forum_id>\d+)/$', forum_views.moderate, name='moderate'),
url('^search/$', forum_views.search, name='search'),
url('^misc/$', forum_views.misc, name='misc'),
# User
url('^user/(?P<username>.*)/upload_avatar/$', forum_views.upload_avatar, {
'form_class': UploadAvatarForm,
@ -67,6 +66,9 @@ urlpatterns = patterns('',
# Post preview
url(r'^preview/$', forum_views.post_preview, name='post_preview'),
# Reports
url(r'^reports/$', forum_views.reports, name='forum_reports'),
# Subscription
url('^subscription/topic/(?P<topic_id>\d+)/delete/$', forum_views.delete_subscription, name='forum_delete_subscription'),
url('^subscription/topic/(?P<topic_id>\d+)/add/$', forum_views.add_subscription, name='forum_add_subscription'),

View file

@ -24,7 +24,7 @@ from djangobb_forum.forms import AddPostForm, EditPostForm, UserSearchForm, \
PostSearchForm, ReputationForm, MailToForm, EssentialsProfileForm, \
VotePollForm, ReportForm, VotePollForm, PollForm
from djangobb_forum.models import Category, Forum, Topic, Post, Reputation, \
Attachment, PostTracking
Report, Attachment, PostTracking
from djangobb_forum.templatetags import forum_extras
from djangobb_forum.templatetags.forum_extras import forum_moderated_by
from djangobb_forum.util import build_form, paginate, set_language, smiles, convert_text_to_html
@ -110,6 +110,30 @@ def moderate(request, forum_id):
else:
raise Http404
@transaction.commit_on_success
def reports(request):
if request.user.is_superuser or request.user.has_perm('djangobb_forum.change_report'):
if 'action' in request.GET and request.GET['action'] == 'zap':
for post in request.POST.keys():
if post.startswith('zap_id'):
if request.POST[post] == ' Zap ':
zap_report_id = int(post[7:-1])
zap_report = get_object_or_404(Report, pk=zap_report_id)
zap_report.zapped_by = request.user
zap_report.zapped = True
zap_report.save()
elif request.POST[post] == ' Unzap ':
zap_report_id = int(post[7:-1])
zap_report = get_object_or_404(Report, pk=zap_report_id)
zap_report.zapped_by = None
zap_report.zapped = False
zap_report.save()
new_reports = Report.objects.filter(zapped = False).order_by('-created')
zapped_reports = Report.objects.filter(zapped = True).order_by('-created')[:10]
return render(request, 'djangobb_forum/reports.html', {'new_reports' : new_reports, 'zapped_reports' : zapped_reports})
else:
raise Http404
def search(request):
# TODO: used forms in every search type