web/views/editviews.py
changeset 4621 fe1c5a46a1cb
parent 4387 4aacd6492ef4
child 5037 7778a2bbdf9d
--- a/web/views/editviews.py	Thu Feb 18 07:29:13 2010 +0100
+++ b/web/views/editviews.py	Thu Feb 18 08:39:30 2010 +0100
@@ -12,9 +12,10 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb import typed_eid
-from cubicweb.view import EntityView
+from cubicweb.view import EntityView, StartupView
 from cubicweb.selectors import (one_line_rset, non_final_entity,
                                 match_search_state)
+from cubicweb.web import httpcache, captcha
 from cubicweb.web.views import baseviews, linksearch_select_url
 
 
@@ -93,3 +94,18 @@
             self.w(entity.view('reledit', rtype=rtype))
         else:
             super(EditableFinalView, self).cell_call(row, col, props)
+
+
+class CaptchaView(StartupView):
+    __regid__ = 'captcha'
+
+    http_cache_manager = httpcache.NoHTTPCacheManager
+    binary = True
+    templatable = False
+    content_type = 'image/jpg'
+
+    def call(self):
+        text, data = captcha.captcha(self._cw.vreg.config['captcha-font-file'],
+                                     self._cw.vreg.config['captcha-font-size'])
+        self._cw.set_session_data('captcha', text)
+        self.w(data.read())