# HG changeset patch # User Peter Sanchez # Date 1504044739 25200 # Tue Aug 29 15:12:19 2017 -0700 # Node ID 41fa72a22d19fec0063f81e572420e0d318d94a0 # Parent 0000000000000000000000000000000000000000 Initial commit diff --git a/.hgignore b/.hgignore new file mode 100644 --- /dev/null +++ b/.hgignore @@ -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 diff --git a/form_guard/__init__.py b/form_guard/__init__.py new file mode 100644 diff --git a/form_guard/admin.py b/form_guard/admin.py new file mode 100644 --- /dev/null +++ b/form_guard/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/form_guard/apps.py b/form_guard/apps.py new file mode 100644 --- /dev/null +++ b/form_guard/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class FormGuardConfig(AppConfig): + name = 'form_guard' diff --git a/form_guard/forms.py b/form_guard/forms.py new file mode 100644 --- /dev/null +++ b/form_guard/forms.py @@ -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 diff --git a/form_guard/migrations/__init__.py b/form_guard/migrations/__init__.py new file mode 100644 diff --git a/form_guard/models.py b/form_guard/models.py new file mode 100644 --- /dev/null +++ b/form_guard/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/form_guard/settings.py b/form_guard/settings.py new file mode 100644 --- /dev/null +++ b/form_guard/settings.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +from django.conf import settings + + +FORM_GUARD_MIN_VALUE = getattr(settings, 'FORM_GUARD_MIN_VALUE', 5) diff --git a/form_guard/templates/form_guard/js_snippet.html b/form_guard/templates/form_guard/js_snippet.html new file mode 100644 --- /dev/null +++ b/form_guard/templates/form_guard/js_snippet.html @@ -0,0 +1,16 @@ + diff --git a/form_guard/tests.py b/form_guard/tests.py new file mode 100644 --- /dev/null +++ b/form_guard/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/form_guard/views.py b/form_guard/views.py new file mode 100644 --- /dev/null +++ b/form_guard/views.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here.