Fix UI to add a data object to a parentless archive unit (aka SEDA component)
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 19 Oct 2016 23:10:51 +0200
changeset 1925 d62432403bed
parent 1924 891700ba269e
child 1926 cbcc11b64d08
Fix UI to add a data object to a parentless archive unit (aka SEDA component) We still rely on the referenced_by trick, simply removing __linkto information. This is the quickest way to make it work, because customizing data reference to inline the binary data object for is painful (among other, this is an ambiguous relation which isn't supported by inlined forms). The main known drawback is that the form's title is contextless.
entities/__init__.py
views/archiveunit.py
--- a/entities/__init__.py	Fri Oct 21 17:05:45 2016 +0200
+++ b/entities/__init__.py	Wed Oct 19 23:10:51 2016 +0200
@@ -56,6 +56,10 @@
                 if 'sedaContainerEID' in req.form:
                     container = req.entity_from_eid(int(req.form['sedaContainerEID']))
                     return None, container
+                if 'referenced_by' in req.form:
+                    entity = req.entity_from_eid(int(req.form['referenced_by']))
+                    container = entity.cw_adapt_to('IContained').container
+                    return None, container
                 # unable to get parent eid for now :(
                 return None, None
         parent = req.entity_from_eid(parent_eid)
--- a/views/archiveunit.py	Fri Oct 21 17:05:45 2016 +0200
+++ b/views/archiveunit.py	Wed Oct 19 23:10:51 2016 +0200
@@ -30,7 +30,7 @@
 from cubes.seda.entities import simplified_profile, parent_and_container
 from cubes.seda.entities.itree import parent_archive_unit
 from cubes.seda.views import (add_subobject_link, add_subobjects_button, dropdown_button,
-                              rtags_from_rtype_role_targets, copy_rtag)
+                              rtags_from_rtype_role_targets, copy_rtag, has_rel_perm)
 from cubes.seda.views import clone, viewlib, widgets, content
 from cubes.seda.views import uicfg as sedauicfg  # noqa - ensure those rules are defined first
 
@@ -423,7 +423,18 @@
         params = self.url_params(entity)
         params['referenced_by'] = text_type(entity.eid)
         transfer = entity.container[0]
-        button = add_subobjects_button(transfer, rtype_roles, params)
+        if transfer.cw_etype == 'SEDAArchiveTransfer':
+            button = add_subobjects_button(transfer, rtype_roles, params)
+        else:
+            if has_rel_perm('add', entity, 'seda_data_object_reference', 'object'):
+                vreg = self._cw.vreg
+                url = vreg['etypes'].etype_class('SEDABinaryDataObject').cw_create_url(
+                    self._cw, **params)
+                msg = self._cw.__('seda_binary_data_object_object')
+                link = tags.a(msg, href=url, title=self._cw.__('New SEDABinaryDataObject'))
+                button = dropdown_button(entity._cw._(msg), [link])
+            else:
+                button = None
         if button:
             # No button if user cannot add any relation.
             self.w(button)