web/views/primary.py
brancholdstable
changeset 8462 a14b6562082b
parent 8206 f5f874d8a4f4
child 8216 99ff746e8de8
equal deleted inserted replaced
8231:1bb43e31032d 8462:a14b6562082b
    80 
    80 
    81     :attr:`show_rel_label`
    81     :attr:`show_rel_label`
    82         Renders the relation label next to the relation value if set to `True`.
    82         Renders the relation label next to the relation value if set to `True`.
    83         Otherwise, does only display the relation value.
    83         Otherwise, does only display the relation value.
    84 
    84 
    85     :attr:`skip_none`
       
    86         Does not render an attribute value that is None if set to `True`.
       
    87 
       
    88     :attr:`main_related_section`
    85     :attr:`main_related_section`
    89         Renders the relations of the entity if set to `True`.
    86         Renders the relations of the entity if set to `True`.
    90 
    87 
    91     A good practice is for you to identify the content of your entity type for
    88     A good practice is for you to identify the content of your entity type for
    92     which the default rendering does not answer your need so that you can focus
    89     which the default rendering does not answer your need so that you can focus
    97 
    94 
    98     __regid__ = 'primary'
    95     __regid__ = 'primary'
    99     title = _('primary')
    96     title = _('primary')
   100     show_attr_label = True
    97     show_attr_label = True
   101     show_rel_label = True
    98     show_rel_label = True
   102     skip_none = True
       
   103     rsection = uicfg.primaryview_section
    99     rsection = uicfg.primaryview_section
   104     display_ctrl = uicfg.primaryview_display_ctrl
   100     display_ctrl = uicfg.primaryview_display_ctrl
   105     main_related_section = True
   101     main_related_section = True
   106 
   102 
   107     def html_headers(self):
   103     def html_headers(self):
   146         self.w(u'</div>')
   142         self.w(u'</div>')
   147         # side boxes
   143         # side boxes
   148         if boxes or hasattr(self, 'render_side_related'):
   144         if boxes or hasattr(self, 'render_side_related'):
   149             self.w(u'</td><td>')
   145             self.w(u'</td><td>')
   150             self.w(u'<div class="primaryRight">')
   146             self.w(u'<div class="primaryRight">')
   151             if hasattr(self, 'render_side_related'):
       
   152                 warn('[3.2] render_side_related is deprecated')
       
   153                 self.render_side_related(entity, []) # pylint: disable=E1101
       
   154             self.render_side_boxes(boxes)
   147             self.render_side_boxes(boxes)
   155             self.w(u'</div>')
   148             self.w(u'</div>')
   156             self.w(u'</td></tr></table>')
   149             self.w(u'</td></tr></table>')
   157 
   150 
   158     def content_navigation_components(self, context):
   151     def content_navigation_components(self, context):
   195     def summary(self, entity):
   188     def summary(self, entity):
   196         """default implementation return an empty string"""
   189         """default implementation return an empty string"""
   197         return u''
   190         return u''
   198 
   191 
   199     def render_entity_attributes(self, entity):
   192     def render_entity_attributes(self, entity):
   200         """Renders all attributes and relations in the 'attributes' section. The
   193         """Renders all attributes and relations in the 'attributes' section. 
   201         :attr:`skip_none` attribute controls the display of `None` valued
       
   202         attributes.
       
   203         """
   194         """
   204         display_attributes = []
   195         display_attributes = []
   205         for rschema, _, role, dispctrl in self._section_def(entity, 'attributes'):
   196         for rschema, _, role, dispctrl in self._section_def(entity, 'attributes'):
   206             vid = dispctrl.get('vid', 'reledit')
   197             vid = dispctrl.get('vid', 'reledit')
   207             if rschema.final or vid == 'reledit' or dispctrl.get('rtypevid'):
   198             if rschema.final or vid == 'reledit' or dispctrl.get('rtypevid'):
   211                 rset = self._relation_rset(entity, rschema, role, dispctrl)
   202                 rset = self._relation_rset(entity, rschema, role, dispctrl)
   212                 if rset:
   203                 if rset:
   213                     value = self._cw.view(vid, rset)
   204                     value = self._cw.view(vid, rset)
   214                 else:
   205                 else:
   215                     value = None
   206                     value = None
   216             if not self.skip_none or (value is not None and value != ''):
   207             if value is not None and value != '':
   217                 display_attributes.append( (rschema, role, dispctrl, value) )
   208                 display_attributes.append( (rschema, role, dispctrl, value) )
   218         if display_attributes:
   209         if display_attributes:
   219             self.w(u'<table>')
   210             self.w(u'<table>')
   220             for rschema, role, dispctrl, value in display_attributes:
   211             for rschema, role, dispctrl, value in display_attributes:
   221                 # pylint: disable=E1101
   212                 # pylint: disable=E1101
   222                 if not hasattr(self, '_render_attribute'):
   213                 if not hasattr(self, '_render_attribute'):
   223                     label = self._rel_label(entity, rschema, role, dispctrl)
   214                     label = self._rel_label(entity, rschema, role, dispctrl)
   224                     self.render_attribute(label, value, table=True)
   215                     self.render_attribute(label, value, table=True)
   225                 elif support_args(self._render_attribute, 'dispctrl'):
   216                 else:
   226                     warn('[3.9] _render_attribute prototype has changed and '
   217                     warn('[3.9] _render_attribute prototype has changed and '
   227                          'renamed to render_attribute, please update %s'
   218                          'renamed to render_attribute, please update %s'
   228                          % self.__class__, DeprecationWarning)
   219                          % self.__class__, DeprecationWarning)
   229                     self._render_attribute(dispctrl, rschema, value, role=role,
   220                     self._render_attribute(dispctrl, rschema, value, role=role,
   230                                            table=True)
   221                                            table=True)
   231                 else:
       
   232                     self._render_attribute(rschema, value, role=role, table=True)
       
   233                     warn('[3.6] _render_attribute prototype has changed and '
       
   234                          'renamed to render_attribute, please update %s'
       
   235                          % self.__class__, DeprecationWarning)
       
   236             self.w(u'</table>')
   222             self.w(u'</table>')
   237 
   223 
   238     def render_attribute(self, label, value, table=False):
   224     def render_attribute(self, label, value, table=False):
   239         self.field(label, value, tr=False, table=table)
   225         self.field(label, value, tr=False, table=table)
   240 
   226 
   256                 rset = self._relation_rset(entity, rschema, role, dispctrl)
   242                 rset = self._relation_rset(entity, rschema, role, dispctrl)
   257                 if not rset:
   243                 if not rset:
   258                     continue
   244                     continue
   259                 if hasattr(self, '_render_relation'):
   245                 if hasattr(self, '_render_relation'):
   260                     # pylint: disable=E1101
   246                     # pylint: disable=E1101
   261                     if not support_args(self._render_relation, 'showlabel'):
   247                     self._render_relation(dispctrl, rset, 'autolimited')
   262                         self._render_relation(dispctrl, rset, 'autolimited')
   248                     warn('[3.9] _render_relation prototype has changed and has '
   263                         warn('[3.9] _render_relation prototype has changed and has '
   249                          'been renamed to render_relation, please update %s'
   264                              'been renamed to render_relation, please update %s'
   250                          % self.__class__, DeprecationWarning)
   265                              % self.__class__, DeprecationWarning)
       
   266                     else:
       
   267                         self._render_relation(rset, dispctrl, 'autolimited',
       
   268                                               self.show_rel_label)
       
   269                         warn('[3.6] _render_relation prototype has changed and has '
       
   270                              'been renamed to render_relation, please update %s'
       
   271                              % self.__class__, DeprecationWarning)
       
   272                     continue
   251                     continue
   273                 vid = dispctrl.get('vid', 'autolimited')
   252                 vid = dispctrl.get('vid', 'autolimited')
   274                 try:
   253                 try:
   275                     rview = self._cw.vreg['views'].select(
   254                     rview = self._cw.vreg['views'].select(
   276                         vid, self._cw, rset=rset, dispctrl=dispctrl)
   255                         vid, self._cw, rset=rset, dispctrl=dispctrl)
   432     both relations and attributes.
   411     both relations and attributes.
   433     """
   412     """
   434     __regid__ = 'attribute'
   413     __regid__ = 'attribute'
   435     __select__ = EntityView.__select__ & match_kwargs('rtype')
   414     __select__ = EntityView.__select__ & match_kwargs('rtype')
   436 
   415 
   437     def entity_call(self, entity, rtype, role, **kwargs):
   416     def entity_call(self, entity, rtype, role='subject', **kwargs):
   438         if self._cw.vreg.schema.rschema(rtype).final:
   417         if self._cw.vreg.schema.rschema(rtype).final:
   439             self.w(entity.printable_value(rtype))
   418             self.w(entity.printable_value(rtype))
   440         else:
   419         else:
   441             dispctrl = uicfg.primaryview_display_ctrl.etype_get(
   420             dispctrl = uicfg.primaryview_display_ctrl.etype_get(
   442                 entity.e_schema, rtype, role, '*')
   421                 entity.e_schema, rtype, role, '*')
   492 
   471 
   493 _pvs = uicfg.primaryview_section
   472 _pvs = uicfg.primaryview_section
   494 for rtype in META_RTYPES:
   473 for rtype in META_RTYPES:
   495     _pvs.tag_subject_of(('*', rtype, '*'), 'hidden')
   474     _pvs.tag_subject_of(('*', rtype, '*'), 'hidden')
   496     _pvs.tag_object_of(('*', rtype, '*'), 'hidden')
   475     _pvs.tag_object_of(('*', rtype, '*'), 'hidden')
   497 _pvs.tag_subject_of(('*', 'require_permission', '*'), 'hidden')
       
   498 _pvs.tag_object_of(('*', 'require_permission', '*'), 'hidden')