web/views/formrenderers.py
branchstable
changeset 2198 ac45d4dbaf76
parent 2148 2b2b9626a98f
child 2234 1fbcf202882d
child 2247 9dbbe6a4c9b0
--- a/web/views/formrenderers.py	Mon Jun 29 18:41:07 2009 +0200
+++ b/web/views/formrenderers.py	Mon Jun 29 18:42:37 2009 +0200
@@ -215,12 +215,29 @@
 
 
 class BaseFormRenderer(FormRenderer):
-    """use form_renderer_id = 'base' if you want base FormRenderer without
-    adaptation by selection
+    """use form_renderer_id = 'base' if you want base FormRenderer layout even
+    when selected for an entity
     """
     id = 'base'
 
 
+class EntityBaseFormRenderer(BaseFormRenderer):
+    """use form_renderer_id = 'base' if you want base FormRenderer layout even
+    when selected for an entity
+    """
+    __select__ = entity_implements('Any')
+
+    def display_field(self, form, field):
+        if not super(EntityBaseFormRenderer, self).display_field(form, field):
+            if isinstance(field, HiddenInitialValueField):
+                field = field.visible_field
+            ismeta = form.edited_entity.e_schema.is_metadata(field.name)
+            return ismeta is not None and (
+                ismeta[0] in self.display_fields or
+                (ismeta[0], 'subject') in self.display_fields)
+        return True
+
+
 class HTableFormRenderer(FormRenderer):
     """display fields horizontally in a table
 
@@ -310,9 +327,11 @@
         w(u'</tr>')
 
 
-class EntityFormRenderer(FormRenderer):
+class EntityFormRenderer(EntityBaseFormRenderer):
     """specific renderer for entity edition form (edition)"""
-    __select__ = entity_implements('Any') & yes()
+    id = 'default'
+    # needs some additional points in some case (XXX explain cases)
+    __select__ = EntityBaseFormRenderer.__select__ & yes()
 
     _options = FormRenderer._options + ('display_relations_form',)
     display_relations_form = True