[PATCH 3 of 3 seda v2] [views] Move data object / reference custom form from archiveunit to simplified module

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Oct 11 11:01:13 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507706720 -7200
#      Wed Oct 11 09:25:20 2017 +0200
# Node ID 935cf96e49f3a05e95ff8b2a6f42109181ad7566
# Parent  757262c669cadd9c36b7937f2be100bc0cd002f6
# Available At https://hg.logilab.org/review/cubes/seda
#              hg pull https://hg.logilab.org/review/cubes/seda -r 935cf96e49f3
[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.

diff --git a/cubicweb_seda/views/archiveunit.py b/cubicweb_seda/views/archiveunit.py
--- a/cubicweb_seda/views/archiveunit.py
+++ b/cubicweb_seda/views/archiveunit.py
@@ -1,6 +1,6 @@
-# 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 at logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Lesser General Public License as published by the Free
 # Software Foundation, either version 2.1 of the License, or (at your option)
@@ -1102,41 +1102,7 @@ class ArchiveUnitNoTitleEntityInlinedFor
                                  CONTENT_ETYPE)
                      | (is_instance('SEDAArchiveUnitRefId')
                         & 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')
diff --git a/cubicweb_seda/views/simplified.py b/cubicweb_seda/views/simplified.py
--- a/cubicweb_seda/views/simplified.py
+++ b/cubicweb_seda/views/simplified.py
@@ -1,6 +1,6 @@
-# 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 at logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Lesser General Public License as published by the Free
 # Software Foundation, either version 2.1 of the License, or (at your option)
@@ -20,11 +20,11 @@ from logilab.common.registry import obje
 from cubicweb.predicates import is_instance
 from cubicweb.web.views import uicfg, autoform
 
 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
 
 
 # Add arbitrary score using `yes` to overtake e.g. afs for DataObjectReference defined in content
@@ -191,12 +191,46 @@ for rtype in ('seda_compressed', 'seda_d
 simplified_pvs.tag_object_of(
     ('*', 'seda_date_created_by_application', 'SEDABinaryDataObject'),
     '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', '*'),
     'inlined', 'hidden')
 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())


More information about the saem-devel mailing list