A => .hgignore +15 -0
@@ 0,0 1,15 @@
+syntax:glob
+.coverage
+.tox
+settings_local.py
+.*.swp
+**.pyc
+MANIFEST
+.idea
+
+syntax:regexp
+^htmlcov$
+^env$
+syntax: glob
+*.komodoproject
+.DS_Store
No newline at end of file
A => form_guard/__init__.py +0 -0
A => form_guard/admin.py +6 -0
@@ 0,0 1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.contrib import admin
+
+# Register your models here.
A => form_guard/apps.py +8 -0
@@ 0,0 1,8 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.apps import AppConfig
+
+
+class FormGuardConfig(AppConfig):
+ name = 'form_guard'
A => form_guard/forms.py +25 -0
@@ 0,0 1,25 @@
+# -*- coding: utf-8 -*-
+from django import forms
+from django.core.exceptions import PermissionDenied
+
+from .settings import FORM_GUARD_MIN_VALUE
+
+
+class FormGuardForm(forms.Form):
+ antispam_ = forms.CharField(
+ widget=forms.HiddenInput(),
+ initial='default',
+ attrs={'id': 'id_antispam_'})
+ )
+
+ def clean_antispam_(self):
+ antispam = self.cleaned_data.get('antispam')
+ if settings.DEBUG:
+ return antispam
+ try:
+ antispam = int(antispam)
+ except ValueError:
+ raise PermissionDenied
+ if antispam < FORM_GUARD_MIN_VALUE:
+ raise PermissionDenied
+ return antispam
A => form_guard/migrations/__init__.py +0 -0
A => form_guard/models.py +6 -0
@@ 0,0 1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models
+
+# Create your models here.
A => form_guard/settings.py +5 -0
@@ 0,0 1,5 @@
+# -*- coding: utf-8 -*-
+from django.conf import settings
+
+
+FORM_GUARD_MIN_VALUE = getattr(settings, 'FORM_GUARD_MIN_VALUE', 5)
A => form_guard/templates/form_guard/js_snippet.html +16 -0
@@ 0,0 1,16 @@
+<script type="text/javascript">
+ var antiSpam = function() {
+ if (document.getElementById("id_antispam")) {
+ a = document.getElementById("id_antispam");
+ if (isNaN(a.value) == true) {
+ a.value = 0;
+ } else {
+ a.value = parseInt(a.value) + 1;
+ }
+ }
+ setTimeout("antiSpam()", 1000);
+ }
+ $(document).ready(function(){
+ antiSpam();
+ });
+</script>
A => form_guard/tests.py +6 -0
@@ 0,0 1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.test import TestCase
+
+# Create your tests here.
A => form_guard/views.py +6 -0
@@ 0,0 1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.shortcuts import render
+
+# Create your views here.