Last change
on this file since 3544 was
3544,
checked in by vmaksymiv, 12 years ago
|
removed unused import
|
File size:
1.4 KB
|
Rev | Line | |
---|
[1960] | 1 | from zope.interface import implementer |
---|
| 2 | |
---|
| 3 | from z3c.form import interfaces |
---|
| 4 | from z3c.form import widget |
---|
| 5 | |
---|
| 6 | from Products.CMFCore.utils import getToolByName |
---|
| 7 | |
---|
| 8 | from z3c.form.browser.text import TextWidget |
---|
| 9 | |
---|
[3257] | 10 | |
---|
[3468] | 11 | class CaptchaError(Exception): |
---|
[3257] | 12 | def __init__(self, value): |
---|
| 13 | self.value = value |
---|
| 14 | def __str__(self): |
---|
| 15 | return repr(self.value) |
---|
| 16 | |
---|
| 17 | |
---|
[1960] | 18 | class CaptchaWidget(TextWidget): |
---|
| 19 | |
---|
| 20 | def getCaptcha(self): |
---|
[3257] | 21 | try: |
---|
| 22 | return self.form.context.getCaptcha() |
---|
| 23 | except AttributeError: |
---|
| 24 | raise CaptchaError('quintagroup.captcha.core not installed. ' |
---|
| 25 | 'Install quintagroup.captcha.core using Quickinstaller or Plone Control Panel') |
---|
[1960] | 26 | |
---|
| 27 | def render(self): |
---|
| 28 | key = self.getCaptcha() |
---|
| 29 | portal_url = getToolByName(self.form.context, 'portal_url')() |
---|
| 30 | image_url = "%s/getCaptchaImage/%s"%(portal_url, key) |
---|
| 31 | |
---|
| 32 | return u"""<input type="hidden" value="%s" name="%shashkey" /> |
---|
| 33 | %s |
---|
| 34 | <img src="%s" alt="Enter the word"/>""" % (key, |
---|
| 35 | self.form.prefix, |
---|
| 36 | super(CaptchaWidget, self).render(), |
---|
| 37 | image_url) |
---|
| 38 | return super(CaptchaWidget, self).template(self) |
---|
| 39 | |
---|
| 40 | @implementer(interfaces.IFieldWidget) |
---|
| 41 | def CaptchaWidgetFactory(field, request): |
---|
| 42 | return widget.FieldWidget(field, CaptchaWidget(request)) |
---|
Note: See
TracBrowser
for help on using the repository browser.