[PATCH 2 of 8 seda] [schema] Add a relation to indicate the type of keyword provided by a vocabulary

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 16 13:37:39 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489660281 -3600
#      Thu Mar 16 11:31:21 2017 +0100
# Node ID 404456566363c13345b6c7c8fb60bbaaccc7b5c0
# Parent  481d024275a9ce6169550d73ba78f8336bda4620
[schema] Add a relation to indicate the type of keyword provided by a vocabulary

Related to extranet #12351787

diff --git a/cubicweb_seda/i18n/en.po b/cubicweb_seda/i18n/en.po
--- a/cubicweb_seda/i18n/en.po
+++ b/cubicweb_seda/i18n/en.po
@@ -563,10 +563,13 @@ msgid "SEDA 1.0 RNG export"
 msgstr ""
 
 msgid "SEDA 2.0 RNG export"
 msgstr ""
 
+msgid "SEDA code keyword type for this scheme"
+msgstr ""
+
 msgid "SEDA profile tree"
 msgstr ""
 
 msgid "SEDAAccessRule"
 msgstr ""
@@ -3905,10 +3908,24 @@ msgstr ""
 
 msgctxt "SEDAArchiveUnit"
 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 ""
 
 msgid "compat_list"
diff --git a/cubicweb_seda/i18n/fr.po b/cubicweb_seda/i18n/fr.po
--- a/cubicweb_seda/i18n/fr.po
+++ b/cubicweb_seda/i18n/fr.po
@@ -573,10 +573,13 @@ msgid "SEDA 1.0 RNG export"
 msgstr "export SEDA 1.0 RNG"
 
 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"
 
 msgid "SEDAAccessRule"
 msgstr ""
@@ -3919,10 +3922,24 @@ msgstr ""
 
 msgctxt "SEDAArchiveUnit"
 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"
 
 msgid "compat_list"
diff --git a/cubicweb_seda/migration/0.9.0_Any.py b/cubicweb_seda/migration/0.9.0_Any.py
--- a/cubicweb_seda/migration/0.9.0_Any.py
+++ b/cubicweb_seda/migration/0.9.0_Any.py
@@ -9,10 +9,12 @@ for rdef, role in iter_all_rdefs(schema,
     if target_etype == 'SEDAArchiveUnit':
         sync_schema_props_perms((rdef.subject, rdef.rtype, rdef.object))
 
 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é')
     cnx.commit()
     cnx.execute('SET L language_code "seda" WHERE L label_of C, C in_scheme CS, CS eid %(cs)s',
diff --git a/cubicweb_seda/schema/__init__.py b/cubicweb_seda/schema/__init__.py
--- a/cubicweb_seda/schema/__init__.py
+++ b/cubicweb_seda/schema/__init__.py
@@ -17,11 +17,12 @@
 
 from yams.buildobjs import RelationType, RelationDefinition
 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')
 _('0..1')
 _('0..n')
@@ -124,10 +125,25 @@ class simplified_profile(RelationDefinit
     description = _('simplified profiles are compatible with older version of SEDA, but have not '
                     'the full SEDA 2 expressivness')
     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': (),
                        'update': ()}
     subject = 'SEDAArchiveTransfer'
diff --git a/cubicweb_seda/views/__init__.py b/cubicweb_seda/views/__init__.py
--- a/cubicweb_seda/views/__init__.py
+++ b/cubicweb_seda/views/__init__.py
@@ -48,10 +48,15 @@ afs.tag_object_of(('*', 'container', '*'
 
 pvs.tag_subject_of(('*', 'scheme_relation_type', '*'), 'hidden')
 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:
     aff.tag_attribute((etype, 'user_cardinality'), ff.StringField)
     afs.tag_attribute((etype, 'user_annotation'), 'main', 'attributes')
diff --git a/test/test_schema.py b/test/test_schema.py
--- a/test/test_schema.py
+++ b/test/test_schema.py
@@ -235,10 +235,25 @@ class SchemaTC(CubicWebTC):
                 with self.subTest(search=search):
                     rset = cnx.execute('Any X WHERE X has_text %(search)s',
                                        {'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):
 
     @contextmanager
     def assertUnauthorized(self, cnx):


More information about the saem-devel mailing list