[saem-devel] [PATCH 7 of 9] [org] Move organization unit's generic code above its tabs definition

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Jan 27 16:02:55 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1485331604 -3600
#      Wed Jan 25 09:06:44 2017 +0100
# Node ID dbd4241c585447fbf7d1138aeb977e4db0d1cf94
# Parent  592c2f80165a8f3f2eb84229a2a652b252c7ed33
[org] Move organization unit's generic code above its tabs definition

It will be a better organization once shared with authority record tab.

diff --git a/cubicweb_saem_ref/views/org.py b/cubicweb_saem_ref/views/org.py
--- a/cubicweb_saem_ref/views/org.py
+++ b/cubicweb_saem_ref/views/org.py
@@ -132,40 +132,10 @@ class OrganizationRelatedAgentListView(O
     _('creating OrganizationUnit (OrganizationUnit authority Organization %(linkto)s)')
 
 
 # OrganizationUnit
 
-pvs.tag_subject_of(('OrganizationUnit', 'archival_role', '*'), 'attributes')
-afs.tag_subject_of(('OrganizationUnit', 'archival_role', '*'), 'main', 'attributes')
-afs.tag_object_of(('*', 'archival_unit', 'OrganizationUnit'), 'main', 'hidden')
-# archival_role is used in constraints for archival_agent and use_profile relations
-rdc.tag_attribute(('OrganizationUnit', 'archival_role'), {'reload': True})
-pvs.tag_subject_of(('OrganizationUnit', 'contact_point', '*'), 'attributes')
-afs.tag_subject_of(('OrganizationUnit', 'contact_point', '*'), 'main', 'attributes')
-
-pvs.tag_subject_of(('*', 'related_concept_scheme', '*'), 'hidden')
-afs.tag_subject_of(('*', 'related_concept_scheme', '*'), 'main', 'hidden')
-pvs.tag_object_of(('*', 'related_concept_scheme', '*'), 'hidden')
-afs.tag_object_of(('*', 'related_concept_scheme', '*'), 'main', 'hidden')
-abaa.tag_object_of(('*', 'related_concept_scheme', '*'), False)
-
-for rtype in ('use_profile', 'use_authorityrecord'):
-    pvs.tag_subject_of(('*', rtype, '*'), 'hidden')
-    afs.tag_subject_of(('*', rtype, '*'), 'main', 'hidden')
-    abaa.tag_subject_of(('*', rtype, '*'), False)
-
-
-class OrganizationUnitTabbedPrimaryView(tabs.TabbedPrimaryView):
-    """Tabbed primary view for OrganizationUnit"""
-    __select__ = tabs.TabbedPrimaryView.__select__ & is_instance('OrganizationUnit')
-    tabs = [
-        'main_tab',
-        _('saem_ou_concepts_profiles_tab'),
-        _('saem_ou_authorityrecords_tab'),
-    ]
-
-
 class LinkedObjectsTab(SubviewsTabView):
     """Abstract class for tab displaying objects related through non-composite relation.
 
     Parametrized using:
 
@@ -233,23 +203,29 @@ class RTypeListView(RelatedEntitiesListV
         entity = self.cw_rset.one()
         return {'unit': entity, '__redirectpath': entity.rest_path(),
                 'rtype': self.rtype, 'role': self.role}
 
 
-class DepositOrganizationUnitConceptsProfilesTab(LinkedObjectsTab):
-    """SEDA profiles and concept schemes used by an organization unit with role "deposit"."""
-    __regid__ = 'saem_ou_concepts_profiles_tab'
-    __select__ = EntityView.__select__ & is_instance('OrganizationUnit')
-    required_role = 'deposit'
-    not_possible_msg = _("You can't add profiles or concept schemes to organization unit "
-                         "without the 'deposit' role.")
-    link_targets = [('SEDAArchiveTransfer', 'use_profile', 'subject'),
-                    ('ConceptScheme', 'related_concept_scheme', 'subject')]
-    subvids = (
-        'saem.ou.schemes',
-        'saem.ou.profiles',
-    )
+class OrganizationUnitUsingListItemView(EntityView):
+    """Extended 'oneline' view for entities related to an organization unit, including link to
+    remove the relation.
+    """
+    __regid__ = 'saem.listitem'
+    __select__ = EntityView.__select__ & match_kwargs('unit', 'rtype', 'role')
+
+    # XXX usually expect role to be the role of the entity, here it's the role of the organization
+    # unit
+    def entity_call(self, entity, unit, rtype, role, **editurlparams):
+        entity.view('outofcontext', w=self.w)
+        if has_rel_perm('delete', unit, rtype, role, target_entity=entity):
+            self._cw.add_js(('cubicweb.ajax.js', 'cubes.saem_ref.js'))
+            self.w(u'<div class="pull-right">')
+            jscall = js.saem.ajaxRemoveRelation(unit.eid, entity.eid, rtype, role,
+                                                'saem_ou_concepts_profiles_tab')
+            self.w(tags.a(title=self._cw._('delete'), klass='icon-trash',
+                          href='javascript: %s' % jscall))
+            self.w(u'</div>')
 
 
 class OrganizationUnitSearchForRelatedEntitiesView(rwdg.SearchForRelatedEntitiesView):
     __select__ = (rwdg.SearchForRelatedEntitiesView.__select__
                   & (rwdg.edited_relation('use_profile')
@@ -275,10 +251,55 @@ def add_relations(self, eid, rtype, role
     for related_eid in related_eids:
         self._cw.execute(rql, {'eids': eid if role == 'subject' else int(related_eid),
                                'eido': eid if role == 'object' else int(related_eid)})
 
 
+pvs.tag_subject_of(('OrganizationUnit', 'archival_role', '*'), 'attributes')
+afs.tag_subject_of(('OrganizationUnit', 'archival_role', '*'), 'main', 'attributes')
+afs.tag_object_of(('*', 'archival_unit', 'OrganizationUnit'), 'main', 'hidden')
+# archival_role is used in constraints for archival_agent and use_profile relations
+rdc.tag_attribute(('OrganizationUnit', 'archival_role'), {'reload': True})
+pvs.tag_subject_of(('OrganizationUnit', 'contact_point', '*'), 'attributes')
+afs.tag_subject_of(('OrganizationUnit', 'contact_point', '*'), 'main', 'attributes')
+
+pvs.tag_subject_of(('*', 'related_concept_scheme', '*'), 'hidden')
+afs.tag_subject_of(('*', 'related_concept_scheme', '*'), 'main', 'hidden')
+pvs.tag_object_of(('*', 'related_concept_scheme', '*'), 'hidden')
+afs.tag_object_of(('*', 'related_concept_scheme', '*'), 'main', 'hidden')
+abaa.tag_object_of(('*', 'related_concept_scheme', '*'), False)
+
+for rtype in ('use_profile', 'use_authorityrecord'):
+    pvs.tag_subject_of(('*', rtype, '*'), 'hidden')
+    afs.tag_subject_of(('*', rtype, '*'), 'main', 'hidden')
+    abaa.tag_subject_of(('*', rtype, '*'), False)
+
+
+class OrganizationUnitTabbedPrimaryView(tabs.TabbedPrimaryView):
+    """Tabbed primary view for OrganizationUnit"""
+    __select__ = tabs.TabbedPrimaryView.__select__ & is_instance('OrganizationUnit')
+    tabs = [
+        'main_tab',
+        _('saem_ou_concepts_profiles_tab'),
+        _('saem_ou_authorityrecords_tab'),
+    ]
+
+
+class DepositOrganizationUnitConceptsProfilesTab(LinkedObjectsTab):
+    """SEDA profiles and concept schemes used by an organization unit with role "deposit"."""
+    __regid__ = 'saem_ou_concepts_profiles_tab'
+    __select__ = EntityView.__select__ & is_instance('OrganizationUnit')
+    required_role = 'deposit'
+    not_possible_msg = _("You can't add profiles or concept schemes to organization unit "
+                         "without the 'deposit' role.")
+    link_targets = [('SEDAArchiveTransfer', 'use_profile', 'subject'),
+                    ('ConceptScheme', 'related_concept_scheme', 'subject')]
+    subvids = (
+        'saem.ou.schemes',
+        'saem.ou.profiles',
+    )
+
+
 class OrganizationUnitUsingConceptSchemeListView(RTypeListView):
     """View for ConceptScheme, to be displayed in the context of an organization unit."""
     __regid__ = 'saem.ou.schemes'
     rtype = 'related_concept_scheme'
     role = 'subject'
@@ -289,31 +310,10 @@ class RelatedSEDAArchiveTransferListView
     __regid__ = 'saem.ou.profiles'
     rtype = 'use_profile'
     role = 'subject'
 
 
-class OrganizationUnitUsingListItemView(EntityView):
-    """Extended 'oneline' view for entities related to an organization unit, including link to
-    remove the relation.
-    """
-    __regid__ = 'saem.listitem'
-    __select__ = EntityView.__select__ & match_kwargs('unit', 'rtype', 'role')
-
-    # XXX usually expect role to be the role of the entity, here it's the role of the organization
-    # unit
-    def entity_call(self, entity, unit, rtype, role, **editurlparams):
-        entity.view('outofcontext', w=self.w)
-        if has_rel_perm('delete', unit, rtype, role, target_entity=entity):
-            self._cw.add_js(('cubicweb.ajax.js', 'cubes.saem_ref.js'))
-            self.w(u'<div class="pull-right">')
-            jscall = js.saem.ajaxRemoveRelation(unit.eid, entity.eid, rtype, role,
-                                                'saem_ou_concepts_profiles_tab')
-            self.w(tags.a(title=self._cw._('delete'), klass='icon-trash',
-                          href='javascript: %s' % jscall))
-            self.w(u'</div>')
-
-
 class OrganizationUnitAuthorityRecordsTab(LinkedObjectsTab):
     """Authority records used by this organization unit."""
     __regid__ = 'saem_ou_authorityrecords_tab'
     __select__ = EntityView.__select__ & relation_possible('use_authorityrecord')
     required_role = 'archival'


More information about the saem-devel mailing list