Le 9 août 2013 17:35, "Guewen Baconnier @ Camptocamp" <
<email address hidden>> a écrit :
>
> Thanks for the patch!
> I think that's the responsibility of the mappers and not of the
synchronizer. Although, not all models have those fields.
>
> In the mappers, these fields are actually in direct mappings:
>
> direct = [
> ('created_at', 'created_at'),
> ('updated_at', 'updated_at'),
> ]
>
> The simple but a bit tedious solution is to transform all of them in
> method mappings:
>
> @mapping
> def created_at(self, record):
> return normalize_date(record['created_at'])
>
> Where normalize_date would be a simple helper which clean the invalid
> dates:
>
> def normalize_date(value):
> if value == '0000-00-00 00:00:00':
> return None
> return value
>
> The solution I would prefer is to add the possibility (directly in the
`connector` module) to give a transformation method on the direct mappings.
> Either in this form:
>
> direct = [
> ('created_at', normalize_date('created_at')),
> ('updated_at', normalize_date('updated_at')),
> ]
>
> (using a closure like:
> def normalize_date(field):
> def transform(self, record):
> if record[field] == '0000-00-00 00:00:00':
> return None
> return record[field]
> return transform
> )
>
With a bit more of thinking that's definitely my preferred form as we can
write a generic converter for types or have special arguments that the
3-items tuple below would not permit. Example
> Or in this form:
>
> direct = [
> ('created_at', 'created_at', normalize_date),
> ('updated_at', 'updated_at', normalize_date),
> ]
>
> The latter form would allow to use builtin types like str but is maybe
> less readable.
>
Le 9 août 2013 17:35, "Guewen Baconnier @ Camptocamp" < date(record[ 'created_ at']) date(value) : date('created_ at')), date('updated_ at')), date(field) :
<email address hidden>> a écrit :
>
> Thanks for the patch!
> I think that's the responsibility of the mappers and not of the
synchronizer. Although, not all models have those fields.
>
> In the mappers, these fields are actually in direct mappings:
>
> direct = [
> ('created_at', 'created_at'),
> ('updated_at', 'updated_at'),
> ]
>
> The simple but a bit tedious solution is to transform all of them in
> method mappings:
>
> @mapping
> def created_at(self, record):
> return normalize_
>
> Where normalize_date would be a simple helper which clean the invalid
> dates:
>
> def normalize_
> if value == '0000-00-00 00:00:00':
> return None
> return value
>
> The solution I would prefer is to add the possibility (directly in the
`connector` module) to give a transformation method on the direct mappings.
> Either in this form:
>
> direct = [
> ('created_at', normalize_
> ('updated_at', normalize_
> ]
>
> (using a closure like:
> def normalize_
> def transform(self, record):
> if record[field] == '0000-00-00 00:00:00':
> return None
> return record[field]
> return transform
> )
>
With a bit more of thinking that's definitely my preferred form as we can
write a generic converter for types or have special arguments that the
3-items tuple below would not permit. Example
direct = [
(' created_ at', normalize_ date('created_ at')),
(' updated_ at', normalize_ date('updated_ at')),
( 'myfield' , convert( 'origin_ field', float)),
]
> Or in this form:
>
> direct = [
> ('created_at', 'created_at', normalize_date),
> ('updated_at', 'updated_at', normalize_date),
> ]
>
> The latter form would allow to use builtin types like str but is maybe
> less readable.
>