diff --git a/README.rst b/README.rst index 5d81995..36a4f99 100644 --- a/README.rst +++ b/README.rst @@ -19,7 +19,7 @@ user to fill. {% include "feedback/header.html" %} - + {% include "feedback/button.html" %} @@ -28,7 +28,7 @@ user to fill. {% include "feedback/feedback.html" %}
- + + All feedback can be seen in the Django admin interface @@ -37,3 +37,10 @@ user to fill. + Feedback can optionally be emailed to you as well, as it is submitted. Specify your email address in settings.py: FEEDBACK_EMAIL = "me@example.com" + ++ Feedback can be protected with a simple text captcha by adding the following to your settings.py file:: + + FEEDBACK_CAPTCHAS = [ + (_("question1"), ["answer1"]), + (_("question2"), ["answer2", "alternative ansnwer 2"]), + ] diff --git a/feedback/forms.py b/feedback/forms.py index c267520..4f6e3ff 100644 --- a/feedback/forms.py +++ b/feedback/forms.py @@ -1,11 +1,26 @@ #!/usr/bin/env python from django import forms +from django.conf import settings from django.contrib.sites.models import Site +from django.utils.translation import ugettext_lazy as _ from feedback.models import Feedback class FeedbackForm(forms.ModelForm): '''The form shown when giving feedback''' + def __init__(self, *args, **kwargs): + super(FeedbackForm, self).__init__(*args, **kwargs) + self.captchas = getattr(settings, 'FEEDBACK_CAPTCHAS', {}) + if self.captchas: + self.fields['captchaquestion'] = forms.CharField() + self.fields['captcha'] = forms.CharField() + + def clean_captcha(self): + for question, answers in self.captchas: + if self.cleaned_data['captchaquestion'] == question and self.cleaned_data['captcha'] in answers: + return self.cleaned_data['captcha'] + raise forms.ValidationError(_("Captcha incorrect")) + class Meta: model = Feedback fields = "__all__" diff --git a/feedback/locale/cs/LC_MESSAGES/django.mo b/feedback/locale/cs/LC_MESSAGES/django.mo index 7c6bd94..ee59880 100644 Binary files a/feedback/locale/cs/LC_MESSAGES/django.mo and b/feedback/locale/cs/LC_MESSAGES/django.mo differ diff --git a/feedback/locale/cs/LC_MESSAGES/django.po b/feedback/locale/cs/LC_MESSAGES/django.po index 057b351..e88e519 100644 --- a/feedback/locale/cs/LC_MESSAGES/django.po +++ b/feedback/locale/cs/LC_MESSAGES/django.po @@ -18,6 +18,9 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" +msgid "Captcha incorrect" +msgstr "Nesprávná captcha" + #: models.py:7 msgid "site" msgstr "stránka" diff --git a/feedback/templates/feedback/captcha.html b/feedback/templates/feedback/captcha.html new file mode 100644 index 0000000..c27bd99 --- /dev/null +++ b/feedback/templates/feedback/captcha.html @@ -0,0 +1,6 @@ +{% if question %} +
+ + + +{% endif %} diff --git a/feedback/templates/feedback/feedback.html b/feedback/templates/feedback/feedback.html index 7cf3bf9..e2d1482 100644 --- a/feedback/templates/feedback/feedback.html +++ b/feedback/templates/feedback/feedback.html @@ -1,4 +1,5 @@ {% load i18n %} +{% load captcha %}