[PATCH 4 of 9 seda] [views] UI to edit file_category instead of format_id / mime_type relations

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Oct 12 16:59:49 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507727763 -7200
#      Wed Oct 11 15:16:03 2017 +0200
# Node ID 1ef4f5936c15d72393a0938e680f58e05912d5ca
# Parent  5b3ec7300aaec6a5c726b8c952db4bb4605f0b5e
# Available At https://hg.logilab.org/review/cubes/seda
#              hg pull https://hg.logilab.org/review/cubes/seda -r 1ef4f5936c15
[views] UI to edit file_category instead of format_id / mime_type relations

Do it minimal with no js involved but a simple multiple select. This still have
to be coupled to format_id / mime_type but this will be done in later csets.

Related to #36331831

diff --git a/cubicweb_seda/views/dataobject.py b/cubicweb_seda/views/dataobject.py
--- a/cubicweb_seda/views/dataobject.py
+++ b/cubicweb_seda/views/dataobject.py
@@ -117,10 +117,12 @@ pvdc.tag_object_of(('*', 'seda_data_obje
                     'subvid': 'seda.object-ref.archive-unit',
                     'label': _('referenced by:')})
 
 pvs.tag_subject_of(('*', 'seda_algorithm', '*'), 'attributes')
 pvs.tag_object_of(('*', 'seda_target', '*'), 'hidden')  # in the relationship tab
+# hide file_category from the main tab, it lives in the format tab
+pvs.tag_subject_of(('SEDABinaryDataObject', 'file_category', '*'), 'hidden')
 
 for rtype in ('seda_compressed', 'seda_data_object_version_from'):
     # hide relation from autoform because of limitation of _container_eid
     afs.tag_object_of(('*', rtype, '*'), 'main', 'hidden')
     pvs.tag_object_of(('*', rtype, '*'), 'attributes')
@@ -180,27 +182,63 @@ class BinaryDataObjectTabbedPrimaryView(
         _('seda_bdo_file_information'),
         _('seda_do_relations'),
     ]
 
 
+def _setup_format_tab(rsection, display_ctrl):
+    # hide format_id / mime_type, in favor of custom 'file_category'. Actual
+    # format_id and mime_type will be derived from that value (XXX hook or profile
+    # gen time ?)
+    rsection.tag_object_of(('*', 'seda_format_id_from', 'SEDABinaryDataObject'), 'hidden')
+    rsection.tag_object_of(('*', 'seda_mime_type_from', 'SEDABinaryDataObject'), 'hidden')
+    rsection.tag_subject_of(('SEDABinaryDataObject', 'file_category', '*'), 'attributes')
+    # dunno why it crashes without this
+    display_ctrl.tag_subject_of(('SEDABinaryDataObject', 'file_category', '*'), {'order': 0})
+
+
 class BinaryDataObjectFormatIdentificationTab(viewlib.PrimaryTabWithoutBoxes):
     """Display format identification information of a binary data object"""
 
     __regid__ = 'seda_bdo_format_identification'
     __select__ = is_instance('SEDABinaryDataObject')
 
     rsection, display_ctrl = rtags_from_xsd_element('SEDABinaryDataObject', 'FormatIdentification')
+    _setup_format_tab(rsection, display_ctrl)
 
 
 class SimplifiedBinaryDataObjectFormatIdentificationTab(BinaryDataObjectFormatIdentificationTab):
 
     __select__ = BinaryDataObjectFormatIdentificationTab.__select__ & simplified_profile()
 
     rsection, display_ctrl = rtags_from_xsd_element('SEDABinaryDataObject', 'FormatIdentification')
+    _setup_format_tab(rsection, display_ctrl)
     rsection.tag_object_of(('*', 'seda_format_litteral', 'SEDABinaryDataObject'), 'hidden')
 
 
+def file_category_vocabulary(form, field):
+    rset = form._cw.execute(
+        'Any C,CLL,E,ELL ORDERBY CLL,ELL WHERE '
+        'C in_scheme CS, CS scheme_relation_type CR, CR name "file_category", '
+        'NOT C broader_concept SC, E broader_concept C, '
+        'CL label_of C, CL label CLL,'
+        'EL label_of E, EL label ELL'
+    )
+    values = []
+    current_category = None
+    for category, category_label, extension, extension_label in rset:
+        if current_category is None or current_category != category:
+            current_category = category
+            values.append((category_label, str(category)))
+        values.append((u'{} > {}'.format(category_label, extension_label),
+                       str(extension)))
+    return values
+
+
+affk.tag_subject_of(('SEDABinaryDataObject', 'file_category', '*'),
+                    {'choices': file_category_vocabulary})
+
+
 class BinaryDataObjectFileInfoTab(viewlib.PrimaryTabWithoutBoxes):
     """Display file information of a binary data object"""
 
     __regid__ = 'seda_bdo_file_information'
     __select__ = is_instance('SEDABinaryDataObject') & full_seda2_profile()


More information about the saem-devel mailing list