[ui] Add business value view for the various kinds of relation
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 12 Jul 2016 10:11:13 +0200
changeset 1409 19dd7d28374c
parent 1408 7555792af428
child 1410 f15e2d29131d
[ui] Add business value view for the various kinds of relation
views/content.py
--- a/views/content.py	Tue Jul 12 09:58:32 2016 +0200
+++ b/views/content.py	Tue Jul 12 10:11:13 2016 +0200
@@ -22,6 +22,7 @@
 
 from cubes.relationwidget.views import RelationFacetWidget
 
+from cubes.seda.xsd import un_camel_case
 from cubes.seda.views import rtags_from_rtype_role_targets, rtags_from_xsd_element
 from cubes.seda.views import viewlib, widgets
 from cubes.seda.views import uicfg as sedauicfg  # noqa - ensure those rules are defined first
@@ -315,3 +316,30 @@
             else:
                 msg = xml_escape(self._cw._('<no reference specified>'))
             self.w(u'<br/><span>{0} {1}</span>'.format(msg, kwr.view('seda.xsdmeta')))
+
+
+class BusinessValueLinkedEntityView(viewlib.BusinessValueEntityView):
+    __select__ = is_instance('SEDAIsVersionOf', 'SEDAIsPartOf',
+                             'SEDAReplaces', 'SEDARequires',
+                             'SEDAReferences')
+
+    def entity_value(self, entity):
+        alt_rtype = (un_camel_case(entity.cw_etype).replace('seda_', 'seda_alt_')
+                     + '_archive_unit_ref_id')
+        alt = getattr(entity, alt_rtype)[0]
+        alternatives = []
+        for rtype, value_rtype in (
+                ('seda_data_object_reference', 'seda_data_object_reference_id'),
+                ('seda_archive_unit_ref_id_from', 'seda_archive_unit_ref_id_to'),
+                ('seda_repository_archive_unit_pid', None),
+                ('seda_repository_object_pid', None)):
+            value = alt.related(rtype, role='object')
+            if value:
+                value = value.one()
+                target_value = getattr(value, value_rtype) if value_rtype else None
+                if target_value:
+                    content = target_value[0].view('oneline')
+                else:
+                    content = xml_escape(self._cw._('<no value specified>'))
+                alternatives.append(value.dc_type() + ' ' + content)
+        return (u'<b>{0}</b>'.format(self._cw._(' ALT_I18N '))).join(alternatives)