From 2dd360e5e7cc6dd024d3fd0b82d401b7273258f7 Mon Sep 17 00:00:00 2001 From: zhengxie Date: Tue, 5 Aug 2014 14:41:04 +0800 Subject: [PATCH] Update captcha --- thirdpart/captcha/__init__.py | 6 +- thirdpart/captcha/conf/settings.py | 5 +- thirdpart/captcha/fields.py | 13 ++--- thirdpart/captcha/helpers.py | 9 ++- .../captcha/locale/bg/LC_MESSAGES/django.po | 31 +++++++++++ .../captcha/locale/cs/LC_MESSAGES/django.po | 2 +- .../captcha/locale/de/LC_MESSAGES/django.po | 1 + .../captcha/locale/es/LC_MESSAGES/django.po | 32 +++++++++++ .../captcha/locale/fr/LC_MESSAGES/django.po | 5 +- .../captcha/locale/it/LC_MESSAGES/django.po | 3 +- .../captcha/locale/ja/LC_MESSAGES/django.po | 31 +++++++++++ .../captcha/locale/nl/LC_MESSAGES/django.po | 5 +- .../captcha/locale/pl/LC_MESSAGES/django.po | 5 +- .../locale/pt_BR/LC_MESSAGES/django.po | 4 +- .../captcha/locale/ru/LC_MESSAGES/django.po | 11 ++-- .../captcha/locale/sk/LC_MESSAGES/django.po | 32 +++++++++++ .../captcha/locale/tr/LC_MESSAGES/django.po | 4 +- .../captcha/locale/uk/LC_MESSAGES/django.po | 32 +++++++++++ .../locale/zh_CN/LC_MESSAGES/django.po | 6 +- .../management/commands/captcha_clean.py | 8 +-- thirdpart/captcha/migrations/0001_initial.py | 55 +++++++------------ thirdpart/captcha/migrations/__init__.py | 21 +++++++ thirdpart/captcha/models.py | 3 +- .../captcha/south_migrations/0001_initial.py | 39 +++++++++++++ .../captcha/south_migrations/__init__.py | 0 thirdpart/captcha/tests/__init__.py | 2 +- thirdpart/captcha/tests/tests.py | 35 +++++++++--- thirdpart/captcha/tests/urls.py | 3 +- thirdpart/captcha/tests/views.py | 9 ++- thirdpart/captcha/urls.py | 3 +- thirdpart/captcha/views.py | 24 ++++++-- 31 files changed, 339 insertions(+), 100 deletions(-) create mode 100644 thirdpart/captcha/locale/bg/LC_MESSAGES/django.po create mode 100644 thirdpart/captcha/locale/es/LC_MESSAGES/django.po create mode 100644 thirdpart/captcha/locale/ja/LC_MESSAGES/django.po create mode 100644 thirdpart/captcha/locale/sk/LC_MESSAGES/django.po create mode 100644 thirdpart/captcha/locale/uk/LC_MESSAGES/django.po create mode 100644 thirdpart/captcha/south_migrations/0001_initial.py create mode 100644 thirdpart/captcha/south_migrations/__init__.py diff --git a/thirdpart/captcha/__init__.py b/thirdpart/captcha/__init__.py index 01ecc45967..bdcf76dbed 100644 --- a/thirdpart/captcha/__init__.py +++ b/thirdpart/captcha/__init__.py @@ -1,6 +1,6 @@ import re -VERSION = (0, 4, 0) +VERSION = (0, 4, 3) def get_version(svn=False): @@ -20,8 +20,8 @@ def pillow_required(): except ImportError: try: import Image - import ImageDraw - import ImageFont + import ImageDraw # NOQA + import ImageFont # NOQA except ImportError: return True diff --git a/thirdpart/captcha/conf/settings.py b/thirdpart/captcha/conf/settings.py index c24196df84..e344bd9107 100644 --- a/thirdpart/captcha/conf/settings.py +++ b/thirdpart/captcha/conf/settings.py @@ -1,6 +1,5 @@ import os from django.conf import settings -from django.core.exceptions import ImproperlyConfigured CAPTCHA_FONT_PATH = getattr(settings, 'CAPTCHA_FONT_PATH', os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'fonts/Vera.ttf'))) CAPTCHA_FONT_SIZE = getattr(settings, 'CAPTCHA_FONT_SIZE', 22) @@ -19,9 +18,9 @@ CAPTCHA_IMAGE_BEFORE_FIELD = getattr(settings, 'CAPTCHA_IMAGE_BEFORE_FIELD', Tru CAPTCHA_DICTIONARY_MIN_LENGTH = getattr(settings, 'CAPTCHA_DICTIONARY_MIN_LENGTH', 0) CAPTCHA_DICTIONARY_MAX_LENGTH = getattr(settings, 'CAPTCHA_DICTIONARY_MAX_LENGTH', 99) if CAPTCHA_IMAGE_BEFORE_FIELD: - CAPTCHA_OUTPUT_FORMAT = getattr(settings, 'CAPTCHA_OUTPUT_FORMAT', u'%(image)s %(hidden_field)s %(text_field)s') + CAPTCHA_OUTPUT_FORMAT = getattr(settings, 'CAPTCHA_OUTPUT_FORMAT', '%(image)s %(hidden_field)s %(text_field)s') else: - CAPTCHA_OUTPUT_FORMAT = getattr(settings, 'CAPTCHA_OUTPUT_FORMAT', u'%(hidden_field)s %(text_field)s %(image)s') + CAPTCHA_OUTPUT_FORMAT = getattr(settings, 'CAPTCHA_OUTPUT_FORMAT', '%(hidden_field)s %(text_field)s %(image)s') CAPTCHA_TEST_MODE = getattr(settings, 'CAPTCHA_TEST_MODE', getattr(settings, 'CATPCHA_TEST_MODE', False)) diff --git a/thirdpart/captcha/fields.py b/thirdpart/captcha/fields.py index 4dd2b374fc..05b7b7d2b8 100644 --- a/thirdpart/captcha/fields.py +++ b/thirdpart/captcha/fields.py @@ -1,12 +1,12 @@ from captcha.conf import settings -from django.conf import settings as django_settings from captcha.models import CaptchaStore, get_safe_now from django.core.exceptions import ImproperlyConfigured -from django.core.urlresolvers import reverse, NoReverseMatch +from django.core.urlresolvers import reverse, NoReverseMatch from django.forms import ValidationError from django.forms.fields import CharField, MultiValueField from django.forms.widgets import TextInput, MultiWidget, HiddenInput from django.utils.translation import ugettext, ugettext_lazy +from six import u class BaseCaptchaTextInput(MultiWidget): @@ -38,14 +38,10 @@ class BaseCaptchaTextInput(MultiWidget): key = CaptchaStore.generate_key() # these can be used by format_output and render - self._value = [key, u''] + self._value = [key, u('')] self._key = key self.id_ = self.build_attrs(attrs).get('id', None) - def render(self, name, value, attrs=None): - #self.fetch_captcha_store(name, value, attrs) - return super(BaseCaptchaTextInput, self).render(name, self._value, attrs=attrs) - def id_for_label(self, id_): if id_: return id_ + '_1' @@ -76,6 +72,7 @@ class CaptchaTextInput(BaseCaptchaTextInput): def format_output(self, rendered_widgets): hidden_field, text_field = rendered_widgets + text_field = text_field.replace(', 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: django-simple-captcha 0.4.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-02-10 14:43+0200\n" +"PO-Revision-Date: 2014-02-10 15:00+0200\n" +"Last-Translator: Venelin Stoykov \n" +"Language-Team: bg \n" +"Language: bg\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" + +#: fields.py:91 +msgid "Play CAPTCHA as audio file" +msgstr "Чуй текста като аудио файл" + +#: fields.py:106 fields.py:135 tests/tests.py:99 tests/tests.py:239 +#: tests/tests.py:246 +msgid "Invalid CAPTCHA" +msgstr "Сгрешен текст" + +#: tests/tests.py:125 +msgid "This field is required." +msgstr "Това поле е задължително" diff --git a/thirdpart/captcha/locale/cs/LC_MESSAGES/django.po b/thirdpart/captcha/locale/cs/LC_MESSAGES/django.po index f633cfee65..21ef0297e8 100644 --- a/thirdpart/captcha/locale/cs/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/cs/LC_MESSAGES/django.po @@ -11,7 +11,7 @@ msgstr "" "PO-Revision-Date: 2012-10-09 07:08+0200\n" "Last-Translator: Beda Kosata \n" "Language-Team: Czech <>\n" -"Language: \n" +"Language: cs\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/locale/de/LC_MESSAGES/django.po b/thirdpart/captcha/locale/de/LC_MESSAGES/django.po index b38051e3b8..286ce653ad 100644 --- a/thirdpart/captcha/locale/de/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/de/LC_MESSAGES/django.po @@ -11,6 +11,7 @@ msgstr "" "PO-Revision-Date: 2013-07-16 12:10+0100\n" "Last-Translator: Patrick Lauber \n" "Language-Team: DE \n" +"Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/locale/es/LC_MESSAGES/django.po b/thirdpart/captcha/locale/es/LC_MESSAGES/django.po new file mode 100644 index 0000000000..bd44d3ee58 --- /dev/null +++ b/thirdpart/captcha/locale/es/LC_MESSAGES/django.po @@ -0,0 +1,32 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: django-simple-captcha\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-07-16 12:06+0200\n" +"PO-Revision-Date: 2014-05-20 21:22+0100\n" +"Last-Translator: https://github.com/dragosdobrota\n" +"Language-Team: es\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.6.5\n" + +#: fields.py:90 +msgid "Play CAPTCHA as audio file" +msgstr "Reproducir CAPTCHA de audio" + +#: fields.py:105 fields.py:134 tests/tests.py:99 tests/tests.py:239 +#: tests/tests.py:246 +msgid "Invalid CAPTCHA" +msgstr "CAPTCHA no válido" + +#: tests/tests.py:125 +msgid "This field is required." +msgstr "Este campo es obligatorio." diff --git a/thirdpart/captcha/locale/fr/LC_MESSAGES/django.po b/thirdpart/captcha/locale/fr/LC_MESSAGES/django.po index 28f990f32c..5a07f5d7d1 100644 --- a/thirdpart/captcha/locale/fr/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/fr/LC_MESSAGES/django.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # Patrick Samson , 2010. # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: django-simple-captcha 0.2.0\n" @@ -11,8 +10,8 @@ msgstr "" "POT-Creation-Date: 2012-07-25 11:44+0300\n" "PO-Revision-Date: 2010-09-16 12:16+0200\n" "Last-Translator: Patrick Samson \n" -"Language-Team: LANGUAGE \n" -"Language: \n" +"Language-Team: fr \n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/locale/it/LC_MESSAGES/django.po b/thirdpart/captcha/locale/it/LC_MESSAGES/django.po index 8cd7724508..03a5851f22 100644 --- a/thirdpart/captcha/locale/it/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/it/LC_MESSAGES/django.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # Arjuna Del Toso , 2012 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: django-simple-captcha 0.3.6\n" @@ -12,6 +11,8 @@ msgstr "" "PO-Revision-Date: 2012-11-14 02:53+0000\n" "Last-Translator: Arjuna Del Toso \n" "MIME-Version: 1.0\n" +"Language-Team: Arjuna Del Toso \n" +"Language: it\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n>1;\n" diff --git a/thirdpart/captcha/locale/ja/LC_MESSAGES/django.po b/thirdpart/captcha/locale/ja/LC_MESSAGES/django.po new file mode 100644 index 0000000000..f2aafbb563 --- /dev/null +++ b/thirdpart/captcha/locale/ja/LC_MESSAGES/django.po @@ -0,0 +1,31 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# Keisuke URAGO , 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: django-simple-captcha\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-02-13 07:11+0900\n" +"PO-Revision-Date: 2014-02-13 07:11+0900\n" +"Last-Translator: Keisuke URAGO \n" +"Language-Team: Keisuke URAGO \n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: fields.py:90 +msgid "Play CAPTCHA as audio file" +msgstr "CAPTCHAをオーディオで読み上げる" + +#: fields.py:105 fields.py:134 tests/tests.py:99 tests/tests.py:239 +#: tests/tests.py:246 +msgid "Invalid CAPTCHA" +msgstr "CAPTCHAの値が違っています" + +#: tests/tests.py:125 +msgid "This field is required." +msgstr "この項目は必須です" diff --git a/thirdpart/captcha/locale/nl/LC_MESSAGES/django.po b/thirdpart/captcha/locale/nl/LC_MESSAGES/django.po index 3b0162ce55..bf69a6a9bd 100644 --- a/thirdpart/captcha/locale/nl/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/nl/LC_MESSAGES/django.po @@ -3,15 +3,16 @@ # This file is distributed under the same license as the PACKAGE package. # Leon de Rijke , 2013. # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: django-simple-captcha 0.3.6\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-02-15 13:26+0100\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2013-02-15 13:26+0100\n" "Last-Translator: Leon de Rijke \n" "MIME-Version: 1.0\n" +"Language-Team: Leon de Rijke \n" +"Language: nl\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" diff --git a/thirdpart/captcha/locale/pl/LC_MESSAGES/django.po b/thirdpart/captcha/locale/pl/LC_MESSAGES/django.po index 86d65c1833..5bcbf4018d 100644 --- a/thirdpart/captcha/locale/pl/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/pl/LC_MESSAGES/django.po @@ -3,16 +3,15 @@ # This file is distributed under the same license as the django-simple-captcha package. # Sławomir Zborowski , 2013. # -#, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" +"Project-Id-Version: django-simple-captcha 0.3.6\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-08-18 18:49+0200\n" "PO-Revision-Date: 2013-08-18 18:52+0200\n" "Last-Translator: Sławomir Zborowski \n" "Language-Team: Polisch\n" -"Language: \n" +"Language: pl\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/locale/pt_BR/LC_MESSAGES/django.po b/thirdpart/captcha/locale/pt_BR/LC_MESSAGES/django.po index 4dbecd5ef4..47e84f1224 100644 --- a/thirdpart/captcha/locale/pt_BR/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/pt_BR/LC_MESSAGES/django.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # Alisson Patricio , 2013. # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: django-simple-captcha 0.3.7\n" @@ -11,7 +10,8 @@ msgstr "" "POT-Creation-Date: 2013-05-18 10:58-0300\n" "PO-Revision-Date: 2013-05-18 13:12-0300\n" "Last-Translator: Alisson Patricio \n" -"Language: Portuguese (Brazilian)\n" +"Language-Team: Alisson Patricio \n" +"Language: pt_br\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/locale/ru/LC_MESSAGES/django.po b/thirdpart/captcha/locale/ru/LC_MESSAGES/django.po index 4c3c8aaf72..5c6a9f3836 100644 --- a/thirdpart/captcha/locale/ru/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/ru/LC_MESSAGES/django.po @@ -3,16 +3,15 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" +"Project-Id-Version: django-simple-captcha 0.3.7\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2012-07-25 11:17+0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" +"PO-Revision-Date: 2012-07-25 11:17+0300\n" +"Last-Translator: \n" +"Language-Team: ru \n" +"Language: ru\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/locale/sk/LC_MESSAGES/django.po b/thirdpart/captcha/locale/sk/LC_MESSAGES/django.po new file mode 100644 index 0000000000..f3ce9b33a4 --- /dev/null +++ b/thirdpart/captcha/locale/sk/LC_MESSAGES/django.po @@ -0,0 +1,32 @@ +# Slovak translation of django-simple-captcha. +# Copyright (C) 2013 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# Pavol Otto , 2013. +# + +msgid "" +msgstr "" +"Project-Id-Version: django-simple-captcha 0.3.7\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-10-15 17:16+0200\n" +"PO-Revision-Date: 2013-10-15 17:16+0200\n" +"Last-Translator: Pavol Otto \n" +"Language-Team: SK\n" +"Language: sk\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" + +#: fields.py:90 +msgid "Play CAPTCHA as audio file" +msgstr "Prehrať captchu ako audio súbor" + +#: fields.py:105 fields.py:134 tests/tests.py:99 tests/tests.py:239 +#: tests/tests.py:246 +msgid "Invalid CAPTCHA" +msgstr "Neplatná CAPTCHA" + +#: tests/tests.py:125 +msgid "This field is required." +msgstr "Toto pole je povinné." diff --git a/thirdpart/captcha/locale/tr/LC_MESSAGES/django.po b/thirdpart/captcha/locale/tr/LC_MESSAGES/django.po index 8c0edb2536..ed35e2bd86 100644 --- a/thirdpart/captcha/locale/tr/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/tr/LC_MESSAGES/django.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: django-simple-captcha 0.3.6\n" @@ -11,7 +10,8 @@ msgstr "" "POT-Creation-Date: 2013-01-19 16:33-0200\n" "PO-Revision-Date: 2013-01-19 20:52+0200\n" "Last-Translator: Gokmen Gorgen \n" -"Language: \n" +"Language-Team: TR Gokmen Gorgen \n" +"Language: tr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/locale/uk/LC_MESSAGES/django.po b/thirdpart/captcha/locale/uk/LC_MESSAGES/django.po new file mode 100644 index 0000000000..50c505e92e --- /dev/null +++ b/thirdpart/captcha/locale/uk/LC_MESSAGES/django.po @@ -0,0 +1,32 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: django-simple-captcha 0.3.6\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-02-21 22:05+0200\n" +"PO-Revision-Date: 2014-02-21 22:05+0200\n" +"Last-Translator: @FuriousCoder\n" +"Language-Team: uk @FuriousCoder\n" +"Language: uk\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" + +#: fields.py:91 +msgid "Play CAPTCHA as audio file" +msgstr "Відтворити CAPTCHA як аудіо файл." + +#: fields.py:106 fields.py:135 tests/tests.py:99 tests/tests.py:239 +#: tests/tests.py:246 +msgid "Invalid CAPTCHA" +msgstr "Неправильна відповідь." + +#: tests/tests.py:125 +msgid "This field is required." +msgstr "Це поле є обов'язковим." diff --git a/thirdpart/captcha/locale/zh_CN/LC_MESSAGES/django.po b/thirdpart/captcha/locale/zh_CN/LC_MESSAGES/django.po index 85f28265d3..e85dcf95e0 100644 --- a/thirdpart/captcha/locale/zh_CN/LC_MESSAGES/django.po +++ b/thirdpart/captcha/locale/zh_CN/LC_MESSAGES/django.po @@ -3,15 +3,15 @@ # This file is distributed under the same license as the PACKAGE package. # Ming Chen , 2013. # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: django-simple-captcha 0.3.6\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-03-01 05:04+0800\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2013-03-01 05:04+0800\n" "Last-Translator: Ming Chen \n" -"Language: \n" +"Language-Team: zh_cn Ming Chen \n" +"Language: zh_cn\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/thirdpart/captcha/management/commands/captcha_clean.py b/thirdpart/captcha/management/commands/captcha_clean.py index 1d22f11443..88f28e402f 100644 --- a/thirdpart/captcha/management/commands/captcha_clean.py +++ b/thirdpart/captcha/management/commands/captcha_clean.py @@ -11,15 +11,15 @@ class Command(BaseCommand): verbose = int(options.get('verbosity')) expired_keys = CaptchaStore.objects.filter(expiration__lte=get_safe_now()).count() if verbose >= 1: - print "Currently %d expired hashkeys" % expired_keys + print("Currently %d expired hashkeys" % expired_keys) try: CaptchaStore.remove_expired() except: if verbose >= 1: - print "Unable to delete expired hashkeys." + print("Unable to delete expired hashkeys.") sys.exit(1) if verbose >= 1: if expired_keys > 0: - print "%d expired hashkeys removed." % expired_keys + print("%d expired hashkeys removed." % expired_keys) else: - print "No keys to remove." + print("No keys to remove.") diff --git a/thirdpart/captcha/migrations/0001_initial.py b/thirdpart/captcha/migrations/0001_initial.py index 389897b447..c842039471 100644 --- a/thirdpart/captcha/migrations/0001_initial.py +++ b/thirdpart/captcha/migrations/0001_initial.py @@ -1,39 +1,26 @@ -# encoding: utf-8 -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models +# -*- coding: utf-8 -*- +from __future__ import unicode_literals -class Migration(SchemaMigration): - - def forwards(self, orm): - - # Adding model 'CaptchaStore' - db.create_table('captcha_captchastore', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('challenge', self.gf('django.db.models.fields.CharField')(max_length=32)), - ('response', self.gf('django.db.models.fields.CharField')(max_length=32)), - ('hashkey', self.gf('django.db.models.fields.CharField')(unique=True, max_length=40)), - ('expiration', self.gf('django.db.models.fields.DateTimeField')()), - )) - db.send_create_signal('captcha', ['CaptchaStore']) +from django.db import models, migrations - def backwards(self, orm): - - # Deleting model 'CaptchaStore' - db.delete_table('captcha_captchastore') +class Migration(migrations.Migration): + dependencies = [ + ] - models = { - 'captcha.captchastore': { - 'Meta': {'object_name': 'CaptchaStore'}, - 'challenge': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'expiration': ('django.db.models.fields.DateTimeField', [], {}), - 'hashkey': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'response': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - } - } - - complete_apps = ['captcha'] + operations = [ + migrations.CreateModel( + name='CaptchaStore', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('challenge', models.CharField(max_length=32)), + ('response', models.CharField(max_length=32)), + ('hashkey', models.CharField(unique=True, max_length=40)), + ('expiration', models.DateTimeField()), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/thirdpart/captcha/migrations/__init__.py b/thirdpart/captcha/migrations/__init__.py index e69de29bb2..1276b35c86 100644 --- a/thirdpart/captcha/migrations/__init__.py +++ b/thirdpart/captcha/migrations/__init__.py @@ -0,0 +1,21 @@ +""" +Django migrations for django-simple-captcha app + +This package does not contain South migrations. South migrations can be found +in the ``south_migrations`` package. +""" + +SOUTH_ERROR_MESSAGE = """\n +For South support, customize the SOUTH_MIGRATION_MODULES setting like so: + + SOUTH_MIGRATION_MODULES = { + 'captcha': 'captcha.south_migrations', + } +""" + +# Ensure the user is not using Django 1.6 or below with South +try: + from django.db import migrations # noqa +except ImportError: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured(SOUTH_ERROR_MESSAGE) \ No newline at end of file diff --git a/thirdpart/captcha/models.py b/thirdpart/captcha/models.py index 2bc62d30df..8263b5bf90 100644 --- a/thirdpart/captcha/models.py +++ b/thirdpart/captcha/models.py @@ -40,10 +40,9 @@ class CaptchaStore(models.Model): expiration = models.DateTimeField(blank=False) def save(self, *args, **kwargs): - #import ipdb; ipdb.set_trace() + self.response = six.text_type(self.response).lower() if not self.expiration: - #self.expiration = datetime.datetime.now() + datetime.timedelta(minutes=int(captcha_settings.CAPTCHA_TIMEOUT)) self.expiration = get_safe_now() + datetime.timedelta(minutes=int(captcha_settings.CAPTCHA_TIMEOUT)) if not self.hashkey: key_ = unicodedata.normalize('NFKD', str(randrange(0, MAX_RANDOM_KEY)) + str(time.time()) + six.text_type(self.challenge)).encode('ascii', 'ignore') + unicodedata.normalize('NFKD', six.text_type(self.response)).encode('ascii', 'ignore') diff --git a/thirdpart/captcha/south_migrations/0001_initial.py b/thirdpart/captcha/south_migrations/0001_initial.py new file mode 100644 index 0000000000..389897b447 --- /dev/null +++ b/thirdpart/captcha/south_migrations/0001_initial.py @@ -0,0 +1,39 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding model 'CaptchaStore' + db.create_table('captcha_captchastore', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('challenge', self.gf('django.db.models.fields.CharField')(max_length=32)), + ('response', self.gf('django.db.models.fields.CharField')(max_length=32)), + ('hashkey', self.gf('django.db.models.fields.CharField')(unique=True, max_length=40)), + ('expiration', self.gf('django.db.models.fields.DateTimeField')()), + )) + db.send_create_signal('captcha', ['CaptchaStore']) + + + def backwards(self, orm): + + # Deleting model 'CaptchaStore' + db.delete_table('captcha_captchastore') + + + models = { + 'captcha.captchastore': { + 'Meta': {'object_name': 'CaptchaStore'}, + 'challenge': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'expiration': ('django.db.models.fields.DateTimeField', [], {}), + 'hashkey': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'response': ('django.db.models.fields.CharField', [], {'max_length': '32'}) + } + } + + complete_apps = ['captcha'] diff --git a/thirdpart/captcha/south_migrations/__init__.py b/thirdpart/captcha/south_migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/thirdpart/captcha/tests/__init__.py b/thirdpart/captcha/tests/__init__.py index b45c48cd9c..8ce44e15b5 100644 --- a/thirdpart/captcha/tests/__init__.py +++ b/thirdpart/captcha/tests/__init__.py @@ -1 +1 @@ -from .tests import CaptchaCase, trivial_challenge +from .tests import CaptchaCase, trivial_challenge # NOQA diff --git a/thirdpart/captcha/tests/tests.py b/thirdpart/captcha/tests/tests.py index 7c93e6855c..a2b26a16e9 100644 --- a/thirdpart/captcha/tests/tests.py +++ b/thirdpart/captcha/tests/tests.py @@ -12,6 +12,7 @@ import json import re import six import os +from six import u class CaptchaCase(TestCase): @@ -42,7 +43,6 @@ class CaptchaCase(TestCase): settings.CAPTCHA_WORDS_DICTIONARY = self.__current_settings_dictionary settings.CAPTCHA_PUNCTUATION = self.__current_settings_punctuation - def __extract_hash_and_response(self, r): hash_ = re.findall(r'value="([0-9a-f]+)"', str(r.content))[0] response = CaptchaStore.objects.get(hashkey=hash_).response @@ -175,7 +175,7 @@ class CaptchaCase(TestCase): def testOutputFormat(self): for urlname in ('captcha-test', 'captcha-test-model-form'): - settings.CAPTCHA_OUTPUT_FORMAT = u'%(image)s

Hello, captcha world

%(hidden_field)s%(text_field)s' + settings.CAPTCHA_OUTPUT_FORMAT = u('%(image)s

Hello, captcha world

%(hidden_field)s%(text_field)s') r = self.client.get(reverse(urlname)) self.assertEqual(r.status_code, 200) self.assertTrue('

Hello, captcha world

' in str(r.content)) @@ -186,7 +186,7 @@ class CaptchaCase(TestCase): # we turn on DEBUG because CAPTCHA_OUTPUT_FORMAT is only checked debug django_settings.DEBUG = True - settings.CAPTCHA_OUTPUT_FORMAT = u'%(image)s' + settings.CAPTCHA_OUTPUT_FORMAT = u('%(image)s') try: self.client.get(reverse(urlname)) self.fail() @@ -195,14 +195,14 @@ class CaptchaCase(TestCase): django_settings.DEBUG = __current_settings_debug def testPerFormFormat(self): - settings.CAPTCHA_OUTPUT_FORMAT = u'%(image)s testCustomFormatString %(hidden_field)s %(text_field)s' + settings.CAPTCHA_OUTPUT_FORMAT = u('%(image)s testCustomFormatString %(hidden_field)s %(text_field)s') r = self.client.get(reverse('captcha-test')) self.assertTrue('testCustomFormatString' in str(r.content)) r = self.client.get(reverse('test_per_form_format')) self.assertTrue('testPerFieldCustomFormatString' in str(r.content)) def testIssue31ProperLabel(self): - settings.CAPTCHA_OUTPUT_FORMAT = u'%(image)s %(hidden_field)s %(text_field)s' + settings.CAPTCHA_OUTPUT_FORMAT = u('%(image)s %(hidden_field)s %(text_field)s') r = self.client.get(reverse('captcha-test')) self.assertTrue('