[PATCH eac V3] Add item atttribute and functions to implement <list> <item>

gvandevelde guillaume.vandevelde at logilab.fr
Thu Aug 22 16:37:56 CEST 2019


Message de commit changé,

Hash du nouveau changeset:

f0f7b8fae35c

On 8/22/19 4:32 PM, Guillaume Vandevelde wrote:
> # HG changeset patch
> # User Guillaume Vandevelde <gvandevelde at logilab.fr>
> # Date 1563894538 -7200
> #      Tue Jul 23 17:08:58 2019 +0200
> # Node ID 65438f330a02e7784514d849fb8dda1acbdc3584
> # Parent  901576a43c42f021873a04eebd973f25dbdeffee
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r 65438f330a02
> Add item atttribute and functions to implement <list> <item>
>
> diff -r 901576a43c42 -r 65438f330a02 cubicweb_eac/dataimport.py
> --- a/cubicweb_eac/dataimport.py	Fri Jul 26 13:56:10 2019 +0200
> +++ b/cubicweb_eac/dataimport.py	Tue Jul 23 17:08:58 2019 +0200
> @@ -18,6 +18,7 @@
>   """
>   
>   from collections import deque
> +import copy
>   import json
>   import datetime
>   from functools import wraps, partial
> @@ -136,6 +137,22 @@
>       return decorator
>   
>   
> +def add_items_for(etype):
> +    """Add an `items` attribute in ExtEntity's values dictionnary."""
> +    def decorator(func):
> +        @wraps(func)
> +        def wrapper(self, elem):
> +            for extentity in func(self, elem):
> +                if extentity.etype == etype:
> +                    items = self.parse_items(elem)
> +                    if items:
> +                        extentity.values['items'] = set([items])
> +                        extentity.values['items_format'] = set([u'text/html'])
> +                yield extentity
> +        return wrapper
> +    return decorator
> +
> +
>   def relate_to_record_through(etype, rtype):
>       """Add an ``rtype`` relationship from ``etype`` to the imported record."""
>       def decorator(func):
> @@ -313,6 +330,16 @@
>                   values[var_name] = set([text_type(var.text)])
>           return values
>   
> +    def parse_items(self, elem):
> +        values = []
> +        new_elem = copy.deepcopy(elem)
> +        for list_elem in self._elem_findall(new_elem, 'eac:list'):
> +            list_elem.tag = 'ul'
> +            for child in self._elem_findall(list_elem, 'eac:item'):
> +                child.tag = 'li'
> +            values.append(list_elem)
> +        return u"\n".join(etree.tostring(item, encoding='utf-8') for item in values)
> +
>       def record_visited(self, elem, extentity):
>           assert extentity.extid, extentity
>           self._visited.setdefault(elem, set([])).add(extentity.extid)
> @@ -468,7 +495,8 @@
>                   yield extentity
>           # structure
>           for structure in self._elem_findall(description, 'eac:structureOrGenealogy'):
> -            yield self.build_structure(structure)
> +            for extentity in self.build_structure(structure):
> +                yield extentity
>           # function
>           for function in self.find_nested(description, 'eac:function', 'eac:functions'):
>               for extentity in self.build_function(function):
> @@ -566,6 +594,7 @@
>       @relate_to_record_through('LegalStatus', 'legal_status_agent')
>       @filter_empty
>       @add_citations_for('LegalStatus')
> +    @add_items_for('LegalStatus')
>       @add_dates_for('LegalStatus')
>       @equivalent_concept('eac:term', 'LegalStatus')
>       def build_legal_status(self, elem, **kwargs):
> @@ -583,6 +612,7 @@
>       @relate_to_record_through('Mandate', 'mandate_agent')
>       @filter_empty
>       @add_citations_for('Mandate')
> +    @add_items_for('Mandate')
>       @add_dates_for('Mandate')
>       @equivalent_concept('eac:term', 'Mandate')
>       def build_mandate(self, elem, **kwargs):
> @@ -619,6 +649,7 @@
>       @relate_to_record_through('History', 'history_agent')
>       @add_events_for('History')
>       @add_citations_for('History')
> +    @add_items_for('History')
>       @elem_maybe_none
>       def build_history(self, elem):
>           """Build a `History` external entity."""
> @@ -648,18 +679,20 @@
>   
>       @elem_maybe_none
>       @relate_to_record_through('Structure', 'structure_agent')
> +    @add_items_for('Structure')
>       def build_structure(self, elem):
>           """Build a `Structure` external entity."""
>           desc, desc_format = self.parse_tag_content(elem)
>           if desc:
>               values = {'description': set([desc]),
>                         'description_format': set([desc_format])}
> -            return ExtEntity('Structure', self._gen_extid(), values)
> +            yield ExtEntity('Structure', self._gen_extid(), values)
>   
>       @relate_to_record_through('AgentPlace', 'place_agent')
>       @filter_empty
>       @add_citations_for('AgentPlace')
>       @add_dates_for('AgentPlace')
> +    @add_items_for('AgentPlace')
>       @equivalent_concept('eac:placeEntry', 'AgentPlace')
>       def build_place(self, elem):
>           """Build a AgentPlace external entity"""
> @@ -692,6 +725,7 @@
>       @filter_empty
>       @add_citations_for('AgentFunction')
>       @add_dates_for('AgentFunction')
> +    @add_items_for('AgentFunction')
>       @equivalent_concept('eac:term', 'AgentFunction')
>       def build_function(self, elem):
>           """Build a `AgentFunction`s external entities"""
> @@ -704,6 +738,7 @@
>       @relate_to_record_through('Occupation', 'occupation_agent')
>       @filter_empty
>       @add_citations_for('Occupation')
> +    @add_items_for('Occupation')
>       @add_dates_for('Occupation')
>       @equivalent_concept('eac:term', 'Occupation')
>       def build_occupation(self, elem):
> @@ -716,6 +751,7 @@
>   
>       @relate_to_record_through('GeneralContext', 'general_context_of')
>       @add_citations_for('GeneralContext')
> +    @add_items_for('GeneralContext')
>       def build_generalcontext(self, elem):
>           """Build a `GeneralContext` external entity"""
>           content, content_format = self.parse_tag_content(elem)
> diff -r 901576a43c42 -r 65438f330a02 cubicweb_eac/migration/0.9.0_Any.py
> --- a/cubicweb_eac/migration/0.9.0_Any.py	Fri Jul 26 13:56:10 2019 +0200
> +++ b/cubicweb_eac/migration/0.9.0_Any.py	Tue Jul 23 17:08:58 2019 +0200
> @@ -27,3 +27,8 @@
>           E start_date SD, E end_date ED""".format(etype))
>       drop_attribute(etype, 'start_date')
>       drop_attribute(etype, 'end_date')
> +
> +for etype in ('GeneralContext', 'Mandate', 'Occupation', 'History',
> +              'AgentFunction', 'LegalStatus', 'AgentPlace', 'Structure'):
> +    add_attribute(etype, 'items')
> +
> diff -r 901576a43c42 -r 65438f330a02 cubicweb_eac/schema.py
> --- a/cubicweb_eac/schema.py	Fri Jul 26 13:56:10 2019 +0200
> +++ b/cubicweb_eac/schema.py	Tue Jul 23 17:08:58 2019 +0200
> @@ -38,6 +38,13 @@
>       return cls
>   
>   
> +def with_items(cls):
> +    """Class decorator adding an `items` attribute to an EntityType"""
> +    desc = _('HTML list of elements')
> +    cls.add_relation(RichString(description=desc), name='items')
> +    return cls
> +
> +
>   Activity.add_relation(String(description=_('the agent responsible for this activity'),
>                                indexed=True, fulltextindexed=True), name='agent')
>   
> @@ -107,6 +114,7 @@
>       inlined = True
>   
>   
> + at with_items
>   class AgentFunction(EntityType):
>       """The function of an AuthorityRecord"""
>       name = String(fulltextindexed=True, internationalizable=True)
> @@ -123,6 +131,7 @@
>       inlined = True
>   
>   
> + at with_items
>   class AgentPlace(EntityType):
>       """Qualified relation between an AuthorityRecord and a PostalAddress"""
>       name = String(fulltextindexed=True,
> @@ -179,6 +188,7 @@
>       inlined = True
>   
>   
> + at with_items
>   class GeneralContext(EntityType):
>       """Information about the general social and cultural context of an authority record"""
>       content = RichString(fulltextindexed=True)
> @@ -263,12 +273,14 @@
>       object = 'AuthorityRecord'
>   
>   
> + at with_items
>   class Mandate(EntityType):
>       """Reference text coming from an authority"""
>       term = String(fulltextindexed=True)
>       description = RichString(fulltextindexed=True)
>   
>   
> + at with_items
>   class LegalStatus(EntityType):
>       """Information relative to the legal status of an authority"""
>       term = String(fulltextindexed=True)
> @@ -281,6 +293,7 @@
>       description = RichString(fulltextindexed=True)
>   
>   
> + at with_items
>   class History(EntityType):
>       """Biographical or historical information"""
>       abstract = RichString(fulltextindexed=True)
> @@ -301,11 +314,13 @@
>       description = _('HistoricalEvent with date for describing an historical event')
>   
>   
> + at with_items
>   class Structure(EntityType):
>       """Information about the structure of an authority"""
>       description = RichString(fulltextindexed=True)
>   
>   
> + at with_items
>   class Occupation(EntityType):
>       term = String(fulltextindexed=True)
>       description = RichString(fulltextindexed=True)
> diff -r 901576a43c42 -r 65438f330a02 test/data/FRAD033_EAC_00001_simplified.xml
> --- a/test/data/FRAD033_EAC_00001_simplified.xml	Fri Jul 26 13:56:10 2019 +0200
> +++ b/test/data/FRAD033_EAC_00001_simplified.xml	Tue Jul 23 17:08:58 2019 +0200
> @@ -223,6 +223,26 @@
>   	  </chronList>
>   	  <chronList></chronList>
>   	  <chronList><chronItem></chronItem></chronList>
> +	  <list>
> +	    <item>
> +	      <span style="font-
> +			   style:italic">1450-1950
> +	      </span>
> +	      (1929)
> +	    </item>
> +	    <item>
> +	      <span style="font-style:italic">Globe
> +	      Gliding
> +	      </span>
> +	      (1930)
> +	    </item>
> +	    <item>
> +	      <span style="font-
> +			   style:italic">Gems
> +	      </span>
> +	      (1931)
> +	    </item>
> +	  </list>
>         </biogHist>
>   
>         <!--empty biogHist-->
> diff -r 901576a43c42 -r 65438f330a02 test/test_dataimport.py
> --- a/test/test_dataimport.py	Fri Jul 26 13:56:10 2019 +0200
> +++ b/test/test_dataimport.py	Tue Jul 23 17:08:58 2019 +0200
> @@ -245,6 +245,17 @@
>                                             u"L'inspecteur Canardo"])
>                 ]),
>                 'text_format': set([u'text/html']),
> +              'items': set([u'<ul xmlns="urn:isbn:1-931666-33-4" '
> +                            u'xmlns:xlink="http://www.w3.org/1999'
> +                            u'/xlink">\n\t    <li>\n\t      <span style="font-       '
> +                            u'style:italic">1450-1950\n\t      </span>\n\t      '
> +                            u'(1929)\n\t    </li>\n\t    <li>\n\t      <span '
> +                            u'style="font-style:italic">Globe\n\t      '
> +                            u'Gliding\n\t      </span>\n\t      (1930)\n\t    '
> +                            u'</li>\n\t    <li>\n\t      <span style="font-'
> +                            u'       style:italic">Gems\n\t      </span>\n\t'
> +                            u'      (1931)\n\t    </li>\n\t  </ul>\n      ']),
> +              'items_format': set([u'text/html']),
>                 'history_agent': set(['FRAD033_EAC_00001']),
>                 'has_citation': set(['21', '22']),
>                 'has_event': set(['24', '23']),
> @@ -571,7 +582,7 @@
>                             'localControl': set([54]),
>                             'source': set([76]),  # empty.
>                             'structureOrGenealogy': set([189]),  # empty.
> -                          'biogHist': set([229, 232]),  # empty.
> +                          'biogHist': set([249, 252]),  # empty.
>                             })
>   
>       def check_order_entities(self, entities, expected):
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/saem-devel/attachments/20190822/232bec8c/attachment-0185.html>


More information about the saem-devel mailing list