[PATCH 1 of 3 eac V2] EACFunctionRelation add json dump support

Frank Bessou frank.bessou at logilab.fr
Mon Aug 19 15:46:51 CEST 2019



On 19/08/2019 15:30, Guillaume Vandevelde wrote:
> # HG changeset patch
> # User Guillaume Vandevelde <gvandevelde at logilab.fr>
> # Date 1566219818 -7200
> #      Mon Aug 19 15:03:38 2019 +0200
> # Node ID 5399160e43df7b26039f112a74ad716558688d13
> # Parent  351377a503a44b10f0e8c297b0bfb08858c5ed65
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r 5399160e43df
> EACFunctionRelation add json dump support


I see three modifications in this changeset:
Rename "attributes" to "xml_attributes"
Add default value on import of FunctionRelation xml attributes
Change the way attributes are stored in xml_attributes (can probably be 
merged with another changeset).


> 
> diff -r 351377a503a4 -r 5399160e43df cubicweb_eac/dataimport.py
> --- a/cubicweb_eac/dataimport.py	Mon Aug 19 15:03:41 2019 +0200
> +++ b/cubicweb_eac/dataimport.py	Mon Aug 19 15:03:38 2019 +0200
> @@ -866,9 +866,11 @@
>               elem,
>               (('place_entry', 'eac:placeEntry'),
>                ('relation_entry', 'eac:relationEntry'))))
> -        attrib = sorted(dict(elem.attrib).items())
> -        if attrib:
> -            values.update({'attributes': set([text_type(attrib)])})
> +        if elem.attrib:
> +            attributes = json.dumps(dict(elem.attrib), sort_keys=True)
> +        else:
> +            attributes = json.dumps({})
> +        values.update({'xml_attributes': set([text_type(attributes)])})
>           yield ExtEntity('EACFunctionRelation', self._gen_extid(), values)
>   
>       @add_xml_wrap_for('EACResourceRelation')
> diff -r 351377a503a4 -r 5399160e43df cubicweb_eac/entities.py
> --- a/cubicweb_eac/entities.py	Mon Aug 19 15:03:41 2019 +0200
> +++ b/cubicweb_eac/entities.py	Mon Aug 19 15:03:38 2019 +0200
> @@ -149,7 +149,7 @@
>                                                   'description',
>                                                   'relation_entry',
>                                                   'place_entry',
> -                                                'attributes',))
> +                                                'xml_attributes',))
>   
>       @property
>       def record(self):
> diff -r 351377a503a4 -r 5399160e43df cubicweb_eac/migration/0.9.0_Any.py
> --- a/cubicweb_eac/migration/0.9.0_Any.py	Mon Aug 19 15:03:41 2019 +0200
> +++ b/cubicweb_eac/migration/0.9.0_Any.py	Mon Aug 19 15:03:38 2019 +0200
> @@ -4,3 +4,4 @@
>   add_entity_type('EACFunctionRelation')
>   add_attribute('EACResourceRelation', 'xml_attributes')
>   add_attribute('EACResourceRelation', 'relation_entry')
> +add_attribute('EACFunctionRelation', 'xml_attributes')
> diff -r 351377a503a4 -r 5399160e43df cubicweb_eac/schema.py
> --- a/cubicweb_eac/schema.py	Mon Aug 19 15:03:41 2019 +0200
> +++ b/cubicweb_eac/schema.py	Mon Aug 19 15:03:38 2019 +0200
> @@ -379,7 +379,7 @@
>       description = RichString(fulltextindexed=True)
>       relation_entry = String(fulltextindexed=True)
>       place_entry = String(fulltextindexed=True)
> -    attributes = String(fulltextindexed=True)
> +    xml_attributes = String(fulltextindexed=True)
>   
>   
>   class function_relation_agent(RelationDefinition):
> diff -r 351377a503a4 -r 5399160e43df test/test_dataimport.py
> --- a/test/test_dataimport.py	Mon Aug 19 15:03:41 2019 +0200
> +++ b/test/test_dataimport.py	Mon Aug 19 15:03:38 2019 +0200
> @@ -424,10 +424,10 @@
>                                  u'">Boschiero\n\t      </namePart>\n\t      <role>\n\t\t<roleTerm'
>                                  u' type="text">autore\n\t\t</roleTerm>\n\t      </role>\n\t'
>                                  u'    </name>\n\t  </mods>\n\t']),
> -              'attributes': set([u"[('{http://www.w3.org/1999/xlink}actuate', 'onLoad'),"
> -                                 u" ('{http://www.w3.org/1999/xlink}arcrole',"
> -                                 u" 'http://test_arcrole.lol.com'), ('{http://www.w3."
> -                                 u"org/1999/xlink}role', 'http://test_role.lmao.com')]"])
> +              'xml_attributes': set([u'{"{http://www.w3.org/1999/xlink}actuate": "onLoad", "{http:'
> +                                     u'//www.w3.org/1999/xlink}arcrole": "http://test_arcrole.lol.c'
> +                                     u'om", "{http://www.w3.org/1999/xlink}role": "http://'
> +                                     u'test_role.lmao.com"}'])
>                 },
>                ),
>               ('EACFunctionRelation', _gen_extid(),
> @@ -443,7 +443,8 @@
>                 'r_type': set([u'controls']),
>                 'description_format': set([u'text/html']),
>                 'relation_entry': set([u'Establishment and abolishment\n\tof schools\n\t']),
> -              'start_date': set([datetime.date(1922, 1, 1)])
> +              'start_date': set([datetime.date(1922, 1, 1)]),
> +              'xml_attributes': set([u'{}'])
>                 },
>                ),
>               ('EACFunctionRelation', _gen_extid(),
> @@ -457,7 +458,8 @@
>                 'end_date': set([datetime.date(2001, 1, 1)]),
>                 'description_format': set([u'text/html']),
>                 'relation_entry': set([u'Some relation entry\n          ']),
> -              'start_date': set([datetime.date(1922, 1, 1)])
> +              'start_date': set([datetime.date(1922, 1, 1)]),
> +              'xml_attributes': set([u'{}'])
>                 },
>                ),
>               ('EACFunctionRelation', _gen_extid(),
> @@ -471,7 +473,8 @@
>                 'end_date': set([datetime.date(2001, 1, 1)]),
>                 'description_format': set([u'text/html']),
>                 'relation_entry': set([u'Some relation entry\n          ']),
> -              'start_date': set([datetime.date(1922, 1, 1)])
> +              'start_date': set([datetime.date(1922, 1, 1)]),
> +              'xml_attributes': set([u'{}'])
>                 },
>                ),
>               ('ExternalUri', 'ONLY_XLINK',
> @@ -767,11 +770,12 @@
>                                                   u"{http://www.w3.org/1999/xlink}type": u"simple"})
>           rset = cnx.find('EACFunctionRelation', r_type=u'performs')
>           func_relation = rset.one()
> -        self.assertEqual(func_relation.attributes,
> -                         u"[('{http://www.w3.org/1999/xlink}actuate', "
> -                         u"'onLoad'), ('{http://www.w3.org/1999/xlink}arcrole',"
> -                         u" 'http://test_arcrole.lol.com'), ('{http://www.w3.org"
> -                         u"/1999/xlink}role', 'http://test_role.lmao.com')]")
> +        self.assertEqual(func_relation.xml_attributes,
> +                         u'{"{http://www.w3.org/1999/xlink}actuate": "onLoad", '
> +                         u'"{http://www.w3.org/1999/xlink}arcrole": '
> +                         u'"http://test_arcrole.lol.com", '
> +                         u'"{http://www.w3.org/1999/xlink}role": '
> +                         u'"http://test_role.lmao.com"}')
>           self.assertEqual(func_relation.relation_entry,
>                            u'Alumni communication\n\tmanagement, '
>                            'University of\n\tGlasgow\n\t')
> 

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



More information about the saem-devel mailing list