[saem-devel] [PATCH] [hook] export EAC ARK on AuthorityRecordId

Philippe Pepiot philippe.pepiot at logilab.fr
Wed Feb 15 14:47:25 CET 2017



On 02/09/2017 01:13 PM, Denis Laxalde wrote:
> Philippe Pepiot a écrit :
>> # HG changeset patch
>> # User Philippe Pepiot <philippe.pepiot at logilab.fr>
>> # Date 1486565867 -3600
>> #      Wed Feb 08 15:57:47 2017 +0100
>> # Node ID 1fb0cc9f7273c44e9953ea6b02d1bc135ab14089
>> # Parent  8a064175a178fcaa2e116f031821b70e786ddbce
>> # Available At https://hg.logilab.org/review/cubes/saem_ref
>> #              hg pull https://hg.logilab.org/review/cubes/saem_ref 
>> -r 1fb0cc9f7273
>> # Tested at https://jenkins.logilab.org/job/cubicweb-saem_ref/78/
>> [hook] export EAC ARK on AuthorityRecordId
>>
>> Copy (eventually) created recordId to otherRecordId and set recordId 
>> to ARK
>> (thus export ARK in a <recordId /> field).
>>
>> Closes extranet #12572781
>>
>> diff --git a/cubicweb_saem_ref/hooks.py b/cubicweb_saem_ref/hooks.py
>> --- a/cubicweb_saem_ref/hooks.py
>> +++ b/cubicweb_saem_ref/hooks.py
>> @@ -222,6 +222,27 @@ def extract_ark(url):
>>      return ark
>>
>>
>> +class AuthorityRecordIdOp(hook.DataOperationMixIn, hook.Operation):
>> +    """Copy EAC recordId to otherRecordId and set recordId to ARK"""
>> +
>> +    def precommit_event(self):
>> +        cnx = self.cnx
>> +        for entity in self.get_data():
>> +            if entity.record_id:
>> +                cnx.create_entity('EACOtherRecordId', 
>> value=entity.record_id,
>> + eac_other_record_id_of=entity)
>> +                entity.cw_set(record_id=entity.ark)
>> +
>> +
>> +class AuthorityRecordIdHook(hook.Hook):
>> +    __regid__ = 'saem_ref.authority_record_id'
>> +    __select__ = hook.Hook.__select__ & is_instance('AuthorityRecord')
>> +    events = ('after_add_entity',)
>> +
>> +    def __call__(self):
>> + AuthorityRecordIdOp.get_instance(self._cw).add_data(self.entity)
>> +
>> +
>
> I wonder why this is done in 'after_add_entity' event and using an
> operation. Couldn't it be a 'before_entity_event' so that you'd update
> 'self.entity.cw_edited'? Otherwise, this deserves an explanation.

Since ark assignation is done in a 'before_add_entity' event, I thought 
that I might be better to not rely on hook execution order for this.

-- 
Philippe Pepiot
https://www.logilab.fr



More information about the saem-devel mailing list