[ui] Configure list item view for events
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 13 Jul 2016 09:37:10 +0200
changeset 1420 c18e9eec211e
parent 1419 010bc985bc6e
child 1421 4a761cdede9a
[ui] Configure list item view for events with nicer and consistent ordering w/ autoform.
i18n/en.po
i18n/fr.po
views/content.py
--- a/i18n/en.po	Tue Jul 12 16:22:42 2016 +0200
+++ b/i18n/en.po	Wed Jul 13 09:37:10 2016 +0200
@@ -4344,6 +4344,9 @@
 msgid "keyword_content"
 msgstr ""
 
+msgid "mandatory"
+msgstr ""
+
 msgctxt "Agent"
 msgid "name"
 msgstr ""
@@ -4365,6 +4368,9 @@
 msgid "need_reassessing_authorization"
 msgstr ""
 
+msgid "optional"
+msgstr ""
+
 msgid "originating_agency_archive_unit_identifier"
 msgstr ""
 
--- a/i18n/fr.po	Tue Jul 12 16:22:42 2016 +0200
+++ b/i18n/fr.po	Wed Jul 13 09:37:10 2016 +0200
@@ -4352,6 +4352,9 @@
 msgid "keyword_content"
 msgstr ""
 
+msgid "mandatory"
+msgstr "obligatoire"
+
 msgctxt "Agent"
 msgid "name"
 msgstr ""
@@ -4373,6 +4376,9 @@
 msgid "need_reassessing_authorization"
 msgstr ""
 
+msgid "optional"
+msgstr "optionnel"
+
 msgid "originating_agency_archive_unit_identifier"
 msgstr "valeur"
 
--- a/views/content.py	Tue Jul 12 16:22:42 2016 +0200
+++ b/views/content.py	Wed Jul 13 09:37:10 2016 +0200
@@ -385,6 +385,39 @@
                                   ('seda_repository_archive_unit_pid', 'object')])
 
 
+class EventLinkMetaEntityView(viewlib.LinkMetaEntityView):
+    __select__ = viewlib.LinkMetaEntityView.__select__ & is_instance('SEDAEvent')
+
+    def entity_call(self, entity):
+        entity.view('seda.xsdmeta', w=self.w, skip_one_card=True)
+        attrs = []
+        for rtype in ['seda_event_type_from',
+                      'seda_event_identifier',
+                      'seda_event_detail']:
+            related = getattr(entity, 'reverse_' + rtype)
+            if related:
+                if related[0].user_cardinality == '1':
+                    card = self._cw._('mandatory')
+                else:
+                    card = self._cw._('optional')
+                value = ''
+                if rtype == 'seda_event_type_from':
+                    value = related[0].seda_event_type_to
+                    if value:
+                        value = value[0].label()
+                attrs.append(u'{rtype} {value} {card}'.format(rtype=self._cw.__(rtype + '_object'),
+                                                              value=value,
+                                                              card=card))
+        if attrs:
+            self.w(u' ({0})'.format(', '.join(attrs)))
+
+
+affk.set_fields_order('SEDAEvent', ['user_cardinality',
+                                    ('seda_event_type_from', 'object'),
+                                    ('seda_event_identifier', 'object'),
+                                    ('seda_event_detail', 'object')])
+
+
 class CustodialHistoryItemLinkMetaEntityView(viewlib.LinkMetaEntityView):
     __select__ = viewlib.LinkMetaEntityView.__select__ & is_instance('SEDACustodialHistoryItem')