[xsd2yams] Skip KeywordContent
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 20 Jan 2017 10:39:21 +0100
changeset 2314 4286fd72c879
parent 2312 7f773346c679
child 2315 17b947d38a25
[xsd2yams] Skip KeywordContent This is a mandatory and unique children of Keyword, so it may be skipped while this ease thing to get a different UI for 'simple keyword' vs 'concept keyword' that still has to be done. Related to #16070921
entities/custom.py
entities/generated.py
entities/profile_generation.py
i18n/en.po
i18n/fr.po
migration/0.6.0_Any.py
schema/seda2.py
test/test_profile_generation.py
test/test_xsd2yams.py
views/uicfg.py
xsd.py
--- a/entities/custom.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/entities/custom.py	Fri Jan 20 10:39:21 2017 +0100
@@ -194,10 +194,6 @@
 class SEDAKeyword(generated.SEDAKeyword):
 
     @property
-    def content_string(self):
-        return self.seda_keyword_content[0].keyword_content
-
-    @property
     def reference(self):
         return (self.reverse_seda_keyword_reference_from[0]
                 if self.reverse_seda_keyword_reference_from else None)
--- a/entities/generated.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/entities/generated.py	Fri Jan 20 10:39:21 2017 +0100
@@ -475,8 +475,8 @@
 
 class SEDAKeyword(SEDAAnyEntity):
     __regid__ = 'SEDAKeyword'
-    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
-    value_attr = None
+    fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality', 'keyword_content', 'user_annotation'])
+    value_attr = 'keyword_content'
 
 class SEDAOriginatingAgency(SEDAAnyEntity):
     __regid__ = 'SEDAOriginatingAgency'
@@ -578,11 +578,6 @@
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
     value_attr = None
 
-class SEDAKeywordContent(SEDAAnyEntity):
-    __regid__ = 'SEDAKeywordContent'
-    fetch_attrs, cw_fetch_order = fetch_config(['keyword_content'])
-    value_attr = 'keyword_content'
-
 class SEDAKeywordReference(SEDAAnyEntity):
     __regid__ = 'SEDAKeywordReference'
     fetch_attrs, cw_fetch_order = fetch_config(['user_cardinality'])
--- a/entities/profile_generation.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/entities/profile_generation.py	Fri Jan 20 10:39:21 2017 +0100
@@ -330,7 +330,7 @@
             if not path:
                 assert not isinstance(occ.target, graph_nodes.XMLAttribute)
                 assert occ.target.local_name in JUMP_ELEMENTS, occ.target
-                if not any(iter_path_children(occ.target, entity)):
+                if occ.minimum == 0 and not any(iter_path_children(occ.target, entity)):
                     # element has no children, skip it
                     continue
                 if occ.target.local_name in JUMPED_OPTIONAL_ELEMENTS:
@@ -1196,7 +1196,7 @@
                                       cardinality=keyword.user_cardinality,
                                       documentation=keyword.user_annotation,
                                       xsd_attributes=[XAttr('Id', 'xsd:ID')])
-        content = keyword.content_string
+        content = keyword.keyword_content
         url = None
         if keyword.reference:
             concept = keyword.reference.concept
--- a/i18n/en.po	Fri Jan 20 10:34:37 2017 +0100
+++ b/i18n/en.po	Fri Jan 20 10:39:21 2017 +0100
@@ -338,9 +338,6 @@
 msgid "New SEDAKeyword"
 msgstr ""
 
-msgid "New SEDAKeywordContent"
-msgstr ""
-
 msgid "New SEDAKeywordReference"
 msgstr ""
 
@@ -1246,16 +1243,6 @@
 msgid "SEDAKeyword"
 msgstr ""
 
-msgid "SEDAKeywordContent"
-msgstr ""
-
-msgctxt "inlined:SEDAKeyword.seda_keyword_content.subject"
-msgid "SEDAKeywordContent"
-msgstr ""
-
-msgid "SEDAKeywordContent_plural"
-msgstr ""
-
 msgid "SEDAKeywordReference"
 msgstr ""
 
@@ -2435,12 +2422,6 @@
 msgid "This SEDAKeyword:"
 msgstr ""
 
-msgid "This SEDAKeywordContent"
-msgstr ""
-
-msgid "This SEDAKeywordContent:"
-msgstr ""
-
 msgid "This SEDAKeywordReference"
 msgstr ""
 
@@ -3301,13 +3282,6 @@
 msgid "add a SEDAKeyword"
 msgstr ""
 
-msgid "add a SEDAKeywordContent"
-msgstr ""
-
-msgctxt "inlined:SEDAKeyword.seda_keyword_content.subject"
-msgid "add a SEDAKeywordContent"
-msgstr ""
-
 msgid "add a SEDAKeywordReference"
 msgstr ""
 
@@ -4175,10 +4149,6 @@
 msgid "container"
 msgstr ""
 
-msgctxt "SEDAKeywordContent"
-msgid "container"
-msgstr ""
-
 msgctxt "SEDAKeywordReference"
 msgid "container"
 msgstr ""
@@ -4708,7 +4678,7 @@
 msgid "keyword_content"
 msgstr ""
 
-msgctxt "SEDAKeywordContent"
+msgctxt "SEDAKeyword"
 msgid "keyword_content"
 msgstr ""
 
@@ -6272,20 +6242,6 @@
 msgid "seda_keyword"
 msgstr ""
 
-msgid "seda_keyword_content"
-msgstr ""
-
-msgctxt "SEDAKeyword"
-msgid "seda_keyword_content"
-msgstr ""
-
-msgid "seda_keyword_content_object"
-msgstr ""
-
-msgctxt "SEDAKeywordContent"
-msgid "seda_keyword_content_object"
-msgstr ""
-
 msgid "seda_keyword_object"
 msgstr ""
 
--- a/i18n/fr.po	Fri Jan 20 10:34:37 2017 +0100
+++ b/i18n/fr.po	Fri Jan 20 10:39:21 2017 +0100
@@ -345,9 +345,6 @@
 msgid "New SEDAKeyword"
 msgstr ""
 
-msgid "New SEDAKeywordContent"
-msgstr ""
-
 msgid "New SEDAKeywordReference"
 msgstr ""
 
@@ -1256,16 +1253,6 @@
 msgid "SEDAKeyword"
 msgstr ""
 
-msgid "SEDAKeywordContent"
-msgstr "mot-clé"
-
-msgctxt "inlined:SEDAKeyword.seda_keyword_content.subject"
-msgid "SEDAKeywordContent"
-msgstr ""
-
-msgid "SEDAKeywordContent_plural"
-msgstr ""
-
 msgid "SEDAKeywordReference"
 msgstr "référence"
 
@@ -2447,12 +2434,6 @@
 msgid "This SEDAKeyword:"
 msgstr ""
 
-msgid "This SEDAKeywordContent"
-msgstr ""
-
-msgid "This SEDAKeywordContent:"
-msgstr ""
-
 msgid "This SEDAKeywordReference"
 msgstr ""
 
@@ -3315,13 +3296,6 @@
 msgid "add a SEDAKeyword"
 msgstr ""
 
-msgid "add a SEDAKeywordContent"
-msgstr ""
-
-msgctxt "inlined:SEDAKeyword.seda_keyword_content.subject"
-msgid "add a SEDAKeywordContent"
-msgstr ""
-
 msgid "add a SEDAKeywordReference"
 msgstr "ajouter un identifiant de référence"
 
@@ -4189,10 +4163,6 @@
 msgid "container"
 msgstr ""
 
-msgctxt "SEDAKeywordContent"
-msgid "container"
-msgstr ""
-
 msgctxt "SEDAKeywordReference"
 msgid "container"
 msgstr ""
@@ -4727,7 +4697,7 @@
 msgid "keyword_content"
 msgstr "valeur"
 
-msgctxt "SEDAKeywordContent"
+msgctxt "SEDAKeyword"
 msgid "keyword_content"
 msgstr ""
 
@@ -6293,20 +6263,6 @@
 msgid "seda_keyword"
 msgstr ""
 
-msgid "seda_keyword_content"
-msgstr ""
-
-msgctxt "SEDAKeyword"
-msgid "seda_keyword_content"
-msgstr ""
-
-msgid "seda_keyword_content_object"
-msgstr ""
-
-msgctxt "SEDAKeywordContent"
-msgid "seda_keyword_content_object"
-msgstr ""
-
 msgid "seda_keyword_object"
 msgstr "mot-clé"
 
--- a/migration/0.6.0_Any.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/migration/0.6.0_Any.py	Fri Jan 20 10:39:21 2017 +0100
@@ -48,3 +48,8 @@
 add_cube('eac')
 if 'Agent' not in fsschema:
     drop_entity_type('Agent')
+
+add_attribute('SEDAKeyword', 'keyword_content')
+rql('SET KW keyword_content C WHERE KWC seda_keyword_content KW, KWC keyword_content C')
+commit()
+drop_entity_type('SEDAKeywordContent')
--- a/schema/seda2.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/schema/seda2.py	Fri Jan 20 10:39:21 2017 +0100
@@ -1804,6 +1804,7 @@
                       annotable=True)
 class SEDAKeyword(EntityType):
     u""""""
+    keyword_content = String(fulltextindexed=True)
 
 
 class seq_alt_archive_unit_archive_unit_ref_id_management_keyword(RelationDefinition):
@@ -2253,22 +2254,6 @@
     inlined = True
     constraints = []
 
-@seda_profile_element(cardinalities=['1'], default_cardinality='1',
-                      annotable=False)
-class SEDAKeywordContent(EntityType):
-    u""""""
-    keyword_content = String(fulltextindexed=True)
-
-
-class keyword_keyword_content(RelationDefinition):
-    name = 'seda_keyword_content'
-    subject = 'SEDAKeyword'
-    object = 'SEDAKeywordContent'
-    cardinality = '11'
-    composite = fulltext_container = 'subject'
-    inlined = True
-    constraints = []
-
 @seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='0..1',
                       annotable=True)
 class SEDAKeywordReference(EntityType):
--- a/test/test_profile_generation.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/test/test_profile_generation.py	Fri Jan 20 10:39:21 2017 +0100
@@ -226,7 +226,6 @@
             create = cnx.create_entity
             kw = create('SEDAKeyword', user_cardinality=u'0..n')
             kt = create('SEDAKeywordType', seda_keyword_type_from=kw)
-            kc = create('SEDAKeywordContent', reverse_seda_keyword_content=kw)
 
             edef = next(element_defs)
             # self.assertEqual(
@@ -234,7 +233,7 @@
             #  ('Keyword', 'SEDAKeyword', [
             #      ('id', [('seda_id', 'object', 'SEDAid'),
             #              ('id', 'subject', 'String')]),
-            #      ('KeywordContent', [('seda_keyword_content', 'subject', 'SEDAKeywordContent')]),
+            #      ('KeywordContent', []),
             #      ('KeywordReference',
             #       [('seda_keyword_reference_from', 'object', 'SEDAKeywordReference'),
             #        ('seda_keyword_reference_to', 'subject', 'Concept')]),
@@ -248,13 +247,6 @@
             self.assertEqual(target_value[0], None)
             self.assertEqual(target_value[1], None)
 
-            path = edef[-1][1][1]
-            target_values = _path_target_values(kw, path)
-            self.assertEqual(len(target_values), 1)
-            target_value = target_values[0]
-            self.assertEqual(target_value[0].eid, kc.eid)
-            self.assertEqual(target_value[1].eid, kc.eid)
-
             path = edef[-1][2][1]
             target_values = _path_target_values(kw, path)
             self.assertEqual(len(target_values), 0)
@@ -279,11 +271,11 @@
             edef = next(element_defs)
             # self.assertEqual(
             #     readable_edef(edef),
-            #     ('KeywordContent', 'SEDAKeywordContent', [
+            #     ('KeywordContent', 'SEDAKeyword', [
             #         ('KeywordContent', [('keyword_content', 'subject', 'String')]),
             #     ]))
             path = edef[-1][0][1]
-            target_values = _path_target_values(kc, path)
+            target_values = _path_target_values(kw, path)
             self.assertEqual(len(target_values), 1)
             target_value = target_values[0]
             self.assertEqual(target_value[0], None)
@@ -478,9 +470,8 @@
             unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(
                 transfer, user_cardinality=u'0..n')
 
-            kw = create('SEDAKeyword', seda_keyword=unit_alt_seq)
-            create('SEDAKeywordContent', reverse_seda_keyword_content=kw,
-                   keyword_content=u'kwick')
+            kw = create('SEDAKeyword', seda_keyword=unit_alt_seq,
+                        keyword_content=u'kwick')
             kwr_e = create('SEDAKeywordReference', seda_keyword_reference_from=kw)
             create('SEDAKeywordType', seda_keyword_type_from=kw,
                    seda_keyword_type_to=kw_type)
@@ -669,7 +660,6 @@
             kw = create('SEDAKeyword', user_cardinality=u'0..n', seda_keyword=unit_alt_seq)
             create('SEDAKeywordType', seda_keyword_type_from=kw)
             create('SEDAKeywordReference', seda_keyword_reference_from=kw)
-            create('SEDAKeywordContent', reverse_seda_keyword_content=kw)
             history_item = create('SEDACustodialHistoryItem',
                                   seda_custodial_history_item=unit_alt_seq)
             create('SEDAwhen', seda_when=history_item)
@@ -823,8 +813,7 @@
 
             kw = create('SEDAKeyword',
                         user_cardinality=u'0..n',
-                        seda_keyword=unit_alt_seq,
-                        seda_keyword_content=create('SEDAKeywordContent'))  # XXX
+                        seda_keyword=unit_alt_seq)
             create('SEDAKeywordReference',
                    seda_keyword_reference_from=kw,
                    seda_keyword_reference_to=concepts['file'],
@@ -973,7 +962,6 @@
             create('SEDAStartDate', seda_start_date=subunit_alt_seq)
             create('SEDAEndDate', seda_end_date=subunit_alt_seq)
             kw = create('SEDAKeyword', user_cardinality=u'0..n', seda_keyword=subunit_alt_seq)
-            create('SEDAKeywordContent', reverse_seda_keyword_content=kw)
             create('SEDAKeywordReference', seda_keyword_reference_from=kw)
 
             create('SEDASystemId', seda_system_id=subunit_alt_seq)
--- a/test/test_xsd2yams.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/test/test_xsd2yams.py	Fri Jan 20 10:39:21 2017 +0100
@@ -72,7 +72,7 @@
 
     def test_keyword(self):
         mapping = xsy_mapping('Keyword')
-        emapping = mapping.etypes['SEDAKeywordContent']
+        emapping = mapping.etypes['SEDAKeyword']
         self.assertEMappingEqual(emapping, {'keyword_content': 'String'})
 
     def test_binarydataobject(self):
@@ -115,7 +115,7 @@
             ('Keyword', 'SEDAKeyword', [
                 ('id', [('seda_id', 'object', 'SEDAid'),
                         ('id', 'subject', 'String')]),
-                ('KeywordContent', [('seda_keyword_content', 'subject', 'SEDAKeywordContent')]),
+                ('KeywordContent', []),
                 ('KeywordReference',
                  [('seda_keyword_reference_from', 'object', 'SEDAKeywordReference'),
                   ('seda_keyword_reference_to', 'subject', 'Concept')]),
@@ -125,7 +125,7 @@
         edef = next(element_defs)
         self.assertEqual(
             readable_edef(edef),
-            ('KeywordContent', 'SEDAKeywordContent', [
+            ('KeywordContent', 'SEDAKeyword', [
                 ('KeywordContent', [('keyword_content', 'subject', 'String')]),
             ]))
         self.assertRaises(StopIteration, next, element_defs)
--- a/views/uicfg.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/views/uicfg.py	Fri Jan 20 10:39:21 2017 +0100
@@ -66,7 +66,6 @@
 ives['SEDAAltRequiresArchiveUnitRefId'] = 'subobject'
 ives['SEDANeedAuthorization'] = 'subobject'
 ives['SEDARepositoryObjectPID'] = 'subobject'
-ives['SEDAKeywordContent'] = 'subobject'
 ives['SEDASpatial'] = 'subobject'
 ives['SEDAVersion'] = 'subobject'
 ives['SEDARelationship'] = 'subobject'
@@ -460,8 +459,6 @@
 abaa.tag_object_of(('*', 'seda_custodial_history_item', '*'), False)
 abaa.tag_subject_of(('*', 'seda_custodial_history_file', '*'), False)
 abaa.tag_object_of(('*', 'seda_custodial_history_file', '*'), False)
-abaa.tag_object_of(('*', 'seda_keyword_content', '*'), False)
-abaa.tag_subject_of(('*', 'seda_keyword_content', '*'), False)
 abaa.tag_subject_of(('*', 'seda_keyword_reference_from', '*'), False)
 abaa.tag_object_of(('*', 'seda_keyword_reference_from', '*'), False)
 abaa.tag_object_of(('*', 'seda_keyword_reference_to', '*'), False)
@@ -565,10 +562,10 @@
 affk.tag_subject_of(('*', 'status', '*'), {'widget': fw.TextInput({'size': 80})})
 affk.tag_subject_of(('*', 'version', '*'), {'widget': fw.TextInput({'size': 80})})
 affk.tag_subject_of(('*', 'tag', '*'), {'widget': fw.TextInput({'size': 80})})
+affk.tag_subject_of(('*', 'keyword_content', '*'), {'widget': fw.TextInput({'size': 80})})
 affk.tag_subject_of(('*', 'source', '*'), {'widget': fw.TextInput({'size': 80})})
 affk.tag_subject_of(('*', 'prevent_inheritance', '*'), {'allow_none': True})
 affk.tag_subject_of(('*', 'custodial_history_item', '*'), {'widget': fw.TextInput({'size': 80})})
-affk.tag_subject_of(('*', 'keyword_content', '*'), {'widget': fw.TextInput({'size': 80})})
 affk.tag_subject_of(('*', 'spatial', '*'), {'widget': fw.TextInput({'size': 80})})
 affk.tag_subject_of(('*', 'temporal', '*'), {'widget': fw.TextInput({'size': 80})})
 affk.tag_subject_of(('*', 'juridictional', '*'), {'widget': fw.TextInput({'size': 80})})
@@ -873,8 +870,6 @@
 afs.tag_object_of(('*', 'seda_custodial_history_item', '*'), 'main', 'hidden')
 afs.tag_subject_of(('*', 'seda_custodial_history_file', '*'), 'main', 'hidden')
 afs.tag_object_of(('*', 'seda_custodial_history_file', '*'), 'main', 'hidden')
-afs.tag_object_of(('*', 'seda_keyword_content', '*'), 'main', 'hidden')
-afs.tag_subject_of(('*', 'seda_keyword_content', '*'), 'main', 'inlined')
 afs.tag_subject_of(('*', 'seda_keyword_reference_from', '*'), 'main', 'hidden')
 afs.tag_object_of(('*', 'seda_keyword_reference_from', '*'), 'main', 'inlined')
 afs.tag_object_of(('*', 'seda_keyword_reference_to', '*'), 'main', 'hidden')
@@ -1237,6 +1232,7 @@
 rec.tag_subject_of(('*', 'version', '*'), {'novalue_label': _('<no value specified>')})
 rec.tag_object_of(('*', 'seda_version', '*'), {'novalue_label': _('<unauthorized>')})
 rec.tag_subject_of(('*', 'tag', '*'), {'novalue_label': _('<no value specified>')})
+rec.tag_subject_of(('*', 'keyword_content', '*'), {'novalue_label': _('<no value specified>')})
 rec.tag_object_of(('*', 'seda_originating_agency_from', '*'), {'novalue_label': _('<unauthorized>')})
 rec.tag_subject_of(('*', 'seda_originating_agency_to', '*'), {'novalue_label': _('<no value specified>')})
 rec.tag_object_of(('*', 'seda_submission_agency_from', '*'), {'novalue_label': _('<unauthorized>')})
@@ -1263,8 +1259,6 @@
 rec.tag_subject_of(('*', 'seda_ref_non_rule_id_to', '*'), {'novalue_label': _('<no value specified>')})
 rec.tag_subject_of(('*', 'custodial_history_item', '*'), {'novalue_label': _('<no value specified>')})
 rec.tag_object_of(('*', 'seda_custodial_history_file', '*'), {'novalue_label': _('<unauthorized>')})
-rec.tag_subject_of(('*', 'keyword_content', '*'), {'novalue_label': _('<no value specified>')})
-rec.tag_subject_of(('*', 'seda_keyword_content', '*'), {'novalue_label': _('<no value specified>')})
 rec.tag_object_of(('*', 'seda_keyword_reference_from', '*'), {'novalue_label': _('<unauthorized>')})
 rec.tag_subject_of(('*', 'seda_keyword_reference_to', '*'), {'novalue_label': _('<no value specified>')})
 rec.tag_object_of(('*', 'seda_keyword_type_from', '*'), {'novalue_label': _('<unauthorized>')})
@@ -1349,6 +1343,8 @@
 pvds.set_fields_order('SEDAVersion', ['user_cardinality', 'version', 'user_annotation'])
 affk.set_fields_order('SEDATag', ['user_cardinality', 'tag', 'user_annotation'])
 pvds.set_fields_order('SEDATag', ['user_cardinality', 'tag', 'user_annotation'])
+affk.set_fields_order('SEDAKeyword', ['user_cardinality', 'keyword_content', 'user_annotation'])
+pvds.set_fields_order('SEDAKeyword', ['user_cardinality', 'keyword_content', 'user_annotation'])
 affk.set_fields_order('SEDASource', ['user_cardinality', 'source', 'user_annotation'])
 pvds.set_fields_order('SEDASource', ['user_cardinality', 'source', 'user_annotation'])
 affk.set_fields_order('SEDACustodialHistoryItem', ['user_cardinality', 'custodial_history_item', 'user_annotation'])
--- a/xsd.py	Fri Jan 20 10:34:37 2017 +0100
+++ b/xsd.py	Fri Jan 20 10:39:21 2017 +0100
@@ -67,6 +67,8 @@
     'RelatedObjectReference',
     # ArchiveUnit
     'Content',
+    # Keyword
+    'KeywordContent',
 ])
 XSD2YAMS = {
     'string': 'String',