[PATCH eac V2] Implement raw_address attribute for PostalAddress

gvandevelde guillaume.vandevelde at logilab.fr
Mon Sep 30 11:58:05 CEST 2019


The address line joigning loop was deplaced near the list comprehension 
defining the address lignes. (74dcbed9788d)


On 9/30/19 11:46 AM, 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 ba161b73be015ef2565ecef35470552bab72da94
> # Parent  fde7d0a19cefdaf4cb5978c46904945f0420837a
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r ba161b73be01
> Implement raw_address attribute for PostalAddress
>
> diff -r fde7d0a19cef -r ba161b73be01 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 = {}
> -        for line in self._elem_findall(elem, 'eac:addressLine'):
> +        address_elems = self._elem_findall(elem, 'eac:addressLine')
> +        address_lines = [text_type(e.text.strip())
> +                         for e in address_elems if e.text and e.text.strip()]
> +        for line in address_elems:
>               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 ba161b73be01 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 ba161b73be01 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 ba161b73be01 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""", {
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/saem-devel/attachments/20190930/4e3c8f88/attachment-0185.html>


More information about the saem-devel mailing list