Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added admin usability candy

  • Loading branch information...
commit bf7eb0dd6eac9d3264b964b742e1a3a80ee52036 1 parent 9e5c20f
@maccesch authored
View
1  .gitignore
@@ -4,3 +4,4 @@ DS_STORE
*~
.project
.pydevproject
+.settings
View
8 README.rst
@@ -2,7 +2,7 @@
Django CMS Contact Form Plugin
==============================
-Contact form plugin for `Django CMS <http://www.django-cms.org/>` with spam protection and i18n.
+Contact form plugin for `Django CMS <http://www.django-cms.org/>`_ with spam protection and i18n.
If you want to use ReCAPTCHA you have to get a Public and Private Key from http://www.google.com/recaptcha. You can get them for free.
@@ -16,7 +16,7 @@ Dependencies
Django Apps
-----------
-`glamkit-stopspam <http://github.com/maccesch/glamkit-stopspam>` provides nice spam protection support.
+`glamkit-stopspam <http://github.com/maccesch/glamkit-stopspam>`_ provides nice spam protection support.
Python Libs
-----------
@@ -27,8 +27,8 @@ If you use Akismet for spam protection "akismet" is needed.
Both libraries can be installed by ``easy_install`` or ``pip``.
-Install
-=======
+Installation
+============
Type ``python setup.py install`` in your terminal.
View
80 cmsplugin_contact/admin.py
@@ -0,0 +1,80 @@
+from django.forms import ModelForm, Field, CharField
+from django.forms.util import ErrorList
+from django.core.exceptions import ValidationError
+from django.contrib.sites.models import Site
+from django.conf import settings
+from django.utils.translation import ugettext_lazy as _
+
+from models import Contact
+
+class KeyField(CharField):
+ def validate(self, value):
+ # valdates always. validation is done in the form (see below)
+ pass
+
+class ContactAdminForm(ModelForm):
+ akismet_api_key = KeyField(max_length=255, label=_("Akismet API Key"), help_text=_('Get a Wordpress Key from http://akismet.com/'))
+
+ recaptcha_public_key = KeyField(max_length=255, label=_("ReCAPTCHA Public Key"), help_text=_('Get this from http://www.google.com/recaptcha'))
+ recaptcha_private_key = KeyField(max_length=255, label=_("ReCAPTCHA Private Key"), help_text=_('Get this from http://www.google.com/recaptcha'))
+
+ class Meta:
+ model = Contact
+
+
+ def _add_error(self, field_name, error):
+ if not field_name in self._errors:
+ self._errors[field_name] = ErrorList()
+ self._errors[field_name].append(error)
+
+ def _check_akismet(self):
+ def add_error(error):
+ self._add_error('akismet_api_key', error)
+
+ try:
+ from akismet import Akismet
+ except ImportError:
+ self._add_error('spam_protection_method', _('Akismet library is not installed. Use "easy_install akismet" or "pip install akismet".'))
+
+ api_key = self.cleaned_data['akismet_api_key']
+ if not api_key:
+ add_error(Field.default_error_messages['required'])
+ else:
+ ak = Akismet(
+ key = api_key,
+ blog_url = 'http://%s/' % Site.objects.get(pk=settings.SITE_ID).domain
+ )
+ if not ak.verify_key():
+ add_error(_('The API Key is not valid.'))
+
+
+ def _check_recaptcha(self):
+
+ try:
+ from recaptcha.client import captcha as recaptcha
+ except ImportError:
+ self._add_error('spam_protection_method', _('ReCAPTCHA library is not installed. Use "easy_install recaptcha-client" or "pip install recaptcha-client".'))
+
+ public_key = self.cleaned_data['recaptcha_public_key']
+ private_key = self.cleaned_data['recaptcha_private_key']
+
+ if not public_key:
+ self._add_error('recaptcha_public_key', Field.default_error_messages['required'])
+ if not private_key:
+ self._add_error('recaptcha_private_key', Field.default_error_messages['required'])
+
+
+ def clean(self):
+
+ method = self.cleaned_data['spam_protection_method']
+ print "huhu"
+ if method == 1:
+ # user chose aksimet => akismet api key is required
+ self._check_akismet()
+ elif method == 2:
+ # user chose recaptcha => recaptcha keys are required
+ self._check_recaptcha()
+
+ return self.cleaned_data
+
+
View
21 cmsplugin_contact/cms_plugins.py
@@ -5,11 +5,24 @@
from models import Contact
from forms import AkismetContactForm, RecaptchaContactForm, HoneyPotContactForm
from django.core.mail import EmailMessage
+from admin import ContactAdminForm
class ContactPlugin(CMSPluginBase):
model = Contact
name = _("Contact Form")
render_template = "cmsplugin_contact/contact.html"
+ form = ContactAdminForm
+
+ fieldsets = (
+ (None, {
+ 'fields': ('site_email', 'email_label', 'subject_label', 'content_label', 'thanks', 'submit'),
+ }),
+ (_('Spam Protection'), {
+ 'fields': ('spam_protection_method', 'akismet_api_key', 'recaptcha_public_key', 'recaptcha_private_key', 'recaptcha_theme')
+ })
+ )
+
+ change_form_template = "cmsplugin_contact/admin/plugin_change_form.html"
def create_form(self, instance, request):
if instance.get_spam_protection_method_display() == 'Akismet':
@@ -62,5 +75,13 @@ def render(self, context, instance, placeholder):
})
return context
+
+ def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
+ context.update({
+ 'spam_protection_method': obj.spam_protection_method if obj else 0
+ })
+
+ return super(ContactPlugin, self).render_change_form(request, context, add, change, form_url, obj)
+
plugin_pool.register_plugin(ContactPlugin)
View
BIN  cmsplugin_contact/locale/de/LC_MESSAGES/django.mo
Binary file not shown
View
112 cmsplugin_contact/locale/de/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-08-31 02:33+0200\n"
+"POT-Creation-Date: 2010-09-01 18:46+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,65 +17,125 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
-#: cms_plugins.py:11
+#: admin.py:16
+msgid "Akismet API Key"
+msgstr ""
+
+#: admin.py:16
+msgid "Get a Wordpress Key from http://akismet.com/"
+msgstr "Wordpress Key von http://akismet.com/"
+
+#: admin.py:18
+msgid "ReCAPTCHA Public Key"
+msgstr ""
+
+#: admin.py:18 admin.py:19
+msgid "Get this from http://www.google.com/recaptcha"
+msgstr "Erhältlich von http://www.google.com/recaptcha"
+
+#: admin.py:19
+msgid "ReCAPTCHA Private Key"
+msgstr ""
+
+#: admin.py:37
+msgid ""
+"Akismet library is not installed. Use \"easy_install akismet\" or \"pip "
+"install akismet\"."
+msgstr ""
+"Die Akismet Bibliothek ist nicht installiert. Zum installieren: "
+"\"easy_install akismet\" oder \"pip install akismet\""
+
+#: admin.py:48
+msgid "The API Key is not valid."
+msgstr "Der API Key ist ungültig."
+
+#: admin.py:56
+msgid ""
+"ReCAPTCHA library is not installed. Use \"easy_install recaptcha-client\" or "
+"\"pip install recaptcha-client\"."
+msgstr ""
+"Die ReCAPTCHA Bibliothek ist nicht installiert. Zum installieren: "
+"\"easy_install recaptcha-client\" oder \"pip install recaptcha-client\""
+
+#: cms_plugins.py:12
msgid "Contact Form"
msgstr "Kontaktformular"
-#: cms_plugins.py:35
+#: cms_plugins.py:20
+msgid "Spam Protection"
+msgstr "Spamschutz"
+
+#: cms_plugins.py:48
msgid "No subject"
msgstr "Kein Betreff"
#: models.py:20
-msgid "Email Recipient"
-msgstr "EMail Empf&auml;nger"
+msgid "Email recipient"
+msgstr "E-Mail Empfänger"
+
+#: models.py:21
+msgid "Email sender label"
+msgstr "E-Mail Absender Beschriftung"
#: models.py:21
-msgid "Email Sender Label"
-msgstr "EMail Sender Label"
+msgid "Your email address"
+msgstr "Ihre E-Mail Adresse"
#: models.py:22
-msgid "Subject Label"
-msgstr "Betreff Label"
+msgid "Subject label"
+msgstr "Betreff Beschriftung"
+
+#: models.py:22
+msgid "Subject"
+msgstr "Betreff"
#: models.py:23
-msgid "Message Content Label"
-msgstr "EMail Inhalt Label"
+msgid "Message content label"
+msgstr "Nachrichteninhalt Beschriftung"
+
+#: models.py:23
+msgid "Message"
+msgstr "Nachricht"
#: models.py:24
-msgid "Thanks Message"
+msgid "Thanks message"
msgstr "Dankesnachricht"
#: models.py:24
msgid "Message displayed on successful submit"
-msgstr "Benachrichtigung bei erfolgreichem Senden."
+msgstr "Nachricht nach erfolgreichem Absenden"
+
+#: models.py:24
+msgid "Thank you for your message."
+msgstr "Vielen Dank für Ihre Nachricht."
#: models.py:25
-msgid "Submit Button Value"
+msgid "Submit button value"
msgstr "Senden Button Beschriftung"
-#: models.py:27
-msgid "Method to protect your site from spam"
-msgstr "Spamschutz Methode"
+#: models.py:25
+msgid "Submit"
+msgstr "Senden"
-#: models.py:29
-msgid "Only if you are using Akismet spam protection."
-msgstr "Nur wenn Sie den Akismet Spamschutz verwenden."
+#: models.py:27
+msgid "Spam protection method"
+msgstr "Spamschutzmethode"
-#: models.py:31 models.py:32 models.py:33
-msgid "Only if you are using ReCAPTCHA spam protection."
-msgstr "Nur wenn Sie den ReCAPTCHA Spamschutz verwenden."
+#: models.py:33
+msgid "ReCAPTCHA theme"
+msgstr "ReCAPTCHA Theme"
#: templates/cmsplugin_contact/contact.html:40
msgid "Incorrect please try again"
-msgstr "Nicht korrekt. Bitte versuchen Sie es erneut."
+msgstr "Eingabe nicht korrekt, bitte erneut versuchen"
#: templates/cmsplugin_contact/contact.html:43
msgid "Enter the words above:"
-msgstr "Bitte geben Sie die obigen W&ouml;rter ein:"
+msgstr "Obige Wörter eingeben:"
#: templates/cmsplugin_contact/contact.html:44
msgid "Enter the numbers you hear:"
-msgstr "Bitte geben Sie die Zahlen ein, die Sie h&ouml;ren."
+msgstr "Die gehörten Zahlen eingeben:"
#: templates/cmsplugin_contact/contact.html:49
msgid "Get another CAPTCHA"
View
22 cmsplugin_contact/models.py
@@ -17,20 +17,20 @@ class Contact(CMSPlugin):
('custom', 'Custom'),
)
- site_email = models.EmailField(_('Email Recipient'))
- email_label = models.CharField(_('Email Sender Label'), blank=True, max_length=100)
- subject_label = models.CharField(_('Subject Label'), blank=True, max_length=200)
- content_label = models.CharField(_('Message Content Label'), blank=True, max_length=100)
- thanks = models.CharField(verbose_name=_("Thanks Message"), help_text=_('Message displayed on successful submit'), max_length=200)
- submit = models.CharField(_('Submit Button Value'), blank=True, max_length=30)
+ site_email = models.EmailField(_('Email recipient'))
+ email_label = models.CharField(_('Email sender label'), default=_('Your email address'), max_length=100)
+ subject_label = models.CharField(_('Subject label'), default=_('Subject'), max_length=200)
+ content_label = models.CharField(_('Message content label'), default=_('Message'), max_length=100)
+ thanks = models.CharField(verbose_name=_("Thanks message"), help_text=_('Message displayed on successful submit'), default=_('Thank you for your message.'), max_length=200)
+ submit = models.CharField(_('Submit button value'), default=_('Submit'), max_length=30)
- spam_protection_method = models.SmallIntegerField(help_text=_('Method to protect your site from spam'), choices=SPAM_PROTECTION_CHOICES)
+ spam_protection_method = models.SmallIntegerField(verbose_name=_('Spam protection method'), choices=SPAM_PROTECTION_CHOICES, default=0)
- akismet_api_key = models.CharField(help_text=_('Only if you are using Akismet spam protection.'), verbose_name="Akismet API Key", max_length=255, blank=True)
+ akismet_api_key = models.CharField(max_length=255, blank=True)
- recaptcha_public_key = models.CharField(help_text=_('Only if you are using ReCAPTCHA spam protection.'), verbose_name="ReCAPTCHA Public Key", max_length=255, blank=True)
- recaptcha_private_key = models.CharField(help_text=_('Only if you are using ReCAPTCHA spam protection.'), verbose_name="ReCAPTCHA Private Key", max_length=255, blank=True)
- recaptcha_theme = models.CharField(max_length=20, choices=THEME_CHOICES, default='clean', help_text=_('Only if you are using ReCAPTCHA spam protection.'))
+ recaptcha_public_key = models.CharField(max_length=255, blank=True)
+ recaptcha_private_key = models.CharField(max_length=255, blank=True)
+ recaptcha_theme = models.CharField(max_length=20, choices=THEME_CHOICES, default='clean', verbose_name=_('ReCAPTCHA theme'))
def __unicode__(self):
return self.site_email
View
64 cmsplugin_contact/templates/cmsplugin_contact/admin/plugin_change_form.html
@@ -0,0 +1,64 @@
+{% extends "admin/cms/page/plugin_change_form.html" %}
+
+{% block extrahead %}{{ block.super }}
+<script type="text/javascript">
+//<![CDATA[
+(function($) {
+ function updateVisibility(class_prefix) {
+ $('div.spam_protection_method').parent().children('.form-row').each(function(index, row) {
+ var visible = false;
+ $.each($(row).attr('class').split(/\s+/), function(index, class) {
+ if (class == 'spam_protection_method' || class.indexOf(class_prefix) >= 0) {
+ visible = true;
+ }
+ });
+ if (visible) {
+ $(row).css('display', 'block');
+ } else {
+ $(row).css('display', 'none');
+ }
+ });
+ }
+
+ $(document).ready(function(){
+
+ $('#id_spam_protection_method').change(function() {
+ var curOption = $('#id_spam_protection_method :selected');
+ updateVisibility(curOption.html().toLowerCase());
+ });
+ });
+})(jQuery);
+//]]>
+</script>
+
+{% endblock extrahead %}
+
+{% block extrastyle %}{{ block.super }}
+<style type="text/css">
+ div.form-row label {
+ width: 14em;
+ }
+ form .aligned p.help {
+ padding-left: 48px;
+ margin-left: 13em;
+ }
+
+ {% if spam_protection_method != 1 %}
+ div.form-row.akismet_api_key {
+ display: none;
+ }
+ {% endif %}
+
+ {% if spam_protection_method != 2 %}
+ div.form-row.recaptcha_public_key {
+ display: none;
+ }
+ div.form-row.recaptcha_private_key {
+ display: none;
+ }
+ div.form-row.recaptcha_theme {
+ display: none;
+ }
+ {% endif %}
+</style>
+{% endblock extrastyle %}
Please sign in to comment.
Something went wrong with that request. Please try again.