Add submission reporting

This commit is contained in:
Evert Prants 2017-12-29 16:22:58 +02:00
parent 2afb51ff4b
commit 7481f245fd
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
7 changed files with 149 additions and 3 deletions

View File

@ -185,6 +185,24 @@ class Report(TimestampedModel):
help_text='The URL of the content being reported', help_text='The URL of the content being reported',
verbose_name = 'Content URL' verbose_name = 'Content URL'
) )
read_by = models.ForeignKey(
User,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='reader',
help_text='The administrator that read this report',
verbose_name='Read by'
)
read_at = models.DateTimeField(
null=True,
blank=True,
help_text='The date and time this report was read'
)
resolved = models.BooleanField(
help_text='Whether or not this report has been marked as resolved',
default=False
)
def __str__(self): def __str__(self):
return "%s's report of %s"%(self.reporter, self.url) return "%s's report of %s"%(self.reporter, self.url)

View File

@ -174,6 +174,10 @@ a.episode .submission_cnt {
.submission { .submission {
padding: 10px; padding: 10px;
} }
.submission.highlighted {
background-color: #feffb3 !important;
border: 5px solid #ffbf61;
}
.submission .data { .submission .data {
font-size: 90%; font-size: 90%;
color: #b1b1b1; color: #b1b1b1;
@ -229,6 +233,22 @@ a.episode .submission_cnt {
opacity: 0.5; opacity: 0.5;
user-select: none; user-select: none;
} }
.report-box {
padding: 10px;
margin: 10px 0px;
border: 2px dashed #ddd;
background-color: #fffbdb;
width: 400px;
}
.report-box .submitter {
font-size: 120%;
font-weight: bold;
}
.report-box .url-to {
display: block;
font-size: 90%;
color: #6d6d6d;
}
@media all and (max-width: 800px) { @media all and (max-width: 800px) {
.logo { .logo {
font-size: 5vw !important; font-size: 5vw !important;

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from django import forms from django import forms
from LandingPage.models import Submission, Season, Episode, Ban, User from LandingPage.models import Submission, Season, Episode, Ban, User, Report
class SubmissionForm(forms.ModelForm): class SubmissionForm(forms.ModelForm):
class Meta(): class Meta():
@ -45,3 +45,8 @@ class BanForm(forms.ModelForm):
class Meta(): class Meta():
model = Ban model = Ban
fields = ('reason','expiration','permanent',) fields = ('reason','expiration','permanent',)
class ReportForm(forms.ModelForm):
class Meta():
model = Report
fields = ('title','details',)

View File

@ -57,7 +57,7 @@
<h1>Watch <q>{{episode.name}}</q> From</h1> <h1>Watch <q>{{episode.name}}</q> From</h1>
<div class="submission-list"> <div class="submission-list">
{% for sbm in submissions %} {% for sbm in submissions %}
<div class="submission{% if sbm.positives < sbm.negatives %} buried{% endif %}{% if sbm.pinned %} pinned{% endif %}"> <div class="submission{% if sbm.positives < sbm.negatives %} buried{% endif %}{% if sbm.pinned %} pinned{% endif %}{% if highlight and highlight == sbm.id %} highlighted{% endif %}">
<a href="{{sbm.url}}" class="link"> <a href="{{sbm.url}}" class="link">
{% if sbm.pinned %}<i class="fa fa-fw fa-thumb-tack" title="Pinned submission"></i>{% endif %} {% if sbm.pinned %}<i class="fa fa-fw fa-thumb-tack" title="Pinned submission"></i>{% endif %}
{% if sbm.title %} {% if sbm.title %}
@ -92,7 +92,7 @@
{% if "can_moderate_show" in show_perms %} {% if "can_moderate_show" in show_perms %}
<a href="/show/{{show.abbr}}/submission/{{sbm.id}}/moderate" class="button modbutton"><i class="fa fa-fw fa-shield"></i>&nbsp;Change</a> <a href="/show/{{show.abbr}}/submission/{{sbm.id}}/moderate" class="button modbutton"><i class="fa fa-fw fa-shield"></i>&nbsp;Change</a>
{% else %} {% else %}
<a href="/report?url={{ request.get_full_path|urlencode }}&submission={{ sbm.id }}" class="report">Report Invalid or Spam</a> <a href="/show/{{show.abbr}}/submission/{{sbm.id}}/report" class="report">Report Invalid or Spam</a>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -0,0 +1,54 @@
{% extends "base.html" %}
{% block title %}
Report a Submission - {{show.name}} - Episodes.Community
{% endblock %}
{% block content %}
<section class="show-details">
<div class="banner" style="background-image: url(/media/uploaded_resources/{{show.banner}});"></div>
<div class="banner-cover">
<div class="artwork">
{% if episode.season.artwork %}
<img src="/media/uploaded_resources/{{episode.season.artwork}}">
{% else %}
<img src="/media/uploaded_resources/{{show.artwork}}">
{% endif %}
</div>
<div class="details season">
<h1>{{show.name}}</h1>
{% if episode.season.name %}
<h3>{{ episode.season.name }}</h3>
{% else %}
<h3>Season {{ episode.season.number }}</h3>
{% endif %}
<p class="description">
{% if episode.season.description %}
{{ episode.season.description }}
{% else %}
{{ show.description }}
{% endif %}
</p>
</div>
</div>
</section>
<section class="submissions">
<a href="/show/{{show.abbr}}" class="button"><i class="fa fa-fw fa-home"></i>&nbsp;Show Index</a>
<a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}" class="button">Back to Episode</a>
<h1>Report a Submission</h1>
{% if error %}
<div class="message error">{{error}}</div>
{% endif %}
<form action="" method="post">
<div class="report-box">
<span class="submitter">Submission by {{ submission.user.display_name }}</span>
<span class="url-to">URL: {{ submission.url }}</span>
{% if submission.user.is_staff %}
<div class="message error"><b>Warning</b><br>This submission is made by a staff member.<br>Unnecessary reporters <b>will</b> be banned.</div>
{% endif %}
</div>
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit" />
</form>
</div>
</section>
{% endblock %}

View File

@ -40,6 +40,7 @@ urlpatterns = [
url(r'^season/new$', views.SeasonSubmitForm), url(r'^season/new$', views.SeasonSubmitForm),
url(r'^season/(?P<season>\d{1,4})/append$', views.EpisodeSubmitForm), url(r'^season/(?P<season>\d{1,4})/append$', views.EpisodeSubmitForm),
url(r'^submission/(?P<submission>\d{1,4})/moderate$', views.SubmissionModForm), url(r'^submission/(?P<submission>\d{1,4})/moderate$', views.SubmissionModForm),
url(r'^submission/(?P<submission>\d{1,4})/report$', views.ReportSubmission),
url(r'^episode/(?P<season>\d{1,4})/(?P<episode>\d{1,4})(-[\w-]+)?/?$', views.EpisodeView.as_view()), url(r'^episode/(?P<season>\d{1,4})/(?P<episode>\d{1,4})(-[\w-]+)?/?$', views.EpisodeView.as_view()),
url(r'^episode/(?P<season>\d{1,4})/(?P<episode>\d{1,4})(-[\w-]+)?/submit$', views.SubmissionForm), url(r'^episode/(?P<season>\d{1,4})/(?P<episode>\d{1,4})(-[\w-]+)?/submit$', views.SubmissionForm),
url(r'^vote/(?P<subid>\d+)/(?P<positive>[0-1])/?$', views.SubmissionVoteSubmit.as_view()) url(r'^vote/(?P<subid>\d+)/(?P<positive>[0-1])/?$', views.SubmissionVoteSubmit.as_view())

View File

@ -60,6 +60,10 @@ class EpisodeView(TemplateView):
def get_context_data(self, abbr, season, episode, **kwargs): def get_context_data(self, abbr, season, episode, **kwargs):
ctx = super().get_context_data() ctx = super().get_context_data()
highlight = self.request.GET.get('submission', None)
if not highlight == None:
highlight = int(highlight)
# Get show by abbr # Get show by abbr
show = get_object_or_404(Show, abbr=abbr) show = get_object_or_404(Show, abbr=abbr)
episode = get_object_or_404(Episode, show=show,season__number=season,episode=episode) episode = get_object_or_404(Episode, show=show,season__number=season,episode=episode)
@ -82,6 +86,7 @@ class EpisodeView(TemplateView):
ctx['show'] = show ctx['show'] = show
ctx['episode'] = episode ctx['episode'] = episode
ctx['submissions'] = submissions ctx['submissions'] = submissions
ctx['highlight'] = highlight
return ctx return ctx
@ -353,3 +358,46 @@ def BanFromShowForm(req, abbr):
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
return render(req, "create_ban.html", ctx) return render(req, "create_ban.html", ctx)
@login_required
def ReportSubmission(req, abbr, submission):
show = get_object_or_404(Show, abbr=abbr)
submission = get_object_or_404(Submission, pk=submission,episode__show=show)
episode = submission.episode
user = req.user
form = forms.ReportForm()
# Get bans for this user regarding this show
bans = Ban.objects.filter(Q(expiration__gte=datetime.datetime.now()) | Q(permanent=True), user=user, site_wide=True)
if bans.count() > 0:
return HttpResponseForbidden('You are banned from the site and therefor not allowed to create reports.<br>Reason: %s'%(bans.first().reason))
# Request context
ctx = {
'form': form,
'show': show,
'episode': episode,
'submission': submission
}
# Handle POST
if req.method == 'POST':
form = forms.ReportForm(req.POST)
ctx['form'] = form
if form.is_valid():
form_data = form.cleaned_data
# Save
new_report = form.save(commit=False)
new_report.reporter = user
new_report.url = '/show/%s/episode/%d/%d?submission=%s'%(abbr, episode.season.number, episode.episode,submission.pk)
new_report.save()
return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, episode.season.number, episode.episode))
else:
ctx['error'] = 'Invalid fields!'
return render(req, "report.html", ctx)