[saem-devel] [PATCH 3 of 3] [migration] Add migration script to set ark on existing organizations

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Feb 21 15:04:21 CET 2017


comments addressed, v2 of this patch sent to the list.


Le 08/02/2017 à 14:04, Denis Laxalde a écrit :
> Sylvain Thenault a écrit :
>> # HG changeset patch
>> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
>> # Date 1486455063 -3600
>> #      Tue Feb 07 09:11:03 2017 +0100
>> # Node ID b6b6cf96bef0e1ee9dd0c58f2bf7ceaaf5cc2944
>> # Parent  4e5e28519eb9b90ce2f2ec76e6fed21ee53aa4f8
>> [migration] Add migration script to set ark on existing organizations
>>
>> The 0.14.0 migration script added the attribute but didn't set it on
>> pre-existing organization.
>>
>> diff --git a/cubicweb_saem_ref/migration/0.14.3_Any.py
>> b/cubicweb_saem_ref/migration/0.14.3_Any.py
>> new file mode 100644
>> --- /dev/null
>> +++ b/cubicweb_saem_ref/migration/0.14.3_Any.py
>> @@ -0,0 +1,18 @@
>> +from cubicweb_saem_ref.hooks import set_ark_and_cwuri
>> +
>> +
>> +def fix_organization_ark(cnx):
>> +    with cnx.security_enabled(write=False):
>> +        rset = cnx.execute('Any O WHERE O ark NULL, O is Organization')
>> +        for i, org in enumerate(rset.entities()):
>
> "i" does not appear to be used.
>
>> +            if org.ark_naa:
>> +                naa_what = org.ark_naa[0].what
>> +            else:
>> +                naa_what = u'XXX'
>
> maybe "continue" here instead of setting something obviously wrong?
> Otherwise, explain :)
>
>> +            attrs = {}
>> +            set_ark_and_cwuri(cnx, org.eid, 'Organization', attrs,
>> naa_what=naa_what)
>> +            org.cw_set(**attrs)
>> +        cnx.commit()
>> +
>> +
>> +fix_organization_ark(cnx)
> _______________________________________________
> saem-devel mailing list
> saem-devel at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/saem-devel

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list