source: products/quintagroup.z3cform.captcha/trunk/quintagroup/z3cform/captcha/widget.py @ 1960

Last change on this file since 1960 was 1960, checked in by liebster, 9 years ago

#173: Copy quintagroup.z3cform.captcha (from http://svn.quintagroup.com/elaw/packages/quintagroup.z3cform.captcha/) to products repository

File size: 1.1 KB
Line 
1from zope.interface import implementer
2from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
3
4from z3c.form import interfaces
5from z3c.form import widget
6
7from Products.CMFCore.utils import getToolByName
8
9from z3c.form.browser.text import TextWidget
10
11class CaptchaWidget(TextWidget):
12   
13   def getCaptcha(self):
14       return self.form.context.getCaptcha()
15
16   def render(self):
17       key = self.getCaptcha()
18       portal_url = getToolByName(self.form.context, 'portal_url')()
19       image_url = "%s/getCaptchaImage/%s"%(portal_url, key)
20
21       return u"""<input type="hidden" value="%s" name="%shashkey" />
22                   %s
23                   <img src="%s" alt="Enter the word"/>""" % (key,
24                                                              self.form.prefix,
25                                                              super(CaptchaWidget, self).render(),
26                                                              image_url)
27       return super(CaptchaWidget, self).template(self) 
28
29@implementer(interfaces.IFieldWidget)
30def CaptchaWidgetFactory(field, request):
31    return widget.FieldWidget(field, CaptchaWidget(request))
Note: See TracBrowser for help on using the repository browser.