web/views/formrenderers.py
changeset 2234 1fbcf202882d
parent 2181 94ca417b9b07
parent 2198 ac45d4dbaf76
child 2293 7ded2a1416e4
equal deleted inserted replaced
2209:2b91abd9f5a4 2234:1fbcf202882d
   213             w(u'<td>%s</td>\n' % button.render(form))
   213             w(u'<td>%s</td>\n' % button.render(form))
   214         w(u'</tr></table>')
   214         w(u'</tr></table>')
   215 
   215 
   216 
   216 
   217 class BaseFormRenderer(FormRenderer):
   217 class BaseFormRenderer(FormRenderer):
   218     """use form_renderer_id = 'base' if you want base FormRenderer without
   218     """use form_renderer_id = 'base' if you want base FormRenderer layout even
   219     adaptation by selection
   219     when selected for an entity
   220     """
   220     """
   221     id = 'base'
   221     id = 'base'
       
   222 
       
   223 
       
   224 class EntityBaseFormRenderer(BaseFormRenderer):
       
   225     """use form_renderer_id = 'base' if you want base FormRenderer layout even
       
   226     when selected for an entity
       
   227     """
       
   228     __select__ = entity_implements('Any')
       
   229 
       
   230     def display_field(self, form, field):
       
   231         if not super(EntityBaseFormRenderer, self).display_field(form, field):
       
   232             if isinstance(field, HiddenInitialValueField):
       
   233                 field = field.visible_field
       
   234             ismeta = form.edited_entity.e_schema.is_metadata(field.name)
       
   235             return ismeta is not None and (
       
   236                 ismeta[0] in self.display_fields or
       
   237                 (ismeta[0], 'subject') in self.display_fields)
       
   238         return True
   222 
   239 
   223 
   240 
   224 class HTableFormRenderer(FormRenderer):
   241 class HTableFormRenderer(FormRenderer):
   225     """display fields horizontally in a table
   242     """display fields horizontally in a table
   226 
   243 
   308                 if self.display_field(form, field) and field.is_visible():
   325                 if self.display_field(form, field) and field.is_visible():
   309                     w(u'<th>%s</th>' % self.req._(field.label))
   326                     w(u'<th>%s</th>' % self.req._(field.label))
   310         w(u'</tr>')
   327         w(u'</tr>')
   311 
   328 
   312 
   329 
   313 class EntityFormRenderer(FormRenderer):
   330 class EntityFormRenderer(EntityBaseFormRenderer):
   314     """specific renderer for entity edition form (edition)"""
   331     """specific renderer for entity edition form (edition)"""
   315     __select__ = entity_implements('Any') & yes()
   332     id = 'default'
       
   333     # needs some additional points in some case (XXX explain cases)
       
   334     __select__ = EntityBaseFormRenderer.__select__ & yes()
   316 
   335 
   317     _options = FormRenderer._options + ('display_relations_form',)
   336     _options = FormRenderer._options + ('display_relations_form',)
   318     display_relations_form = True
   337     display_relations_form = True
   319 
   338 
   320     def render(self, form, values):
   339     def render(self, form, values):