Reimplement view displaying alternatives of a typed reference
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 06 Jan 2017 14:17:43 +0100
changeset 2226 58b4ad23290e
parent 2225 f905983dfc5e
child 2227 ac4a8c9b5e95
Reimplement view displaying alternatives of a typed reference The old view has been broken for a while (not selected anymore, can't explain why right now), reimplement it on the proper entity types and using `viewlib.alternative_values` function.
views/content.py
--- a/views/content.py	Fri Jan 06 14:11:23 2017 +0100
+++ b/views/content.py	Fri Jan 06 14:17:43 2017 +0100
@@ -279,6 +279,26 @@
     _('creating SEDAReferences (SEDAReferences seda_references SEDAContent %(linkto)s)')
 
 
+class ReferenceListItemContentView(viewlib.ListItemContentView):
+    __select__ = is_instance('SEDAIsVersionOf', 'SEDAReplaces', 'SEDARequires', 'SEDAIsPartOf',
+                             'SEDAReferences')
+
+    def entity_call(self, entity):
+        self.w(u'<b>{} '.format(entity.dc_type()))
+        entity.view('seda.xsdmeta')
+        self.w(u'</b> :')
+        alt_rtype = 'seda_alt_{}_archive_unit_ref_id'.format(un_camel_case(entity.cw_etype[4:]))
+        alt = entity.related(alt_rtype).one()
+        alternatives = viewlib.alternative_values(alt, alt_rtype)
+        self.w(u'<div class="value alternative">')
+        if alternatives:
+            self.w(alternatives)
+        else:
+            self.wdata(self._cw._('<no value specified>'))
+        self.w(u'</div>')
+        self.w(u'<div class="clearfix"/>')
+
+
 class ContentEventTab(viewlib.SubObjectsTab):
     """Display events about an archive unit content."""
 
@@ -359,32 +379,6 @@
                                 'SEDAAltRequiresArchiveUnitRefId')
 
 
-class BusinessValueLinkedEntityView(viewlib.BusinessValueEntityView):
-
-    __select__ = is_instance(*TYPED_REFERENCE_ENTITY_TYPES)
-
-    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)
-
-
 do_ref_afs = copy_rtag(afs, __name__,
                        is_instance('SEDADataObjectReference') & is_typed_reference())
 do_ref_afs.tag_attribute(('SEDADataObjectReference', 'user_cardinality'), 'main', 'hidden')