web/views/editviews.py
branchstable
changeset 5037 7778a2bbdf9d
parent 4621 fe1c5a46a1cb
child 5223 6abd6e3599f4
child 5421 8167de96c523
equal deleted inserted replaced
5036:3e436a494ce3 5037:7778a2bbdf9d
    13 
    13 
    14 from cubicweb import typed_eid
    14 from cubicweb import typed_eid
    15 from cubicweb.view import EntityView, StartupView
    15 from cubicweb.view import EntityView, StartupView
    16 from cubicweb.selectors import (one_line_rset, non_final_entity,
    16 from cubicweb.selectors import (one_line_rset, non_final_entity,
    17                                 match_search_state)
    17                                 match_search_state)
    18 from cubicweb.web import httpcache, captcha
    18 from cubicweb.web import httpcache
    19 from cubicweb.web.views import baseviews, linksearch_select_url
    19 from cubicweb.web.views import baseviews, linksearch_select_url
    20 
    20 
    21 
    21 
    22 class SearchForAssociationView(EntityView):
    22 class SearchForAssociationView(EntityView):
    23     """view called by the edition view when the user asks to search for
    23     """view called by the edition view when the user asks to search for
    93         if entity is not None:
    93         if entity is not None:
    94             self.w(entity.view('reledit', rtype=rtype))
    94             self.w(entity.view('reledit', rtype=rtype))
    95         else:
    95         else:
    96             super(EditableFinalView, self).cell_call(row, col, props)
    96             super(EditableFinalView, self).cell_call(row, col, props)
    97 
    97 
       
    98 try:
       
    99     from cubicweb.web import captcha
       
   100 except ImportError:
       
   101     # PIL not installed
       
   102     pass
       
   103 else:
       
   104     class CaptchaView(StartupView):
       
   105         __regid__ = 'captcha'
    98 
   106 
    99 class CaptchaView(StartupView):
   107         http_cache_manager = httpcache.NoHTTPCacheManager
   100     __regid__ = 'captcha'
   108         binary = True
       
   109         templatable = False
       
   110         content_type = 'image/jpg'
   101 
   111 
   102     http_cache_manager = httpcache.NoHTTPCacheManager
   112         def call(self):
   103     binary = True
   113             text, data = captcha.captcha(self._cw.vreg.config['captcha-font-file'],
   104     templatable = False
   114                                          self._cw.vreg.config['captcha-font-size'])
   105     content_type = 'image/jpg'
   115             key = self._cw.form.get('captchakey', 'captcha')
   106 
   116             self._cw.set_session_data(key, text)
   107     def call(self):
   117             self.w(data.read())
   108         text, data = captcha.captcha(self._cw.vreg.config['captcha-font-file'],
       
   109                                      self._cw.vreg.config['captcha-font-size'])
       
   110         self._cw.set_session_data('captcha', text)
       
   111         self.w(data.read())