[schema] Add a relation to indicate the type of keyword provided by a vocabulary
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 16 Mar 2017 11:31:21 +0100
changeset 2495 e8fdad3ee7cb
parent 2494 62882aa59ac9
child 2496 492163cc78b8
[schema] Add a relation to indicate the type of keyword provided by a vocabulary Related to extranet #12351787
cubicweb_seda/i18n/en.po
cubicweb_seda/i18n/fr.po
cubicweb_seda/migration/0.9.0_Any.py
cubicweb_seda/schema/__init__.py
cubicweb_seda/views/__init__.py
test/test_schema.py
--- a/cubicweb_seda/i18n/en.po	Thu Mar 16 11:31:50 2017 +0100
+++ b/cubicweb_seda/i18n/en.po	Thu Mar 16 11:31:21 2017 +0100
@@ -565,6 +565,9 @@
 msgid "SEDA 2.0 RNG export"
 msgstr ""
 
+msgid "SEDA code keyword type for this scheme"
+msgstr ""
+
 msgid "SEDA profile tree"
 msgstr ""
 
@@ -3907,6 +3910,20 @@
 msgid "clone_of_object"
 msgstr ""
 
+msgid "code_keyword_type"
+msgstr ""
+
+msgctxt "ConceptScheme"
+msgid "code_keyword_type"
+msgstr ""
+
+msgid "code_keyword_type_object"
+msgstr ""
+
+msgctxt "Concept"
+msgid "code_keyword_type_object"
+msgstr ""
+
 msgctxt "SEDAComment"
 msgid "comment"
 msgstr ""
--- a/cubicweb_seda/i18n/fr.po	Thu Mar 16 11:31:50 2017 +0100
+++ b/cubicweb_seda/i18n/fr.po	Thu Mar 16 11:31:21 2017 +0100
@@ -575,6 +575,9 @@
 msgid "SEDA 2.0 RNG export"
 msgstr "export SEDA 2.0 RNG"
 
+msgid "SEDA code keyword type for this scheme"
+msgstr "Type SEDA des mot-clés de ce vocabulaire"
+
 msgid "SEDA profile tree"
 msgstr "arbre du profil SEDA"
 
@@ -3921,6 +3924,20 @@
 msgid "clone_of_object"
 msgstr ""
 
+msgid "code_keyword_type"
+msgstr "type de mot-clés"
+
+msgctxt "ConceptScheme"
+msgid "code_keyword_type"
+msgstr ""
+
+msgid "code_keyword_type_object"
+msgstr ""
+
+msgctxt "Concept"
+msgid "code_keyword_type_object"
+msgstr ""
+
 msgctxt "SEDAComment"
 msgid "comment"
 msgstr "valeur"
--- a/cubicweb_seda/migration/0.9.0_Any.py	Thu Mar 16 11:31:50 2017 +0100
+++ b/cubicweb_seda/migration/0.9.0_Any.py	Thu Mar 16 11:31:21 2017 +0100
@@ -11,6 +11,8 @@
 
 sync_schema_props_perms('clone_of')
 
+add_relation_type('code_keyword_type')
+
 scheme = cnx.find('ConceptScheme', title=u'SEDA 2 : Types de mot-clé').one()
 with cnx.deny_all_hooks_but():
     scheme.cw_set(title=u'SEDA : Types de mot-clé')
--- a/cubicweb_seda/schema/__init__.py	Thu Mar 16 11:31:50 2017 +0100
+++ b/cubicweb_seda/schema/__init__.py	Thu Mar 16 11:31:21 2017 +0100
@@ -19,7 +19,8 @@
 from yams.buildobjs import String
 
 from cubicweb import _
-from cubicweb.schema import ERQLExpression, RRQLExpression
+from cubicweb.schema import ERQLExpression, RRQLExpression, RQLConstraint
+
 from cubes.skos import schema as skos
 
 _('1')
@@ -126,6 +127,21 @@
     cardinality = '11'
 
 
+class code_keyword_type(RelationDefinition):
+    __permissions__ = {
+        'read': ('managers', 'users', 'guests'),
+        'add': ('managers', RRQLExpression('U has_update_permission S')),
+        'delete': ('managers', RRQLExpression('U has_update_permission S')),
+    }
+    subject = 'ConceptScheme'
+    object = 'Concept'
+    cardinality = '?*'
+    inlined = True
+    description = _('SEDA code keyword type for this scheme')
+    constraints = [RQLConstraint('O in_scheme CS, CS scheme_relation_type RT, '
+                                 'RT name "seda_keyword_type_to"')]
+
+
 class compat_list(RelationDefinition):
     __permissions__ = {'read': ('managers', 'users', 'guests',),
                        'add': (),
--- a/cubicweb_seda/views/__init__.py	Thu Mar 16 11:31:50 2017 +0100
+++ b/cubicweb_seda/views/__init__.py	Thu Mar 16 11:31:21 2017 +0100
@@ -50,6 +50,11 @@
 pvs.tag_subject_of(('*', 'scheme_entity_type', '*'), 'hidden')
 pvs.tag_object_of(('*', 'seda_keyword_reference_to_scheme', '*'), 'hidden')
 
+afs.tag_subject_of(('*', 'code_keyword_type', '*'), 'main', 'attributes')
+pvs.tag_subject_of(('*', 'code_keyword_type', '*'), 'attributes')
+afs.tag_object_of(('*', 'code_keyword_type', '*'), 'main', 'hidden')
+pvs.tag_object_of(('*', 'code_keyword_type', '*'), 'hidden')
+
 aff.tag_attribute(('*', 'user_cardinality'), SEDAMetaField)
 afs.tag_attribute(('*', 'user_annotation'), 'main', 'hidden')
 for etype in FIRST_LEVEL_ETYPES:
--- a/test/test_schema.py	Thu Mar 16 11:31:50 2017 +0100
+++ b/test/test_schema.py	Thu Mar 16 11:31:21 2017 +0100
@@ -237,6 +237,21 @@
                                        {'search': search[::-1]})
                     self.assertEqual([r for r, in rset.rows], [transfer.eid])
 
+    def test_scheme_code_keyword_type_constraint(self):
+        with self.admin_access.repo_cnx() as cnx:
+            ckt_scheme = testutils.scheme_for_type(cnx, 'seda_keyword_type_to', None)
+            ckt_concept = ckt_scheme.add_concept(label=u'geoname')
+            scheme = testutils.scheme_for_type(cnx, 'seda_mime_type_to', None)
+            concept = scheme.add_concept(label=u'text/plain')
+            cnx.commit()
+
+            with self.assertRaises(ValidationError):
+                scheme.cw_set(code_keyword_type=concept)
+                cnx.commit()
+
+            scheme.cw_set(code_keyword_type=ckt_concept)
+            cnx.commit()
+
 
 class SecurityTC(CubicWebTC):