Commit 2b47da31 authored by okhin's avatar okhin

Merge branch 'nospam_comments' into 'master'

Adding a captchas to the comment form



See merge request !35
parents ce19fb6b 25bc8280
...@@ -131,6 +131,8 @@ INSTALLED_APPS = ( ...@@ -131,6 +131,8 @@ INSTALLED_APPS = (
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_comments', 'django_comments',
# Reduce the spam in comments
'spamlesscomment',
'tinymce', 'tinymce',
'bt', 'bt',
'captcha', 'captcha',
...@@ -149,6 +151,7 @@ INSTALLED_APPS = ( ...@@ -149,6 +151,7 @@ INSTALLED_APPS = (
'bootstrap3', 'bootstrap3',
) )
COMMENTS_APP = 'spamlesscomment'
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth", TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug", "django.core.context_processors.debug",
"django.core.context_processors.i18n", "django.core.context_processors.i18n",
......
...@@ -741,6 +741,8 @@ input[type="text"], input[type="textarea"] { ...@@ -741,6 +741,8 @@ input[type="text"], input[type="textarea"] {
clear: both; clear: both;
} }
div.honeypot {display: none;}
@media screen and (max-width: 700px) { @media screen and (max-width: 700px) {
h1{font-size:30px} h1{font-size:30px}
h2{font-size:24px} h2{font-size:24px}
...@@ -763,3 +765,4 @@ input[type="text"], input[type="textarea"] { ...@@ -763,3 +765,4 @@ input[type="text"], input[type="textarea"] {
width:100px; width:100px;
} }
} }
...@@ -130,13 +130,13 @@ $("#btn_dismiss").click(function(event) { ...@@ -130,13 +130,13 @@ $("#btn_dismiss").click(function(event) {
<div class="well collapse" id="info-{{ violation.pk }}"> <div class="well collapse" id="info-{{ violation.pk }}">
<form method="post" class="metoo" action="/confirm/{{ violation.pk }}" id="{{ violation.pk }}"> <form method="post" class="metoo" action="/confirm/{{ violation.pk }}" id="{{ violation.pk }}">
<div class="form-group form-inline"> <div class="form-group form-inline">
<label for"email-{{ violation.pk }}">{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label> <label for="email-{{ violation.pk }}">{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
{% csrf_token %} {% csrf_token %}
<input type="email" id="email-{{ violation.pk }}" class="form-control" name="email" placeholder="Email"/> <input type="email" id="email-{{ violation.pk }}" class="form-control" name="email" placeholder="Email"/>
<input type="hidden" id="id-{{ violation.pk }}" value="{{ violation.pk }}" /> <input type="hidden" id="id-{{ violation.pk }}" value="{{ violation.pk }}" />
<div class="btn-group" role="group" aria-label="confirm-deny"> <div class="btn-group" role="group" aria-label="confirm-deny">
<button class="btn btn-success">{% trans "OK" %}</ button> <button class="btn btn-success">{% trans "OK" %}</ button>
<button data-toggle="collapse" data-target="#info-{{ violation.pk}}" aria-expanded="false" aria-controls="info-{{ volation.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button> <button data-toggle="collapse" data-target="#info-{{ violation.pk}}" aria-expanded="false" aria-controls="info-{{ volation.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button>
</div> </div>
</div> </div>
</form> </form>
......
...@@ -11,129 +11,120 @@ ...@@ -11,129 +11,120 @@
{% block scripts %} {% block scripts %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script> <script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
function bindPostCommentHandler() {
$('.toggle').click(function(){
$(this).hide();
$(this).next().show();
});
$('#comment_form form input.submit-preview').remove();
$('#comment_form form').submit(function() {
var postdata=$('#comment_form form').serialize()+'&csrftoken={{csrf_token}}';
$.ajax({
type: "POST",
data: postdata,
url: "{% comment_form_target %}",
cache: false,
dataType: "html",
success: function(html, textStatus) {
$('#comment_form form').replaceWith(html+" "+"{% trans 'It will appear here after moderation.' %}");
bindPostCommentHandler();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$('#comment_form form').replaceWith("{% trans 'Your comment was unable to be posted at this time. We apologise for the inconvenience.' %}");
}
});
return false;
});
}
$(document).ready(function() { $(document).ready(function() {
bindPostCommentHandler(); $('.metoo').submit(function(event) {
$('.confirm_form').submit(function() { event.preventDefault();
var self=this; var form = $(this);
var email=$(this).children('input:first').attr('value'); var pk = $(form).attr("id")
if( email.length>0) { var email = $(form).find("#email-" + pk).val();
$.ajax({url: '/confirm/'+$(this).attr('id')+'/'+email, success: function(data) { $(self).html(data); }});
} else { $.ajax({
console.log($(this).find('[type=submit]')); url: "/confirm/" + pk + "/" + email,
$(this).find('[type=text]').focus(); success: function(data) {
} form.find("div").html(data);
return false; }
}); });
$('span').hover(function(){$('span#'+this.id+'_tooltip').fadeIn();}, function(){$('span#'+this.id+'_tooltip').hide();}); });
}); });
</script> </script>
{% endblock %} {% endblock %}
{%block content%} {%block content%}
<div id='global'> <div id='global'>
<h2>{{v.operator}} ({{v.country}}) {{v.contract}}</h2> <h2>{{v.operator}} ({{v.country}}) {{v.contract}}</h2>
<div id="report"> <div id="report">
<div id="icons"> <div id="icons">
<span id="verified_tooltip" class="tooltip">{% trans "This case was verified by the management team" %}</span> <span id="verified_tooltip" class="tooltip">{% trans "This case was verified by the management team" %}</span>
<span class="tooltip_on">{%if v.confirmations == 0 %} {% trans "Nobody has yet confirmed the case. Feel free to do it" %} {%else%} {{v.confirmations}} {%if v.confirmations == 1 %} {% trans "person has confirmed this case" %} {%else%} {% trans "persons have confirmed this case" %} {%endif%} {%endif%}</span> <span class="tooltip_on">{%if v.confirmations == 0 %} {% trans "Nobody has yet confirmed the case. Feel free to do it" %} {%else%} {{v.confirmations}} {%if v.confirmations == 1 %} {% trans "person has confirmed this case" %} {%else%} {% trans "people have confirmed this case" %} {%endif%} {%endif%}</span>
{% if v.state == 'verified' %}<span id="verified"></span> |{% endif %} {% if v.state == 'verified' %}<span id="verified"></span> |{% endif %}
<span id="confirmations">{{v.confirmations}}</span> | <span id="confirmations">{{v.confirmations}}</span> |
</div> </div>
<dl>{%if v.resource_name%}<dt>{% trans "Affected resource" %}</dt><dd>{{v.resource_name}}</dd>{%endif%} <dl>{%if v.resource_name%}<dt>{% trans "Affected resource" %}</dt><dd>{{v.resource_name}}</dd>{%endif%}
{%if v.type%}<dt>{% trans "Type" %}</dt><dd>{{v.type|type}}</dd>{%endif%} {%if v.type%}<dt>{% trans "Type" %}</dt><dd>{{v.type|type}}</dd>{%endif%}
{%if v.media%}<dt>{% trans "Media" %}</dt><dd>{{v.media|media}}</dd>{%endif%} {%if v.media%}<dt>{% trans "Media" %}</dt><dd>{{v.media|media}}</dd>{%endif%}
{%if v.state%}<dt>{% trans "Status" %}</dt><dd>{{v.state|status}}</dd>{%endif%} {%if v.state%}<dt>{% trans "Status" %}</dt><dd>{{v.state|status}}</dd>{%endif%}
{%if v.temporary%}<dt>{% trans "Temporary restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%} {%if v.temporary%}<dt>{% trans "Temporary restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.loophole%}<dt>{% trans "Another offer provided by the same operator removes this restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%} {%if v.loophole%}<dt>{% trans "Another offer provided by the same operator removes this restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.contractual%}<dt>{% trans "Contractual restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%} {%if v.contractual%}<dt>{% trans "Contractual restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.contract_excerpt%}<dt>{% trans "Contract excerpt" %}</dt><dd class='text'>{{v.contract_excerpt|safe}}</dd>{%endif%} {%if v.contract_excerpt%}<dt>{% trans "Contract excerpt" %}</dt><dd class='text'>{{v.contract_excerpt|safe}}</dd>{%endif%}
{%if v.comment_set.all%}</dl> {%if v.comment_set.all%}</dl>
</div> </div>
{% if v.editorial %} {% if v.editorial %}
<div id="editorial" class='round-box'> <div id="editorial" class='round-box'>
<h3>{% trans "RespectMyNet note" %}</h3> <h3>{% trans "RespectMyNet note" %}</h3>
{{v.editorial|safe}} {{v.editorial|safe}}
</div> </div>
{% endif %} {% endif %}
<div id="description" class='round-box'> <div id="description" class='round-box'>
<h3>{%trans "Description" %}</h3> <h3>{%trans "Description" %}</h3>
{%for c in v.comment_set.all%} {%for c in v.comment_set.all%}
<div class="description-node"> <div class="description-node">
{%if c.attachment_set.all%} {%if c.attachment_set.all%}
<div class="attachs"> <div class="attachs">
<h4>{% trans "Attachments" %}</h4> <h4>{% trans "Attachments" %}</h4>
<ul> <ul>
{%for a in c.attachment_set.all%} {%for a in c.attachment_set.all%}
<li><a href="{% url 'attach' a.id %}">{{a.name}}</a></li> <li><a href="{% url 'attach' a.id %}">{{a.name}}</a></li>
{%endfor%} {%endfor%}
</ul> </ul>
</div> </div>
{%endif%} {%endif%}
<div class="description">{{c.comment|safe}}</div> <div class="description">{{c.comment|safe}}</div>
<span class="submitter">{%if c.submitter_name%}{{c.submitter_name}}{%else%}{{c.submitter_email}}{%endif%}</span> - <span class="comment_date">{{c.timestamp|date:"SHORT_DATE_FORMAT" }}</span> <span class="submitter">{%if c.submitter_name%}{{c.submitter_name}}{%else%}{{c.submitter_email}}{%endif%}</span> - <span class="comment_date">{{c.timestamp|date:"SHORT_DATE_FORMAT" }}</span>
</div> </div>
{%endfor%} {%endfor%}
</div> </div>
<h3>{%trans "This restriction affects me too" %}</h3> <div>
<div class="info-validate" style="display: inline-block;"> <button type="button" class="btn btn-link" data-toggle="collapse" data-target="#info-{{ v.pk }}">
<form method="get" id="{{ v.pk }}" class="confirm_form" > <h3>{%trans "This restriction affects me too" %}</h3>
<label>{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label> </button>
<input type="text" name="email" /> </div>
<input type="hidden" value="{{ v.pk }}" /> <div class="well collapse" id="info-{{ v.pk }}">
<input type="submit" value="{% trans "Me too!" %}" /> <form method="post" id="{{ v.pk }}" class="metoo" action="/confirm/{{ v.pk }}">
</form> <div class="form-group">
</div> <label for="email-{{ v.pk }}">{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
{%endif%} {% csrf_token %}
{% if not key %} <input type="email" id="email-{{ v.pk }}" name="email" placeholder="Email" />
<div id="comments"> <input type="hidden" id="id-{{ v.pk }}" value="{{ v.pk }}" />
<h3>{% trans "Comments" %}</h3> </div>
{% get_comment_list for v as cmt_list %} <div class="btn-group" role="group" aria-label="confirm-deny">
{% for comment in cmt_list %} <button class="btn btn-success">{% trans "OK" %}</button>
<div class="comment"> <button data-toggle="collapse" data-target="#info-{{ v.pk}}" aria-expanded="false" aria-controls="info-{{ v.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button>
<p>{{ comment.user_name }} - {{ comment.submit_date }}</p> </div>
<p>{{ comment.comment|striptags|urlize|linebreaks }}</p> </form>
</div> </div>
{% endfor %} {%endif%}
<div class="toggle button">{% trans "Add comment" %}</div> {% if not key %}
<div id="comment_form" style="display: none;"> <div class="panel panel-default">
{% render_comment_form for v %} <div class="panel-heading">
</div> <h1 class="panel-title">{% trans "Comments" %}</h1>
{% else %} </div>
<br /> {% get_comment_list for v as cmt_list %}
<a class="button" href='/moderate/?key={{key}}&action=approve'>{% trans "Approve Submission" %}</a> <div class="panel-body">
<a class="button" href='/moderate/?key={{key}}&action=delete'>{% trans "Delete Submission" %}</a> <ul class="list-group">
</div> {% for comment in cmt_list %}
{% endif %} <li class="list-group-item">
</div> <p>{{ comment.user_name }} - {{ comment.submit_date }}</p>
<p>{{ comment.comment|striptags|urlize|linebreaks }}</p>
</li>
{% endfor %}
</ul>
</div>
<div class="panel-footer">
<div id="comment_form">
{% render_comment_form for v %}
</div>
</div>
{% else %}
<br />
<a class="btn btn-success" href='/moderate/?key={{key}}&action=approve'>{% trans "Approve Submission" %}</a>
<a class="btn btn-error" href='/moderate/?key={{key}}&action=delete'>{% trans "Delete Submission" %}</a>
</div>
{% endif %}
</div>
{%endblock%} {%endblock%}
from spamlesscomment.forms import CommentFormWithCaptcha
def get_form():
return CommentFormWithCaptcha
from django.contrib import admin
# Register your models here.
from django import forms
from django_comments.forms import CommentForm
from django_comments.models import Comment
from django.utils.translation import ugettext_lazy as _
from captcha.fields import CaptchaField
class CommentFormWithCaptcha(CommentForm):
captcha = CaptchaField(label=_("In order to protect against spam, please fill in the result of the following calculation. (note the + and the * are somewhat confusing)"))
def get_comment_model(self):
return Comment
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment