Andriy Kornatskyy avatar Andriy Kornatskyy committed 331150a

Introduced CaptchaMixin.

Comments (0)

Files changed (4)

 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: src/wheezy/captcha/http.py:86 src/wheezy/captcha/http.py:92
-#: src/wheezy/captcha/http.py:95
+#: src/wheezy/captcha/http.py:91 src/wheezy/captcha/http.py:95
 msgid "The challenge code is not available."
 msgstr "The challenge code is not available."
 
-#: src/wheezy/captcha/http.py:90 src/wheezy/captcha/http.py:96
-#: src/wheezy/captcha/http.py:99
+#: src/wheezy/captcha/http.py:95 src/wheezy/captcha/http.py:99
 msgid "The turing number is not available."
 msgstr "The turing number is not available."
 
-#: src/wheezy/captcha/http.py:96 src/wheezy/captcha/http.py:102
-#: src/wheezy/captcha/http.py:105
+#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:105
 msgid "The challenge code is invalid."
 msgstr "The challenge code is invalid."
 
-#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:107
-#: src/wheezy/captcha/http.py:110
+#: src/wheezy/captcha/http.py:106 src/wheezy/captcha/http.py:110
 msgid "The turing number is invalid."
 msgstr "The turing number is invalid."
 
-#: src/wheezy/captcha/http.py:111 src/wheezy/captcha/http.py:117
-#: src/wheezy/captcha/http.py:120
+#: src/wheezy/captcha/http.py:116 src/wheezy/captcha/http.py:120
 #, python-format
 msgid "The code you typed has expired after %d seconds."
 msgstr "The code you typed has expired after %d seconds."
 
-#: src/wheezy/captcha/http.py:120 src/wheezy/captcha/http.py:126
-#: src/wheezy/captcha/http.py:129
+#: src/wheezy/captcha/http.py:125 src/wheezy/captcha/http.py:129
 #, python-format
 msgid "The code was typed too quickly. Wait at least %d seconds."
 msgstr "The code was typed too quickly. Wait at least %d seconds."
 
-#: src/wheezy/captcha/http.py:125 src/wheezy/captcha/http.py:131
-#: src/wheezy/captcha/http.py:134
+#: src/wheezy/captcha/http.py:130 src/wheezy/captcha/http.py:134
 msgid "The code you typed has no match."
 msgstr "The code you typed has no match."
+
+#: src/wheezy/captcha/mixin.py:23
+msgid "If you cannot read, click to generate a new one."
+msgstr "If you cannot read, click to generate a new one."

i18n/en/LC_MESSAGES/captcha.po

 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: src/wheezy/captcha/http.py:86 src/wheezy/captcha/http.py:92
-#: src/wheezy/captcha/http.py:95
+#: src/wheezy/captcha/http.py:91 src/wheezy/captcha/http.py:95
 msgid "The challenge code is not available."
 msgstr "The challenge code is not available."
 
-#: src/wheezy/captcha/http.py:90 src/wheezy/captcha/http.py:96
-#: src/wheezy/captcha/http.py:99
+#: src/wheezy/captcha/http.py:95 src/wheezy/captcha/http.py:99
 msgid "The turing number is not available."
 msgstr "The turing number is not available."
 
-#: src/wheezy/captcha/http.py:96 src/wheezy/captcha/http.py:102
-#: src/wheezy/captcha/http.py:105
+#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:105
 msgid "The challenge code is invalid."
 msgstr "The challenge code is invalid."
 
-#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:107
-#: src/wheezy/captcha/http.py:110
+#: src/wheezy/captcha/http.py:106 src/wheezy/captcha/http.py:110
 msgid "The turing number is invalid."
 msgstr "The turing number is invalid."
 
-#: src/wheezy/captcha/http.py:111 src/wheezy/captcha/http.py:117
-#: src/wheezy/captcha/http.py:120
+#: src/wheezy/captcha/http.py:116 src/wheezy/captcha/http.py:120
 #, python-format
 msgid "The code you typed has expired after %d seconds."
 msgstr "The code you typed has expired after %d seconds."
 
-#: src/wheezy/captcha/http.py:120 src/wheezy/captcha/http.py:126
-#: src/wheezy/captcha/http.py:129
+#: src/wheezy/captcha/http.py:125 src/wheezy/captcha/http.py:129
 #, python-format
 msgid "The code was typed too quickly. Wait at least %d seconds."
 msgstr "The code was typed too quickly. Wait at least %d seconds."
 
-#: src/wheezy/captcha/http.py:125 src/wheezy/captcha/http.py:131
-#: src/wheezy/captcha/http.py:134
+#: src/wheezy/captcha/http.py:130 src/wheezy/captcha/http.py:134
 msgid "The code you typed has no match."
 msgstr "The code you typed has no match."
+
+#: src/wheezy/captcha/mixin.py:23
+msgid "If you cannot read, click to generate a new one."
+msgstr "If you cannot read, click to generate a new one."

i18n/ru/LC_MESSAGES/captcha.po

 #: src/wheezy/captcha/http.py:134
 msgid "The code you typed has no match."
 msgstr "Нет соответствий с введенным кодом."
+
+#: src/wheezy/captcha/mixin.py:23
+msgid "If you cannot read, click to generate a new one."
+msgstr "Если вы не можете прочитать, нажмите чтобы сгенерировать еще."

src/wheezy/captcha/mixin.py

+
+"""
+"""
+
+from wheezy.core.descriptors import attribute
+
+
+class CaptchaMixin(object):
+
+    @attribute
+    def challenge_code(self):
+        return self.captcha_context.get_challenge_code(self.request)
+
+    def validate_captcha(self):
+        return self.captcha_context.validate(self.request,
+                                             self.errors, self._)
+
+    def captcha_widget(self, path):
+        ctx = self.captcha_context
+        return ('<img id="captcha" src="' + path + '?'
+                + ctx.challenge_key + '=' + self.challenge_code
+                + '" title="'
+                + self._('If you cannot read, click to generate a new one.')
+                + '" /><input type="hidden" name="'
+                + ctx.challenge_key
+                + '" value="'
+                + self.challenge_code
+                + '" />')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.