[views] Move data object / reference custom form from archiveunit to simplified module
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 11 Oct 2017 09:25:20 +0200
changeset 2726 935cf96e49f3
parent 2715 757262c669ca
child 2734 65b1b03e6219
[views] Move data object / reference custom form from archiveunit to simplified module because this is related to simplified view of those object and unrelated to archive unit, so one would rather expect to find them there.
cubicweb_seda/views/archiveunit.py
cubicweb_seda/views/simplified.py
--- a/cubicweb_seda/views/archiveunit.py	Fri Oct 06 08:39:29 2017 +0200
+++ b/cubicweb_seda/views/archiveunit.py	Wed Oct 11 09:25:20 2017 +0200
@@ -1,4 +1,4 @@
-# copyright 2016-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr -- mailto:contact@logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
@@ -1104,39 +1104,5 @@
                         & is_archive_unit_ref())))
 
 
-class DataObjectSimplifiedAutomaticEntityForm(widgets.SimplifiedAutomaticEntityForm):
-    """On creation of a BinaryDataObject or PhysicalDataObject's in the context of a simplified
-    profile, add a field to handle the creation of the relation to the archive unit specified in
-    `req.form`.
-    """
-
-    # don't add match_form_params('referenced_by') since it's only specified for creation, not
-    # edition
-    __select__ = (widgets.SimplifiedAutomaticEntityForm.__select__
-                  & is_instance('SEDABinaryDataObject', 'SEDAPhysicalDataObject')
-                  & simplified_profile())
-
-    def inlined_form_views(self):
-        views = list(super(DataObjectSimplifiedAutomaticEntityForm, self).inlined_form_views())
-        ref_forms = [v.form for v in views if v.rtype == 'seda_data_object_reference_id']
-        if ref_forms:  # may be empty if user has no write access
-            ref_form = ref_forms[0]
-            if not ref_form.edited_entity.has_eid() and not ref_form.posting:
-                ref_form.add_hidden(name='seda_data_object_reference', eidparam=True,
-                                    role='subject',
-                                    value=self._cw.form['referenced_by'])
-        return views
-
-
-class DataObjectReferenceNoTitleEntityInlinedFormRenderer(widgets.NoTitleEntityInlinedFormRenderer):
-    """Don't display any title nor remove link for DataObjectReference in the context of a
-    simplified profile.
-    """
-
-    __select__ = (widgets.NoTitleEntityInlinedFormRenderer.__select__
-                  & is_instance('SEDADataObjectReference')
-                  & simplified_profile())
-
-
 copy_afs = afs.derive(__name__, afs.__select__ & match_form_params(vid='copy'))
 copy_afs.tag_subject_of(('*', 'seda_alt_archive_unit_archive_unit_ref_id', '*'), 'main', 'hidden')
--- a/cubicweb_seda/views/simplified.py	Fri Oct 06 08:39:29 2017 +0200
+++ b/cubicweb_seda/views/simplified.py	Wed Oct 11 09:25:20 2017 +0200
@@ -1,4 +1,4 @@
-# copyright 2016-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr -- mailto:contact@logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
@@ -22,7 +22,7 @@
 
 from ..xsd2yams import RULE_TYPES
 from ..entities import simplified_profile
-from . import CONTENT_ETYPE
+from . import CONTENT_ETYPE, widgets
 # ensure those are registered first
 from . import mgmt_rules, archivetransfer, dataobject, archiveunit  # noqa
 
@@ -193,6 +193,30 @@
     'attributes')
 
 
+class DataObjectSimplifiedAutomaticEntityForm(widgets.SimplifiedAutomaticEntityForm):
+    """On creation of a BinaryDataObject or PhysicalDataObject's in the context of a simplified
+    profile, add a field to handle the creation of the relation to the archive unit specified in
+    `req.form`.
+    """
+
+    # don't add match_form_params('referenced_by') since it's only specified for creation, not
+    # edition
+    __select__ = (widgets.SimplifiedAutomaticEntityForm.__select__
+                  & is_instance('SEDABinaryDataObject', 'SEDAPhysicalDataObject')
+                  & simplified_profile())
+
+    def inlined_form_views(self):
+        views = list(super(DataObjectSimplifiedAutomaticEntityForm, self).inlined_form_views())
+        ref_forms = [v.form for v in views if v.rtype == 'seda_data_object_reference_id']
+        if ref_forms:  # may be empty if user has no write access
+            ref_form = ref_forms[0]
+            if not ref_form.edited_entity.has_eid() and not ref_form.posting:
+                ref_form.add_hidden(name='seda_data_object_reference', eidparam=True,
+                                    role='subject',
+                                    value=self._cw.form['referenced_by'])
+        return views
+
+
 # SEDADataObjectReference
 simplified_afs.tag_subject_of(
     ('SEDADataObjectReference', 'seda_data_object_reference_id', '*'),
@@ -200,3 +224,13 @@
 simplified_afs.tag_attribute(
     ('SEDADataObjectReference', 'user_cardinality'),
     'inlined', 'hidden')
+
+
+class DataObjectReferenceNoTitleEntityInlinedFormRenderer(widgets.NoTitleEntityInlinedFormRenderer):
+    """Don't display any title nor remove link for DataObjectReference in the context of a
+    simplified profile.
+    """
+
+    __select__ = (widgets.NoTitleEntityInlinedFormRenderer.__select__
+                  & is_instance('SEDADataObjectReference')
+                  & simplified_profile())