Last change
on this file since 1861 was
1861,
checked in by liebster, 14 years ago
|
Changed the location of the captcha image on the forms
|
File size:
1.3 KB
|
Rev | Line | |
---|
[871] | 1 | from zope.component import getMultiAdapter |
---|
| 2 | from zope.app.form.browser import ASCIIWidget |
---|
| 3 | from zope.app.form.interfaces import ConversionError |
---|
| 4 | from zope.app.form.browser.textwidgets import renderElement |
---|
| 5 | |
---|
| 6 | from Acquisition import aq_inner |
---|
| 7 | |
---|
| 8 | from quintagroup.plonecaptchas import ProductMessageFactory as _ |
---|
| 9 | |
---|
| 10 | class CaptchaWidget(ASCIIWidget): |
---|
| 11 | def __call__(self): |
---|
| 12 | captcha = getMultiAdapter((aq_inner(self.context.context), self.request), name='captcha') |
---|
| 13 | kwargs = {'type': self.type, |
---|
| 14 | 'name': self.name, |
---|
| 15 | 'id': self.name, |
---|
| 16 | 'cssClass': self.cssClass, |
---|
| 17 | 'style': self.style, |
---|
| 18 | 'size': self.displayWidth, |
---|
| 19 | 'extra': self.extra} |
---|
| 20 | if self.displayMaxWidth: |
---|
| 21 | kwargs['maxlength'] = self.displayMaxWidth # TODO This is untested. |
---|
| 22 | |
---|
[1861] | 23 | return u"""%s%s""" % \ |
---|
| 24 | (renderElement(self.tag, **kwargs), captcha.image_tag()) |
---|
[871] | 25 | |
---|
| 26 | def _toFieldValue(self, input): |
---|
| 27 | # Verify the user input against the captcha |
---|
| 28 | captcha = getMultiAdapter((aq_inner(self.context.context), self.request), name='captcha') |
---|
| 29 | if not captcha.verify(input): |
---|
| 30 | raise ConversionError(_(u"Please re-enter validation code.")) |
---|
| 31 | return super(CaptchaWidget, self)._toFieldValue(input) |
---|
Note: See
TracBrowser
for help on using the repository browser.