[PATCH eac] Add raw_date argument to DateEntity

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Thu Sep 5 15:01:27 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1567614345 -7200
#      Wed Sep 04 18:25:45 2019 +0200
# Node ID 85bc691b625f1fdcad1414ea46198bd9b6d85bfe
# Parent  e87e5bbc15c8175baa078d0579b25cfc20119a2a
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 85bc691b625f
Add raw_date argument to DateEntity

diff -r e87e5bbc15c8 -r 85bc691b625f cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Thu Sep 05 11:18:02 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Wed Sep 04 18:25:45 2019 +0200
@@ -473,14 +473,33 @@
                                                 ('alternative_form', 'eac:alternativeForm')))
         yield ExtEntity('ParallelNames', self._gen_extid(), values)
 
+    def raw_date_range(self, date_range_elem):
+        data_lst = []
+        from_date = self._elem_find(date_range_elem, 'eac:fromDate')
+        to_date = self._elem_find(date_range_elem, 'eac:toDate')
+        if from_date is not None and from_date.text and from_date.text.strip():
+            data_lst.append(text_type(from_date.text.strip()))
+        if to_date is not None and to_date.text and to_date.text.strip():
+            data_lst.append(text_type(to_date.text.strip()))
+        return u'-'.join(data_lst)
+
     @filter_empty
     def extract_dates_from(self, elem):
         for date in self._elem_findall(elem, 'eac:date'):
-            yield ExtEntity('DateEntity', self._gen_extid(),
-                            {'start_date': set([self.parse_date(date)]),
-                             'end_date': set([self.parse_date(date)])})
+            values = {}
+            parsed_date = self.parse_date(date)
+            if parsed_date:
+                values = {'start_date': {parsed_date},
+                          'end_date': {parsed_date}}
+            if date is not None and date.text and date.text.strip():
+                values['raw_date'] = {text_type(date.text.strip())}
+            yield ExtEntity('DateEntity', self._gen_extid(), values)
         for date_range in self._elem_findall(elem, 'eac:dateRange'):
-            yield ExtEntity('DateEntity', self._gen_extid(), self.parse_daterange(date_range))
+            values = self.parse_daterange(date_range)
+            raw_dates = self.raw_date_range(date_range)
+            if raw_dates:
+                values['raw_date'] = {raw_dates}
+            yield ExtEntity('DateEntity', self._gen_extid(), values)
 
     @filter_empty
     @elem_maybe_none
diff -r e87e5bbc15c8 -r 85bc691b625f cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py	Thu Sep 05 11:18:02 2019 +0200
+++ b/cubicweb_eac/migration/0.9.0_Any.py	Wed Sep 04 18:25:45 2019 +0200
@@ -10,6 +10,7 @@
 # Attributes to update
 add_attribute('EACResourceRelation', 'xml_attributes')
 add_attribute('EACResourceRelation', 'relation_entry')
+add_attribute('DateEntity', 'raw_date')
 
 add_attribute('History', 'abstract')
 
diff -r e87e5bbc15c8 -r 85bc691b625f cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py	Thu Sep 05 11:18:02 2019 +0200
+++ b/cubicweb_eac/schema.py	Wed Sep 04 18:25:45 2019 +0200
@@ -531,6 +531,7 @@
     start_date = Date(constraints=[BoundaryConstraint(
         '<=', Attribute('end_date'), msg=_('start date must be less than end date'))])
     end_date = Date()
+    raw_date = String(description=_('Raw data contained in the date type tag'))
 
 
 @xml_wrap
diff -r e87e5bbc15c8 -r 85bc691b625f test/data/FRAD033_EAC_00001_simplified.xml
--- a/test/data/FRAD033_EAC_00001_simplified.xml	Thu Sep 05 11:18:02 2019 +0200
+++ b/test/data/FRAD033_EAC_00001_simplified.xml	Wed Sep 04 18:25:45 2019 +0200
@@ -164,15 +164,13 @@
 	    </toDate>
 	  </dateRange>
 	  <dateRange localType="open">
-	    <fromDate
-		standardDate="1950">1950
+	    <fromDate>TestData1
 	    </fromDate>
-	    <toDate>open
+	    <toDate>TestData2
 	    </toDate>
 	  </dateRange>
 	  <dateRange localType="open">
-	    <fromDate
-		standardDate="1950">1950
+	    <fromDate>TestData1
 	    </fromDate>
 	    <toDate>open
 	    </toDate>
diff -r e87e5bbc15c8 -r 85bc691b625f test/test_dataimport.py
--- a/test/test_dataimport.py	Thu Sep 05 11:18:02 2019 +0200
+++ b/test/test_dataimport.py	Wed Sep 04 18:25:45 2019 +0200
@@ -219,15 +219,16 @@
               },
              ),
             ('DateEntity', _gen_extid(),
-             {'start_date': set([datetime.date(1949, 1, 1)])
+             {'start_date': set([datetime.date(1949, 1, 1)]),
+              'raw_date': set([u'1949 ; open'])
               },
              ),
             ('DateEntity', _gen_extid(),
-             {'start_date': set([datetime.date(1950, 1, 1)])
+             {'raw_date': set([u'TestData1 ; TestData2'])
               },
              ),
             ('DateEntity', _gen_extid(),
-             {'start_date': set([datetime.date(1950, 1, 1)])
+             {'raw_date': set([u'TestData1 ; open'])
               },
              ),
             ('NameEntry', _gen_extid(),
@@ -293,7 +294,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1234, 1, 1)]),
-              'end_date': set([datetime.date(3000, 1, 1)])
+              'end_date': set([datetime.date(3000, 1, 1)]),
+              'raw_date': set([u'The mystic year! ; 3000'])
               },
              ),
             ('Mandate', _gen_extid(),
@@ -335,8 +337,10 @@
               },
              ),
             ('DateEntity', _gen_extid(),
-             {'end_date': [datetime.date(1957, 1, 1)],
-              'start_date': [datetime.date(1957, 1, 1)]}
+             {'end_date': set([datetime.date(1957, 1, 1)]),
+              'start_date': set([datetime.date(1957, 1, 1)]),
+              'raw_date': set([u'1957'])
+              },
              ),
             ('HistoricalEvent', _gen_extid(),
              {'date_relation': set(['37']),
@@ -345,8 +349,10 @@
               },
              ),
             ('DateEntity', _gen_extid(),
-             {'end_date': [datetime.date(1961, 1, 1)],
-              'start_date': [datetime.date(1960, 1, 1)]}
+             {'end_date': set([datetime.date(1961, 1, 1)]),
+              'start_date': set([datetime.date(1960, 1, 1)]),
+              'raw_date': set([u'1960 ; 1961'])
+              },
              ),
             ('Citation', _gen_extid(),
              {'uri': set(['http://www.assemblee-nationale.fr/histoire/images-decentralisation/'
@@ -413,7 +419,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1987, 1, 1)]),
-              'end_date': set([datetime.date(2099, 1, 1)])
+              'end_date': set([datetime.date(2099, 1, 1)]),
+              'raw_date': set([u'1987 ; 2099'])
               },
              ),
             ('Citation', _gen_extid(),
@@ -450,7 +457,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(2008, 1, 1)]),
-              'end_date': set([datetime.date(2099, 1, 1)])
+              'end_date': set([datetime.date(2099, 1, 1)]),
+              'raw_date': set([u'2008 ; 2099'])
               },
              ),
             ('ExternalUri', 'whatever',
@@ -472,7 +480,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1917, 1, 1)]),
-              'end_date': set([datetime.date(2009, 1, 1)])
+              'end_date': set([datetime.date(2009, 1, 1)]),
+              'raw_date': set([u'1917 ; 2009'])
               },
              ),
             ('ChronologicalRelation', _gen_extid(),
@@ -487,7 +496,8 @@
               },
              ),
             ('DateEntity', _gen_extid(),
-             {'start_date': set([datetime.date(2042, 1, 1)])
+             {'start_date': set([datetime.date(2042, 1, 1)]),
+              'raw_date': set([u'2042'])
               },
              ),
             ('IdentityRelation', _gen_extid(),
@@ -500,7 +510,9 @@
                                u'xmlns:xlink="http://www.w3.org/1999/xlink">hips</gloups>'])}
              ),
             ('DateEntity', _gen_extid(),
-             {'start_date': [datetime.date(2042, 1, 1)]}
+             {'start_date': [datetime.date(2042, 1, 1)],
+              'raw_date': set([u'2042'])
+              },
              ),
             ('FamilyRelation', _gen_extid(),
              {'date_relation': ['60'],
@@ -510,7 +522,9 @@
              ),
             ('DateEntity', _gen_extid(),
              {'end_date': [datetime.date(2009, 1, 1)],
-              'start_date': [datetime.date(1917, 1, 1)]}
+              'start_date': [datetime.date(1917, 1, 1)],
+              'raw_date': set([u'1917 ; 2009'])
+              },
              ),
             ('AssociationRelation', _gen_extid(),
              {'association_from': set(['authorityrecord-FRAD033_EAC_00001']),
@@ -537,7 +551,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1673, 1, 1)]),
-              'end_date': set([datetime.date(1963, 1, 1)])
+              'end_date': set([datetime.date(1963, 1, 1)]),
+              'raw_date': set([u'1673 ; 1963'])
               },
              ),
             ('EACFunctionRelation', _gen_extid(),
@@ -588,7 +603,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1922, 1, 1)]),
-              'end_date': set([datetime.date(2001, 1, 1)])
+              'end_date': set([datetime.date(2001, 1, 1)]),
+              'raw_date': set([u'1922 ; 2001'])
               },
              ),
             ('EACFunctionRelation', _gen_extid(),
@@ -607,7 +623,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1922, 1, 1)]),
-              'end_date': set([datetime.date(2001, 1, 1)])
+              'end_date': set([datetime.date(2001, 1, 1)]),
+              'raw_date': set([u'1922 ; 2001'])
               },
              ),
             ('EACFunctionRelation', _gen_extid(),
@@ -626,7 +643,8 @@
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1922, 1, 1)]),
-              'end_date': set([datetime.date(2001, 1, 1)])
+              'end_date': set([datetime.date(2001, 1, 1)]),
+              'raw_date': set([u'1922 ; 2001'])
               },
              ),
             ('ExternalUri', 'ONLY_XLINK',
@@ -695,11 +713,11 @@
                           'recordId': set([8]),
                           'maintenanceAgency': set([16]),
                           'languageDeclaration': set([21]),
-                          'languageUsed': set([188, 195]),
+                          'languageUsed': set([186, 193]),
                           'localControl': set([54]),
                           'source': set([76]),  # empty.
-                          'structureOrGenealogy': set([268]),  # empty.
-                          'biogHist': set([328, 331]),  # empty.
+                          'structureOrGenealogy': set([266]),  # empty.
+                          'biogHist': set([326, 329]),  # empty.
                           })
 
     def check_order_entities(self, entities, expected):



More information about the saem-devel mailing list