[PATCH eac] Add new attributes to NameEntry

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Tue Aug 20 10:24:06 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1563812571 -7200
#      Mon Jul 22 18:22:51 2019 +0200
# Node ID 232bd90ed87f658764cf74ac4b2e8b26243b3c9b
# Parent  42df44a5dbad4cb1469b12b25d21752e8c9d37c3
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 232bd90ed87f
Add new attributes to NameEntry

diff -r 42df44a5dbad -r 232bd90ed87f cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Mon Jul 22 18:22:51 2019 +0200
@@ -41,11 +41,12 @@
 TYPE_MAPPING['human'] = u'person'
 
 ETYPES_ORDER_HINT = ('AgentKind', 'PhoneNumber', 'PostalAddress', 'AuthorityRecord',
-                     'Convention', 'AgentPlace', 'Mandate',
-                     'LegalStatus', 'History', 'HistoricalEvent', 'Structure', 'AgentFunction',
-                     'Occupation', 'GeneralContext', 'AssociationRelation', 'ChronologicalRelation',
-                     'HierarchicalRelation', 'EACResourceRelation', 'EACFunctionRelation',
-                     'ExternalUri', 'EACSource', 'Activity')
+                     'Convention', 'AgentPlace',
+                     'Mandate', 'LegalStatus', 'History', 'HistoricalEvent', 'Structure',
+                     'AgentFunction', 'Occupation', 'GeneralContext', 'AssociationRelation',
+                     'ChronologicalRelation', 'HierarchicalRelation', 'EACResourceRelation',
+                     'EACFunctionRelation', 'ExternalUri', 'EACSource', 'Activity',
+                     'NameEntry')
 
 
 class InvalidEAC(RuntimeError):
@@ -414,6 +415,24 @@
         for name_entry in name_entries:
             yield self.build_name_entry(name_entry)
 
+    @filter_empty
+    @filter_none
+    @elem_maybe_none
+    def build_name_child(self, elem):
+        """Build NameEntry external entity"""
+        for elem in self._elem_findall(elem, 'eac:nameEntry'):
+            values = self.values_from_attrib(elem, (('language', 'lang'),
+                                                    ('script_code', 'scriptCode')))
+            values.update(self.values_from_xpaths(elem,
+                                                  (('preferred_form', 'eac:preferredForm'),
+                                                   ('alternative_form', 'eac:alternativeForm'),
+                                                   ('authorized_form', 'eac:authorizedForm'))))
+            parts = self._elem_findall(elem, 'eac:part')
+            if not parts:
+                raise MissingTag('part', 'nameEntry')
+            values.update({'parts': set([u', '.join(text_type(p.text) for p in parts)])})
+            yield ExtEntity('NameEntry', self._gen_extid(), values)
+
     @filter_none
     def parse_description(self, description):
         """Parse the `description` tag and yield external entities, possibly
diff -r 42df44a5dbad -r 232bd90ed87f cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/entities.py	Mon Jul 22 18:22:51 2019 +0200
@@ -222,6 +222,16 @@
     fetch_attrs, cw_fetch_order = fetch_config(('event',))
 
 
+class NameEntry(AnyEntity):
+    __regid__ = 'NameEntry'
+    fetch_attrs, cw_fetch_order = fetch_config(('language',
+                                                'preferred_form',
+                                                'alternative_form',
+                                                'authorized_form',
+                                                'script_code',
+                                                'parts'))
+
+
 # XML export
 
 def substitute_xml_prefix(prefix_name, namespaces):
diff -r 42df44a5dbad -r 232bd90ed87f cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/migration/0.9.0_Any.py	Mon Jul 22 18:22:51 2019 +0200
@@ -1,6 +1,15 @@
-add_attribute('History', 'abstract')
 add_entity_type('HistoricalEvent')
 add_entity_type('Convention')
 add_entity_type('EACFunctionRelation')
+
+# Attributes to update
 add_attribute('EACResourceRelation', 'xml_attributes')
 add_attribute('EACResourceRelation', 'relation_entry')
+
+add_attribute('History', 'abstract')
+
+for attrib in ('language', 'preferred_form',
+               'alternative_form', 'authorized_form',
+               'script_code'):
+    add_attribute('NameEntry', attrib)
+
diff -r 42df44a5dbad -r 232bd90ed87f cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py	Fri Aug 09 12:35:49 2019 +0200
+++ b/cubicweb_eac/schema.py	Mon Jul 22 18:22:51 2019 +0200
@@ -62,6 +62,11 @@
 
 class NameEntry(EntityType):
     """Represent a nameEntry tag of an EAC-CPF document."""
+    language = String(fulltextindexed=True)
+    preferred_form = String(fulltextindexed=True)
+    alternative_form = String(fulltextindexed=True)
+    authorized_form = String(fulltextindexed=True)
+    script_code = String(fulltextindexed=True)
     parts = String(
         required=True, fulltextindexed=True,
         description=_('concatenation of part tags within a nameEntry'))



More information about the saem-devel mailing list