Move latest content's tab to archive unit
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 11 Jan 2017 21:30:05 +0100
changeset 2299 21132e4f9132
parent 2298 999e4cf6efe9
child 2300 b37082098c56
Move latest content's tab to archive unit i.e. the tab displaying content information which is not yet displayed by other tab (mainly controlled by uicfg rules). Move there pre-existing code in the same module, for the case of simplified profiles. Related to #16684017
i18n/en.po
i18n/fr.po
views/archiveunit.py
--- a/i18n/en.po	Wed Jan 11 14:14:32 2017 +0100
+++ b/i18n/en.po	Wed Jan 11 21:30:05 2017 +0100
@@ -5292,9 +5292,6 @@
 msgid "seda_attachment_object"
 msgstr ""
 
-msgid "seda_au_content_tab"
-msgstr ""
-
 msgid "seda_au_data_objects_refs_tab"
 msgstr ""
 
@@ -5476,6 +5473,9 @@
 msgid "seda_compression_algorithm_code_list_version_to_object"
 msgstr ""
 
+msgid "seda_content_main_tab"
+msgstr ""
+
 msgid "seda_coverage_tab"
 msgstr ""
 
--- a/i18n/fr.po	Wed Jan 11 14:14:32 2017 +0100
+++ b/i18n/fr.po	Wed Jan 11 21:30:05 2017 +0100
@@ -5313,9 +5313,6 @@
 msgid "seda_attachment_object"
 msgstr ""
 
-msgid "seda_au_content_tab"
-msgstr "contenu"
-
 msgid "seda_au_data_objects_refs_tab"
 msgstr "objets-données"
 
@@ -5497,6 +5494,9 @@
 msgid "seda_compression_algorithm_code_list_version_to_object"
 msgstr ""
 
+msgid "seda_content_main_tab"
+msgstr "contenu"
+
 msgid "seda_coverage_tab"
 msgstr "couverture"
 
--- a/views/archiveunit.py	Wed Jan 11 14:14:32 2017 +0100
+++ b/views/archiveunit.py	Wed Jan 11 21:30:05 2017 +0100
@@ -37,12 +37,6 @@
 from . import uicfg as sedauicfg  # noqa - ensure those rules are defined first
 
 
-afs = uicfg.autoform_section
-affk = uicfg.autoform_field_kwargs
-pvs = uicfg.primaryview_section
-rec = uicfg.reledit_ctrl
-
-
 @objectify_predicate
 def is_archive_unit_ref(cls, req, rset=None, entity=None, **kwargs):
     """Return 1 if a unit_type value is specified in kwargs or in form parameters, and its value is
@@ -73,6 +67,35 @@
         return 0 if entity.content_sequence else 1
 
 
+@objectify_predicate
+def is_typed_reference(cls, req, entity=None, **kwargs):
+    """Return positive score for content's typed data object references (IsPartOf, VersionOf, etc.), not
+    those starting directly from archive unit.
+    """
+    if entity is None or not entity.has_eid():
+        try:
+            rtype, eid, role = req.form['__linkto'].split(':')
+        except KeyError:
+            pass
+        else:
+            if rtype == 'seda_data_object_reference':
+                entity = req.entity_from_eid(eid)
+            else:
+                return 0
+    else:
+        entity = entity.seda_data_object_reference[0]
+    if entity is not None and entity.cw_etype == CONTENT_ETYPE:
+        return 0
+    return 1
+
+
+afs = uicfg.autoform_section
+affk = uicfg.autoform_field_kwargs
+pvs = uicfg.primaryview_section
+pvdc = uicfg.primaryview_display_ctrl
+rec = uicfg.reledit_ctrl
+
+
 def unit_ref_vocabulary(form, field):
     """Form vocabulary function for archive unit references, necessary to get parent container while
     the entity is being created.
@@ -198,10 +221,10 @@
     tabs = [
         'main_tab',
         _('seda_management_tab'),
-        _('seda_au_content_tab'),
         _('seda_archive_units_tab'),
         _('seda_au_data_objects_refs_tab'),
         # Content tabs
+        _('seda_content_main_tab'),
         _('seda_identification_tab'),
         _('seda_restriction_tab'),
         _('seda_dates_tab'),
@@ -241,6 +264,8 @@
                               w=self.w)
 
 
+# management tab ###############################################################
+
 class ArchiveUnitManagementTab(viewlib.PrimaryTabWithoutBoxes):
     """Display management information about an archive unit."""
 
@@ -277,39 +302,6 @@
     )
 
 
-class SimplifiedArchiveUnitContentTab(tabs.TabsMixin, EntityView):
-    """Display content information about an archive unit of a simplified profile: direct link to
-    some content's attributes.
-    """
-
-    __regid__ = 'seda_au_content_tab'
-    __select__ = ArchiveUnitSubObjectsTab.__select__ & simplified_profile()
-
-    def entity_call(self, entity):
-        seq = entity.first_level_choice.content_sequence
-        seq.view('seda.simplified_au_content', w=self.w)
-
-
-class SimplifiedArchiveUnitContentView(viewlib.PrimaryTabWithoutBoxes):
-    """Content view underlying SimplifiedArchiveUnitContentTab."""
-
-    __regid__ = 'seda.simplified_au_content'
-    __select__ = is_instance(CONTENT_ETYPE)
-
-    rtype_role_targets = [
-        ('seda_description_level', 'subject', None),
-        ('seda_title', 'object', None),
-        ('seda_start_date', 'object', None),
-        ('seda_end_date', 'object', None),
-        ('seda_description', 'object', None),
-        ('seda_originating_agency_from', 'object', None),
-        ('seda_transferring_agency_archive_unit_identifier', 'object', None),
-        ('seda_system_id', 'object', None),
-        ('seda_language_from', 'object', None),
-    ]
-    rsection, display_ctrl = rtags_from_rtype_role_targets(CONTENT_ETYPE, rtype_role_targets)
-
-
 # identification tab ###########################################################
 
 class ArchiveUnitIdentificationTab(ArchiveUnitContentTab):
@@ -743,6 +735,97 @@
                 self.w(self._cw._(' (optional timestamp)'))
 
 
+# content main tab #############################################################
+
+class ArchiveUnitContentMainTab(ArchiveUnitContentTab):
+    """Display content information which are not in a dedicated tab for an archive unit."""
+
+    __regid__ = 'seda_content_main_tab'
+    content_vid = 'seda_content_main'
+
+
+class ContentMainView(viewlib.PrimaryTabWithoutBoxes):
+    """Display content information which are not in a dedicated tab."""
+
+    __regid__ = 'seda_content_main'
+    __select__ = is_instance(CONTENT_ETYPE)
+
+
+class SimplifiedContentMainView(ContentMainView):
+    """Display content information which are not in a dedicated tab for a simplified archive unit.
+    """
+    __select__ = ContentMainView.__select__ & simplified_profile()
+
+    rtype_role_targets = [
+        ('seda_description_level', 'subject', None),
+        ('seda_title', 'object', None),
+        ('seda_start_date', 'object', None),
+        ('seda_end_date', 'object', None),
+        ('seda_description', 'object', None),
+        ('seda_originating_agency_from', 'object', None),
+        ('seda_transferring_agency_archive_unit_identifier', 'object', None),
+        ('seda_system_id', 'object', None),
+        ('seda_language_from', 'object', None),
+    ]
+    rsection, display_ctrl = rtags_from_rtype_role_targets(CONTENT_ETYPE, rtype_role_targets)
+
+
+content_ordered_fields = [
+    ('seda_description_level', 'subject'),
+    ('seda_title', 'object'),
+    ('seda_description', 'object'),
+    ('seda_version', 'object'),
+    ('seda_type_from', 'object'),
+    ('seda_document_type', 'object'),
+    ('seda_status', 'object'),
+    ('seda_language_from', 'object'),
+    ('seda_description_language_from', 'object'),
+]
+for rtype, role in content_ordered_fields:
+    if role == 'subject':
+        pvs.tag_subject_of((CONTENT_ETYPE, rtype, '*'), 'attributes')
+    else:
+        pvs.tag_object_of(('*', rtype, CONTENT_ETYPE), 'attributes')
+    if rtype == 'seda_description_level':
+        novalue_label = _('<no value specified>')
+    else:
+        novalue_label = _('<unauthorized>')
+    vid = 'seda.reledit.complexlink' if 'language' in rtype else 'seda.reledit.text'
+    if role == 'subject':
+        rec.tag_subject_of((CONTENT_ETYPE, rtype, '*'),
+                           {'rvid': vid, 'novalue_label': novalue_label})
+    else:
+        rec.tag_object_of(('*', rtype, CONTENT_ETYPE),
+                          {'rvid': vid, 'novalue_label': novalue_label})
+
+pvs.tag_object_of(('*', 'seda_seq_alt_archive_unit_archive_unit_ref_id_management', '*'), 'hidden')
+
+affk.tag_subject_of(('SEDALanguage', 'seda_language_to', '*'),
+                    {'widget': rwdg.RelationFacetWidget})
+affk.tag_subject_of(('SEDADescriptionLanguage', 'seda_description_language_to', '*'),
+                    {'widget': rwdg.RelationFacetWidget})
+
+affk.set_fields_order(CONTENT_ETYPE,
+                      ['user_cardinality', 'user_annotation'] + content_ordered_fields)
+pvdc.set_fields_order(CONTENT_ETYPE,
+                      ['user_cardinality', 'user_annotation'] + content_ordered_fields)
+
+# remove from relations section and autoform what is shown in tabs
+for cls in (ContentIdentificationView,
+            ContentDatesView,
+            ContentServicesView,
+            ContentAgentsView,
+            ContentIndexationView,
+            ContentEventsView):
+    for rtype, role, target in cls.rtype_role_targets:
+        if role == 'object':
+            pvs.tag_object_of(('*', rtype, CONTENT_ETYPE), 'hidden')
+            afs.tag_object_of(('*', rtype, CONTENT_ETYPE), 'main', 'hidden')
+        else:
+            pvs.tag_subject_of((CONTENT_ETYPE, rtype, '*'), 'hidden')
+            afs.tag_subject_of((CONTENT_ETYPE, rtype, '*'), 'main', 'hidden')
+
+
 # archive units tab ############################################################
 
 class ArchiveUnitArchiveUnitsTab(tabs.TabsMixin, EntityView):
@@ -789,6 +872,8 @@
     sub_unit_types = [('unit_content', _('seda_archive_unit_object'))]
 
 
+# data objects tab #############################################################
+
 class ArchiveUnitDataObjectReferencesTab(ArchiveUnitSubObjectsTab):
     """Tab for data object references of an archive unit"""
 
@@ -843,6 +928,8 @@
                           subvid=self.subvid, tabid=self.tabid)
 
 
+# reference / content archive unit forms #######################################
+
 # Top level ArchiveUnit form: create to distinct forms, one form archive unit reference and the
 # other for archive unit content. This is done by a mix of uicfg, form and renderer customization
 # depending on a 'unit_type' parameter in form params.