[PATCH eac] Add new `agent_type` attribute for Activity entity

Frank Bessou frank.bessou at logilab.fr
Wed Aug 28 11:46:39 CEST 2019



On 28/08/2019 11:43, Guillaume Vandevelde wrote:
> # HG changeset patch
> # User Guillaume Vandevelde <gvandevelde at logilab.fr>
> # Date 1563887776 -7200
> #      Tue Jul 23 15:16:16 2019 +0200
> # Node ID be4fbddff6630a694a9681e0e6c8292722746666
> # Parent  67ecf498201c1998cb49e179a8b965731c54f167
> # Available At http://hg.logilab.org/review/cubes/eac
> #              hg pull http://hg.logilab.org/review/cubes/eac -r be4fbddff663
> Add new `agent_type` attribute for Activity entity
> 
> diff -r 67ecf498201c -r be4fbddff663 cubicweb_eac/dataimport.py
> --- a/cubicweb_eac/dataimport.py	Tue Jul 23 17:31:41 2019 +0200
> +++ b/cubicweb_eac/dataimport.py	Tue Jul 23 15:16:16 2019 +0200
> @@ -1067,9 +1067,8 @@
>                       values['start'] = set([event_date])
>                       values['end'] = set([event_date])
>           values.update(self.parse_tag_description(elem, 'eac:eventDescription'))
> -        agent = self._elem_find(elem, 'eac:agent')
> -        if agent is not None and agent.text:
> -            values['agent'] = set([text_type(agent.text)])
> +        values.update(self.values_from_xpaths(elem, (('agent', 'eac:agent'),
> +                                                     ('agent_type', 'eac:agentType'))))
>           yield ExtEntity('Activity', self._gen_extid(), values)
>   
>       @relate_to_record_through('Convention', 'convention_of')
> diff -r 67ecf498201c -r be4fbddff663 cubicweb_eac/migration/0.9.0_Any.py
> --- a/cubicweb_eac/migration/0.9.0_Any.py	Tue Jul 23 17:31:41 2019 +0200
> +++ b/cubicweb_eac/migration/0.9.0_Any.py	Tue Jul 23 15:16:16 2019 +0200
> @@ -51,3 +51,5 @@
>       add_attribute(etype, 'items')
>       
>   add_relation_type('place_entry_relation')
> +
> +add_attribute('Activity', 'agent_type')
> diff -r 67ecf498201c -r be4fbddff663 cubicweb_eac/schema.py
> --- a/cubicweb_eac/schema.py	Tue Jul 23 17:31:41 2019 +0200
> +++ b/cubicweb_eac/schema.py	Tue Jul 23 15:16:16 2019 +0200
> @@ -17,7 +17,7 @@
>   
>   from yams.buildobjs import (EntityType, RelationDefinition, String, Date, Bytes,
>                               RichString, Float, ComputedRelation)
> -from yams.constraints import BoundaryConstraint, Attribute
> +from yams.constraints import BoundaryConstraint, StaticVocabularyConstraint, Attribute
>   
>   from cubicweb import _
>   from cubicweb.schema import RRQLExpression, RQLVocabularyConstraint
> @@ -47,6 +47,10 @@
>   
>   Activity.add_relation(String(description=_('the agent responsible for this activity'),
>                                indexed=True, fulltextindexed=True), name='agent')
> +Activity.add_relation(String(
> +    constraints=[StaticVocabularyConstraint(('human', 'machine', 'unknown'))],

According to:
https://cubicweb.readthedocs.io/en/latest/book/devrepo/datamodel/definition/#defining-your-schema-using-yams

this is equivalent to:

vocabulary=['human', 'machine', 'unknown']

also, you can register these strings for translation:

vocabulary=[_('human'), _('machine'), _('unknown')]


> +    description=_('the type of the agent linked to the activity'),
> +    indexed=True, fulltextindexed=True), name='agent_type')
>   
>   
>   class AuthorityRecord(EntityType):
> diff -r 67ecf498201c -r be4fbddff663 test/test_dataimport.py
> --- a/test/test_dataimport.py	Tue Jul 23 17:31:41 2019 +0200
> +++ b/test/test_dataimport.py	Tue Jul 23 15:16:16 2019 +0200
> @@ -120,6 +120,7 @@
>                ),
>               ('Activity', _gen_extid(),
>                {'type': set([u'create']),
> +              'agent_type': [u'human'],
>                 'generated': set(['FRAD033_EAC_00001']),
>                 'start': set([datetime.datetime(2013, 4, 24, 5, 34, 41)]),
>                 'end': set([datetime.datetime(2013, 4, 24, 5, 34, 41)]),
> @@ -130,6 +131,7 @@
>               ('Activity', _gen_extid(),
>                {'generated': set(['FRAD033_EAC_00001']),
>                 'type': set([u'modify']),
> +              'agent_type': [u'human'],
>                 'start': set([datetime.datetime(2015, 1, 15, 7, 16, 33)]),
>                 'end': set([datetime.datetime(2015, 1, 15, 7, 16, 33)]),
>                 'agent': set([u'Delphine Jamet'])
> 

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



More information about the saem-devel mailing list