[PATCH eac] Implement raw_address attribute for PostalAddress

Frank Bessou frank.bessou at logilab.fr
Mon Sep 30 11:52:58 CEST 2019


On 30/09/2019 11:10, Guillaume Vandevelde wrote:
> # HG changeset patch
> # User Guillaume Vandevelde <gvandevelde at logilab.fr>
> # Date 1567160601 -7200
> #      Fri Aug 30 12:23:21 2019 +0200
> # Node ID a82e653362c729bd179e5539ea0c9aa12a9ce77e
> # Parent  fde7d0a19cefdaf4cb5978c46904945f0420837a
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r a82e653362c7
> Implement raw_address attribute for PostalAddress
> 
> diff -r fde7d0a19cef -r a82e653362c7 cubicweb_eac/dataimport.py
> --- a/cubicweb_eac/dataimport.py	Wed Sep 04 18:25:45 2019 +0200
> +++ b/cubicweb_eac/dataimport.py	Fri Aug 30 12:23:21 2019 +0200
> @@ -827,12 +827,17 @@
>       def build_address(self, elem):
>           """Build `PostalAddress`s external entity"""
>           address_entity = {}
> +        address_lines = []
>           for line in self._elem_findall(elem, 'eac:addressLine'):
> +            if line.text and line.text.strip():
> +                address_lines.append(text_type(line.text.strip()))

In this loop there are two things done
- part of the raw address generation
- generation of standard attributes of the PostalAddress

The raw address is finalized later.

I think we could gain clarity by visually separating these two things.

extract_raw_address() #  or equivalent code
extract_standard_attributes()  #  or equivalent code
yield ExtEntity(...)


>               if 'localType' in line.attrib:
>                   attr = dict(ADDRESS_MAPPING).get(line.attrib['localType'])
>                   if attr:
>                       address_entity.setdefault(attr, set()).add(
>                           text_type(line.text))
> +        if address_lines:
> +            address_entity['raw_address'] = set([u'\n'.join(address_lines)])
>           yield ExtEntity('PostalAddress', self._gen_extid(), address_entity)
>   
>       @relate_to_record_through('AgentFunction', 'function_agent')
> diff -r fde7d0a19cef -r a82e653362c7 cubicweb_eac/migration/0.9.0_Any.py
> --- a/cubicweb_eac/migration/0.9.0_Any.py	Wed Sep 04 18:25:45 2019 +0200
> +++ b/cubicweb_eac/migration/0.9.0_Any.py	Fri Aug 30 12:23:21 2019 +0200
> @@ -11,6 +11,7 @@
>   add_attribute('EACResourceRelation', 'xml_attributes')
>   add_attribute('EACResourceRelation', 'relation_entry')
>   add_attribute('DateEntity', 'raw_date')
> +add_attribute('PostalAddress', 'raw_address')
>   
>   add_attribute('History', 'abstract')
>   
> diff -r fde7d0a19cef -r a82e653362c7 cubicweb_eac/schema.py
> --- a/cubicweb_eac/schema.py	Wed Sep 04 18:25:45 2019 +0200
> +++ b/cubicweb_eac/schema.py	Fri Aug 30 12:23:21 2019 +0200
> @@ -22,13 +22,17 @@
>   from cubicweb import _
>   from cubicweb.schema import RRQLExpression, RQLVocabularyConstraint
>   
> -from cubes.addressbook import schema as addressbook
> +from cubicweb_addressbook.schema import PostalAddress
>   from cubicweb_prov.schema import Activity
>   
>   
>   # Customization of addressbook schema.
>   for attrname in ('street', 'city', 'postalcode'):
> -    addressbook.PostalAddress.get_relation(attrname).cardinality = '?1'
> +    PostalAddress.get_relation(attrname).cardinality = '?1'
> +
> +PostalAddress.add_relation(
> +    String(description=_("Attribute containing concatenated <addressLine> values"),
> +           indexed=True, fulltextindexed=True), name='raw_address')
>   
>   
>   def xml_wrap(cls):
> diff -r fde7d0a19cef -r a82e653362c7 test/test_dataimport.py
> --- a/test/test_dataimport.py	Wed Sep 04 18:25:45 2019 +0200
> +++ b/test/test_dataimport.py	Fri Aug 30 12:23:21 2019 +0200
> @@ -246,6 +246,7 @@
>               ('PostalAddress', _gen_extid(),
>                {'street': set([u'1 Esplanade Charles de Gaulle']),
>                 'postalcode': set([u'33074']),
> +              'raw_address': set([u'1 Esplanade Charles de Gaulle\n33074\nBordeaux Cedex']),
>                 'city': set([u' Bordeaux Cedex']),
>                 },
>                ),
> @@ -864,6 +865,8 @@
>               self.assertEqual(address.street, u'1 Esplanade Charles de Gaulle')
>               self.assertEqual(address.postalcode, u'33074')
>               self.assertEqual(address.city, u' Bordeaux Cedex')
> +            self.assertEqual(address.raw_address,
> +                             u'1 Esplanade Charles de Gaulle\n33074\nBordeaux Cedex')
>               rset = cnx.execute("""
>                    Any R,N WHERE P place_agent A, A eid %(eid)s,
>                    P role R, P place_entry_relation E, E name N""", {
> 

-- 
Frank Bessou
Logilab         https://www.logilab.fr



More information about the saem-devel mailing list