[ui] Factorize out abstract class for simplified autoform / inline form renderer
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 21 Jul 2016 15:13:05 +0200
changeset 1487 16f2f6e7cfc9
parent 1486 a29e9d30e63b
child 1488 88e99aa4886a
[ui] Factorize out abstract class for simplified autoform / inline form renderer To be reused from other contexts.
views/archiveunit.py
views/widgets.py
--- a/views/archiveunit.py	Thu Jul 21 14:37:23 2016 +0200
+++ b/views/archiveunit.py	Thu Jul 21 15:13:05 2016 +0200
@@ -20,14 +20,14 @@
 from cubicweb import tags
 from cubicweb.predicates import is_instance
 from cubicweb.view import EntityView
-from cubicweb.web.views import uicfg, baseviews, tabs, autoform, formrenderers
+from cubicweb.web.views import uicfg, baseviews, tabs
 
 from cubes.compound import views as compound
 
 from cubes.seda.entities.itree import parent_archive_unit
 from cubes.seda.views import (add_subobject_link, dropdown_button, rtags_from_rtype_role_targets,
                               copy_rtag)
-from cubes.seda.views import viewlib
+from cubes.seda.views import viewlib, widgets
 from cubes.seda.views import uicfg as sedauicfg  # noqa - ensure those rules are defined first
 
 _ = unicode
@@ -301,29 +301,22 @@
     'inlined', 'inlined')
 
 
-class AltArchiveUnitArchiveUnitRefIdAutomaticEntityForm(autoform.AutomaticEntityForm):
-    """Custom autoform, forcing display of creation form instead of add new link, to be used on
-    SEDAAltArchiveUnitArchiveUnitRefId to force display of its sub ArchiveUnitRefId or
+class AltArchiveUnitRefIdSimplifiedAutomaticEntityForm(widgets.SimplifiedAutomaticEntityForm):
+    """Force display of AltArchiveUnitArchiveUnitRefId's sub-ArchiveUnitRefId or
     SeqAltArchiveUnitArchiveUnitRefIdManagement (uicfg will control which of them is displayed).
     """
-    __select__ = (autoform.AutomaticEntityForm.__select__
+    __select__ = (widgets.SimplifiedAutomaticEntityForm.__select__
                   & is_instance('SEDAAltArchiveUnitArchiveUnitRefId'))
 
-    def should_display_inline_creation_form(self, rschema, existing, card):
-        return not existing
 
-    def should_display_add_new_relation_link(self, rschema, existing, card):
-        return False
-
-
-class NoTitleEntityInlinedFormRenderer(formrenderers.EntityInlinedFormRenderer):
-    """Custom inlined form renderer that doesn't display any title (nor remove link)
+class ArchiveUnitNoTitleEntityInlinedFormRenderer(widgets.NoTitleEntityInlinedFormRenderer):
+    """Don't display any title nor remove link for AltArchiveUnitArchiveUnitRefId,
+    SeqAltArchiveUnitArchiveUnitRefIdManagement or ArchiveUnitRefId in the context of an archive
+    unit reference.
     """
-    __select__ = (formrenderers.EntityInlinedFormRenderer.__select__
+    __select__ = (widgets.NoTitleEntityInlinedFormRenderer.__select__
                   & (is_instance('SEDAAltArchiveUnitArchiveUnitRefId',
                                  'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement')
                      | (is_instance('SEDAArchiveUnitRefId')
                         & is_archive_unit_ref())))
 
-    def render_title(self, w, form, values):
-        pass
--- a/views/widgets.py	Thu Jul 21 14:37:23 2016 +0200
+++ b/views/widgets.py	Thu Jul 21 15:13:05 2016 +0200
@@ -20,7 +20,7 @@
 from cubicweb import tags, utils
 from cubicweb.uilib import js
 from cubicweb.web import formfields as ff, formwidgets as fw
-from cubicweb.web.views import ajaxcontroller, formrenderers
+from cubicweb.web.views import ajaxcontroller, formrenderers, autoform
 
 
 class ConceptOrTextField(ff.Field):
@@ -231,3 +231,24 @@
         w(u'</div>')
         w(u'</div>')
         return data.getvalue()
+
+
+class SimplifiedAutomaticEntityForm(autoform.AutomaticEntityForm):
+    """Custom autoform, forcing display of creation form instead of add new link.
+    """
+    __abstract__ = True
+
+    def should_display_inline_creation_form(self, rschema, existing, card):
+        return not existing
+
+    def should_display_add_new_relation_link(self, rschema, existing, card):
+        return False
+
+
+class NoTitleEntityInlinedFormRenderer(formrenderers.EntityInlinedFormRenderer):
+    """Custom inlined form renderer that doesn't display any title nor remove link.
+    """
+    __abstract__ = True
+
+    def render_title(self, w, form, values):
+        pass