common/view.py
branchtls-sprint
changeset 640 8e64f12be69c
parent 635 305da8d6aa2d
child 655 ca3c4992c7d1
equal deleted inserted replaced
635:305da8d6aa2d 640:8e64f12be69c
     6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
     9 
     9 
    10 from cStringIO import StringIO
    10 from cStringIO import StringIO
    11 from warnings import warn
       
    12 
    11 
    13 from logilab.mtconverter import html_escape
    12 from logilab.mtconverter import html_escape
    14 
    13 
    15 from cubicweb import NotAnEntity, NoSelectableObject
    14 from cubicweb import NotAnEntity, NoSelectableObject
    16 from cubicweb.selectors import (yes, match_user_groups, implements,
    15 from cubicweb.selectors import (yes, match_user_groups, implements,
   295         self.w('}\n-->\n</script>\n')
   294         self.w('}\n-->\n</script>\n')
   296 
   295 
   297     def create_url(self, etype, **kwargs):
   296     def create_url(self, etype, **kwargs):
   298         """ return the url of the entity creation form for a given entity type"""
   297         """ return the url of the entity creation form for a given entity type"""
   299         return self.req.build_url('add/%s'%etype, **kwargs)
   298         return self.req.build_url('add/%s'%etype, **kwargs)
   300 
       
   301 
       
   302 # concrete views base classes #################################################
       
   303 
       
   304 class EntityView(View):
       
   305     """base class for views applying on an entity (i.e. uniform result set)
       
   306     """
       
   307     __registerer__ = accepts_registerer
       
   308     __selectors__ = (implements('Any'),)
       
   309     registered = accepts_compat(View.registered.im_func)
       
   310 
       
   311     category = 'entityview'
       
   312     
   299     
   313     def field(self, label, value, row=True, show_label=True, w=None, tr=True):
   300     def field(self, label, value, row=True, show_label=True, w=None, tr=True):
   314         """ read-only field """
   301         """ read-only field """
   315         if w is None:
   302         if w is None:
   316             w = self.w
   303             w = self.w
   321                 label = display_name(self.req, label)
   308                 label = display_name(self.req, label)
   322             w(u'<span class="label">%s</span>' % label)
   309             w(u'<span class="label">%s</span>' % label)
   323         w(u'<div class="field">%s</div>' % value)
   310         w(u'<div class="field">%s</div>' % value)
   324         if row:
   311         if row:
   325             w(u'</div>')
   312             w(u'</div>')
       
   313 
       
   314 
       
   315 # concrete views base classes #################################################
       
   316 
       
   317 class EntityView(View):
       
   318     """base class for views applying on an entity (i.e. uniform result set)
       
   319     """
       
   320     # XXX deprecate
       
   321     __registerer__ = accepts_registerer
       
   322     __selectors__ = (implements('Any'),)
       
   323     registered = accepts_compat(View.registered.im_func)
       
   324 
       
   325     category = 'entityview'
   326 
   326 
   327 
   327 
   328 class StartupView(View):
   328 class StartupView(View):
   329     """base class for views which doesn't need a particular result set
   329     """base class for views which doesn't need a particular result set
   330     to be displayed (so they can always be displayed !)
   330     to be displayed (so they can always be displayed !)