web/views/baseviews.py
branchtls-sprint
changeset 985 6a25c58a1c23
parent 824 a5e6acffde30
parent 978 536c748e7b3f
child 1006 92a0601b2523
equal deleted inserted replaced
984:536e421b082b 985:6a25c58a1c23
     9 
     9 
    10 :organization: Logilab
    10 :organization: Logilab
    11 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
    11 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
    12 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
    12 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
    13 """
    13 """
       
    14 #from __future__ import with_statement
       
    15 
    14 __docformat__ = "restructuredtext en"
    16 __docformat__ = "restructuredtext en"
    15 
    17 
    16 from warnings import warn
    18 from warnings import warn
    17 
    19 
    18 from rql import nodes
    20 from rql import nodes
    48 class FinalView(AnyRsetView):
    50 class FinalView(AnyRsetView):
    49     """display values without any transformation (i.e. get a number for
    51     """display values without any transformation (i.e. get a number for
    50     entities) 
    52     entities) 
    51     """
    53     """
    52     id = 'final'
    54     id = 'final'
       
    55     # record generated i18n catalog messages
       
    56     _('%d years')
       
    57     _('%d months')
       
    58     _('%d weeks')
       
    59     _('%d days')
       
    60     _('%d hours')
       
    61     _('%d minutes')
       
    62     _('%d seconds')
       
    63     _('%d years')
       
    64     _('%d months')
       
    65     _('%d weeks')
       
    66     _('%d days')
       
    67     _('%d hours')
       
    68     _('%d minutes')
       
    69     _('%d seconds')
    53             
    70             
    54     def cell_call(self, row, col, props=None, displaytime=False, format='text/html'):
    71     def cell_call(self, row, col, props=None, displaytime=False, format='text/html'):
    55         etype = self.rset.description[row][col]
    72         etype = self.rset.description[row][col]
    56         value = self.rset.rows[row][col]
    73         value = self.rset.rows[row][col]
    57         if etype == 'String':
    74         if etype == 'String':
    59             if entity is not None:
    76             if entity is not None:
    60                 # yes !
    77                 # yes !
    61                 self.w(entity.printable_value(rtype, value, format=format))
    78                 self.w(entity.printable_value(rtype, value, format=format))
    62                 return
    79                 return
    63         if etype in ('Time', 'Interval'):
    80         if etype in ('Time', 'Interval'):
    64             _ = self.req._
       
    65             # value is DateTimeDelta but we have no idea about what is the 
    81             # value is DateTimeDelta but we have no idea about what is the 
    66             # reference date here, so we can only approximate years and months
    82             # reference date here, so we can only approximate years and months
       
    83             if format == 'text/html':
       
    84                 space = ' '
       
    85             else:
       
    86                 space = ' '
    67             if value.days > 730: # 2 years
    87             if value.days > 730: # 2 years
    68                 self.w(_('%d years') % (value.days // 365))
    88                 self.w(self.req.__('%%d%syears' % space) % (value.days // 365))
    69             elif value.days > 60: # 2 months
    89             elif value.days > 60: # 2 months
    70                 self.w(_('%d months') % (value.days // 30))
    90                 self.w(self.req.__('%%d%smonths' % space) % (value.days // 30))
    71             elif value.days > 14: # 2 weeks
    91             elif value.days > 14: # 2 weeks
    72                 self.w(_('%d weeks') % (value.days // 7))
    92                 self.w(self.req.__('%%d%sweeks' % space) % (value.days // 7))
    73             elif value.days > 2:
    93             elif value.days > 2:
    74                 self.w(_('%s days') % int(value.days))
    94                 self.w(self.req.__('%%d%sdays' % space) % int(value.days))
    75             elif value.hours > 2:
    95             elif value.hours > 2:
    76                 self.w(_('%s hours') % int(value.hours))
    96                 self.w(self.req.__('%%d%shours' % space) % int(value.hours))
    77             elif value.minutes >= 2:
    97             elif value.minutes >= 2:
    78                 self.w(_('%s minutes') % int(value.minutes))
    98                 self.w(self.req.__('%%d%sminutes' % space) % int(value.minutes))
    79             else:
    99             else:
    80                 self.w(_('%s seconds') % int(value.seconds))
   100                 self.w(self.req.__('%%d%sseconds' % space) % int(value.seconds))
    81             return
   101             return
    82         self.wdata(printable_value(self.req, etype, value, props, displaytime=displaytime))
   102         self.wdata(printable_value(self.req, etype, value, props, displaytime=displaytime))
    83 
   103 
    84         
   104         
    85 PRIMARY_SKIP_RELS = set(['is', 'is_instance_of', 'identity',
   105 PRIMARY_SKIP_RELS = set(['is', 'is_instance_of', 'identity',
   221     def render_side_related(self, entity, siderelations):
   241     def render_side_related(self, entity, siderelations):
   222         """display side related relations:
   242         """display side related relations:
   223         non-meta in a first step, meta in a second step
   243         non-meta in a first step, meta in a second step
   224         """
   244         """
   225         if hasattr(self, 'get_side_boxes_defs'):
   245         if hasattr(self, 'get_side_boxes_defs'):
   226             for label, rset in self.get_side_boxes_defs(entity):
   246             sideboxes = [(label, rset) for label, rset in self.get_side_boxes_defs(entity)
   227                 if rset:
   247                          if rset]
       
   248             if sideboxes:
       
   249                 self.w(u'<table width="100%">')
       
   250                 for label, rset in sideboxes:
       
   251                     self.w(u'<tr><td>')
   228                     self.w(u'<div class="sideRelated">')
   252                     self.w(u'<div class="sideRelated">')
   229                     self.wview('sidebox', rset, title=label)
   253                     self.wview('sidebox', rset, title=label)
   230                     self.w(u'</div>')
   254                     self.w(u'</div>')
       
   255                     self.w(u'</td></tr>')
       
   256                 self.w(u'</table>')
   231         elif siderelations:
   257         elif siderelations:
       
   258             self.w(u'<table width="100%">')
       
   259             self.w(u'<tr><td>')
   232             self.w(u'<div class="sideRelated">')
   260             self.w(u'<div class="sideRelated">')
   233             for relatedinfos in siderelations:
   261             for relatedinfos in siderelations:
   234                 # if not relatedinfos[0].meta:
   262                 # if not relatedinfos[0].meta:
   235                 #    continue
   263                 #    continue
   236                 self._render_related_entities(entity, *relatedinfos)
   264                 self._render_related_entities(entity, *relatedinfos)
   237             self.w(u'</div>')
   265             self.w(u'</div>')
   238         for box in self.vreg.possible_vobjects('boxes', self.req, self.rset,
   266             self.w(u'</td></tr>')
   239                                                row=self.row, view=self,
   267             self.w(u'</table>')
   240                                                context='incontext'):
   268         boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
   241             try:
   269                                                  row=self.row, view=self,
   242                 box.dispatch(w=self.w, row=self.row)
   270                                                  context='incontext'))
   243             except NotImplementedError:
   271         if boxes:
   244                 # much probably a context insensitive box, which only implements
   272             self.w(u'<table width="100%">')
   245                 # .call() and not cell_call()
   273             for box in boxes:
   246                 box.dispatch(w=self.w)
   274                 self.w(u'<tr><td>')
       
   275                 try:
       
   276                     box.dispatch(w=self.w, row=self.row)
       
   277                 except NotImplementedError:
       
   278                     # much probably a context insensitive box, which only implements
       
   279                     # .call() and not cell_call()
       
   280                     box.dispatch(w=self.w)
       
   281                 self.w(u'</td></tr>')
       
   282             self.w(u'</table>')
   247                 
   283                 
   248     def is_side_related(self, rschema, eschema):
   284     def is_side_related(self, rschema, eschema):
   249         return rschema.meta and \
   285         return rschema.meta and \
   250                not rschema.schema_relation() == eschema.schema_entity()
   286                not rschema.schema_relation() == eschema.schema_entity()
   251 
   287