Fix tree box title when displayed on a "component" archive unit
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 20 Oct 2016 08:50:29 +0200
changeset 1944 90595e088196
parent 1943 e958e8bd54c6
child 1945 577f41dceb9f
Fix tree box title when displayed on a "component" archive unit To do so, introduce a new "component_unit" selector.
entities/__init__.py
i18n/en.po
i18n/fr.po
views/sedatree.py
--- a/entities/__init__.py	Thu Oct 20 00:11:30 2016 +0200
+++ b/entities/__init__.py	Thu Oct 20 08:50:29 2016 +0200
@@ -73,7 +73,7 @@
     return parent, container
 
 
-def _transfer_from_context(rset, entity):
+def _seda_container_from_context(rset, entity):
     if entity is None:
         entity = rset.one()
     # protect against unrelated entity types
@@ -85,9 +85,18 @@
 
 
 @objectify_predicate
+def component_unit(cls, req, rset=None, entity=None, **kwargs):
+    """Predicate returning 1 score if context entity is within "component" archive unit (i.e.
+    container root is not a SEDAArchiveTransfer but a SEDAArchiveUnit).
+    """
+    entity = _seda_container_from_context(rset, entity)
+    return 1 if entity.cw_etype == 'SEDAArchiveUnit' else 0
+
+
+@objectify_predicate
 def simplified_profile(cls, req, rset=None, entity=None, **kwargs):
     """Predicate returning 1 score if context entity is within a simplified profile."""
-    entity = _transfer_from_context(rset, entity)
+    entity = _seda_container_from_context(rset, entity)
     if entity is None:
         return 0
     if entity.cw_etype == 'SEDAArchiveUnit':
@@ -99,7 +108,7 @@
 @objectify_predicate
 def full_seda2_profile(cls, req, rset=None, entity=None, **kwargs):
     """Predicate returning 1 score if context entity is within a full seda2 profile."""
-    entity = _transfer_from_context(rset, entity)
+    entity = _seda_container_from_context(rset, entity)
     if entity is None:
         return 1
     if entity.cw_etype == 'SEDAArchiveUnit':
--- a/i18n/en.po	Thu Oct 20 00:11:30 2016 +0200
+++ b/i18n/en.po	Thu Oct 20 08:50:29 2016 +0200
@@ -95,6 +95,9 @@
 msgid "An xsd:choice element cannot be empty"
 msgstr ""
 
+msgid "Archive unit component tree"
+msgstr ""
+
 msgid ""
 "Default identifier that will be used to handle references. This is not "
 "necessarily the identifier that will appear in the final sheet."
--- a/i18n/fr.po	Thu Oct 20 00:11:30 2016 +0200
+++ b/i18n/fr.po	Thu Oct 20 08:50:29 2016 +0200
@@ -95,6 +95,9 @@
 msgid "An xsd:choice element cannot be empty"
 msgstr "Une alternative doit contenir au moins un élément"
 
+msgid "Archive unit component tree"
+msgstr "arbre de l'unité d'archive"
+
 msgid ""
 "Default identifier that will be used to handle references. This is not "
 "necessarily the identifier that will appear in the final sheet."
--- a/views/sedatree.py	Thu Oct 20 00:11:30 2016 +0200
+++ b/views/sedatree.py	Thu Oct 20 08:50:29 2016 +0200
@@ -19,12 +19,12 @@
 from cubicweb.predicates import adaptable, is_instance
 from cubicweb.web import component
 
-from cubes.seda.entities import simplified_profile
+from cubes.seda.entities import simplified_profile, component_unit
 from cubes.seda.views import jqtree
 
 
-class SEDAArchiveUnitTree(component.EntityCtxComponent):
-    """Display the whole archive unit tree."""
+class ProfileTreeComponent(component.EntityCtxComponent):
+    """Display the whole profile tree."""
     __regid__ = 'seda.tree'
     __select__ = component.EntityCtxComponent.__select__ & adaptable('ITreeBase')
     context = 'left'
@@ -36,6 +36,11 @@
         self.entity.view('jqtree.treeview', w=w)
 
 
+class UnitTreeComponent(ProfileTreeComponent):
+    __select__ = ProfileTreeComponent.__select__ & component_unit()
+    title = _('Archive unit component tree')
+
+
 class ArchiveTransferIJQTreeAdapter(jqtree.IJQTreeAdapter):
     __select__ = (jqtree.IJQTreeAdapter.__select__
                   & is_instance('SEDAArchiveTransfer') & simplified_profile())