[PATCH 1 of 5 saem_ref] Add an "index" attribute to Mandate and AgentFunction

Frank Bessou frank.bessou at logilab.fr
Tue Sep 25 12:03:09 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1537352930 -7200
#      Wed Sep 19 12:28:50 2018 +0200
# Node ID 975f4a115ea61e901ba4d88bb264cb6f833ab0e8
# Parent  40f49de273745dac84f6984d9fe0286437a8beb8
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 975f4a115ea6
# EXP-Topic CONSEJIRA-578-584
Add an "index" attribute to Mandate and AgentFunction

We want to be able to sort mandates and functions of related to a given
autority record. So introduce an index to keep track of respective
position.

We hide this attribute from primary view and autoform since it is meant
to be managed by a hook or a dedicated UI logic (to be implemented in
forthcoming patches).

CONSEJIRA-578, CONSEJIRA-584.

diff --git a/cubicweb_saem_ref/i18n/en.po b/cubicweb_saem_ref/i18n/en.po
--- a/cubicweb_saem_ref/i18n/en.po
+++ b/cubicweb_saem_ref/i18n/en.po
@@ -690,6 +690,22 @@ msgctxt "SEDAArchiveTransfer"
 msgid "generated_object"
 msgstr ""
 
+msgid "index"
+msgstr ""
+
+msgctxt "AgentFunction"
+msgid "index"
+msgstr ""
+
+msgctxt "Mandate"
+msgid "index"
+msgstr ""
+
+msgid ""
+"index of entity as an item of the collection of similar entities related to "
+"a given authority record"
+msgstr ""
+
 msgid "latest update on"
 msgstr ""
 
diff --git a/cubicweb_saem_ref/i18n/fr.po b/cubicweb_saem_ref/i18n/fr.po
--- a/cubicweb_saem_ref/i18n/fr.po
+++ b/cubicweb_saem_ref/i18n/fr.po
@@ -711,6 +711,24 @@ msgctxt "SEDAArchiveTransfer"
 msgid "generated_object"
 msgstr ""
 
+msgid "index"
+msgstr "indice"
+
+msgctxt "AgentFunction"
+msgid "index"
+msgstr ""
+
+msgctxt "Mandate"
+msgid "index"
+msgstr ""
+
+msgid ""
+"index of entity as an item of the collection of similar entities related to "
+"a given authority record"
+msgstr ""
+"indice de l'entité en tant qu'élément d'une collection d'entités similaires "
+"reliées à une notice d'autorité donnée"
+
 msgid "latest update on"
 msgstr "dernière mise à jour"
 
diff --git a/cubicweb_saem_ref/migration/0.21.0_Any.py b/cubicweb_saem_ref/migration/0.21.0_Any.py
new file mode 100644
--- /dev/null
+++ b/cubicweb_saem_ref/migration/0.21.0_Any.py
@@ -0,0 +1,2 @@
+add_attribute('AgentFunction', 'index')
+add_attribute('Mandate', 'index')
diff --git a/cubicweb_saem_ref/schema.py b/cubicweb_saem_ref/schema.py
--- a/cubicweb_saem_ref/schema.py
+++ b/cubicweb_saem_ref/schema.py
@@ -17,7 +17,10 @@
 """cubicweb-saem-ref schema"""
 
 from yams.buildobjs import EntityType, RelationDefinition, String, Int, ComputedRelation
-from yams.constraints import UniqueConstraint
+from yams.constraints import (
+    IntervalBoundConstraint,
+    UniqueConstraint,
+)
 
 from cubicweb import _
 from cubicweb.schema import (RO_ATTR_PERMS, ERQLExpression, RRQLExpression,
@@ -134,6 +137,15 @@ for etype_def in (eac.ChronologicalRelat
     }
 
 
+class index(RelationDefinition):
+    subject = ('AgentFunction', 'Mandate')
+    object = 'Int'
+    description = _('index of entity as an item of the collection of similar '
+                    'entities related to a given authority record')
+    cardinality = '?1'
+    constraints = [IntervalBoundConstraint(0)]
+
+
 # SKOS #########################################################################
 
 make_workflowable(skos.ConceptScheme)
diff --git a/cubicweb_saem_ref/views/authorityrecord.py b/cubicweb_saem_ref/views/authorityrecord.py
--- a/cubicweb_saem_ref/views/authorityrecord.py
+++ b/cubicweb_saem_ref/views/authorityrecord.py
@@ -60,6 +60,10 @@ for rtype in ('chronological_predecessor
 
 afs.tag_object_of(('*', 'use_authorityrecord', 'AuthorityRecord'), 'main', 'hidden')
 
+for etype in ('Mandate', 'AgentFunction'):
+    pvs.tag_attribute((etype, 'index'), 'hidden')
+    afs.tag_attribute((etype, 'index'), 'main', 'hidden')
+
 
 class EACImportComponent(ImportEntityComponent):
     """Component with a link to import an authority record from an EAC-CPF file."""


More information about the saem-devel mailing list