From 07e0582dd3e7395dc306c60365057ab0d219ee01 Mon Sep 17 00:00:00 2001 From: hparfr Date: Thu, 27 Sep 2018 17:22:11 +0200 Subject: [PATCH 1/4] Add coerce on dpd --- roulier/api.py | 37 +++++++++++++++++++ roulier/carriers/dpd/dpd_api.py | 5 ++- roulier/carriers/geodis/geodis_api_edi.py | 6 ++- .../carriers/geodis/geodis_transport_edi.py | 28 -------------- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/roulier/api.py b/roulier/api.py index 42b3e42..c6b5959 100644 --- a/roulier/api.py +++ b/roulier/api.py @@ -34,6 +34,43 @@ def _normalize_coerce_zpl(self, value): for ctrl in ctrl_cars: val = val.replace("%c" % ctrl, "") return val + + def _normalize_coerce_accents(self, value): + """Sanitize accents for some WS.""" + if not isinstance(value, basestring): + return value + import pdb; pdb.set_trace() + sanitized = ( + value + # quick and dirty replacement + # of common accentued chars in french + # because some ws don't handle well utf8 + .replace(u"é", "e") + .replace(u"è", "e") + .replace(u"ë", "e") + .replace(u"ê", "e") + .replace(u"ô", "o") + .replace(u"ï", "i") + .replace(u"ö", "o") + .replace(u"à", "a") + .replace(u"â", "a") + .replace(u"ç", "c") + .replace(u"û", "u") + .replace(u"ù", "u") + .replace(u"É", "E") + .replace(u"È", "E") + .replace(u"Ë", "E") + .replace(u"Ê", "E") + .replace(u"Ô", "O") + .replace(u"Ï", "I") + .replace(u"Ö", "O") + .replace(u"À", "A") + .replace(u"Â", "A") + .replace(u"Ç", "C") + .replace(u"Û", "U") + .replace(u"Ù", "U") + ).encode('ascii', 'ignore') # cut remaining chars + return sanitized class Api(object): diff --git a/roulier/carriers/dpd/dpd_api.py b/roulier/carriers/dpd/dpd_api.py index 44b41fd..8f2c8eb 100644 --- a/roulier/carriers/dpd/dpd_api.py +++ b/roulier/carriers/dpd/dpd_api.py @@ -71,10 +71,13 @@ def _address(self): def _to_address(self): schema = super(DpdApi, self)._to_address() - schema['firstName'] = {'default': '', 'description': """First name"""} + schema['firstName'] = {'default': '', 'description': """First name""", + 'coerce': 'accents'} schema['door1'] = {'default': '', 'description': """Door code 1"""} schema['door2'] = {'default': '', 'description': """Door code 2"""} schema['intercom'] = {'default': '', 'description': """Intercom"""} + for field in ['city', 'company', 'name', 'street1', 'street2']: + schema[field].update({ 'coerce': 'accents'}) return schema def _from_address(self): diff --git a/roulier/carriers/geodis/geodis_api_edi.py b/roulier/carriers/geodis/geodis_api_edi.py index 56af3f3..a15c713 100644 --- a/roulier/carriers/geodis/geodis_api_edi.py +++ b/roulier/carriers/geodis/geodis_api_edi.py @@ -102,9 +102,13 @@ def _shipments(self): } def _schemas(self): - return { + schemas = { 'service': self._service(), 'shipments': self._shipments(), 'agency_address': self._from_address(), 'from_address': self._from_address(), } + for schema in schemas: + for field in schemas[schema]: + schemas[schema][field].update({'coerce': 'accents'}) + return schemas diff --git a/roulier/carriers/geodis/geodis_transport_edi.py b/roulier/carriers/geodis/geodis_transport_edi.py index 2db8074..d67a13f 100644 --- a/roulier/carriers/geodis/geodis_transport_edi.py +++ b/roulier/carriers/geodis/geodis_transport_edi.py @@ -63,34 +63,6 @@ def sanitize(token): .replace("'", " ") .replace("+", " ") .replace(":", " ") - # quick and dirty replacement - # of common accentued chars in french - # because geodis don't handle well utf8 - # TODO: put it in api coerce - .replace(u"é", "e") - .replace(u"è", "e") - .replace(u"ë", "e") - .replace(u"ê", "e") - .replace(u"ô", "o") - .replace(u"ï", "i") - .replace(u"ö", "o") - .replace(u"à", "a") - .replace(u"â", "a") - .replace(u"ç", "c") - .replace(u"û", "u") - .replace(u"ù", "u") - .replace(u"É", "E") - .replace(u"È", "E") - .replace(u"Ë", "E") - .replace(u"Ê", "E") - .replace(u"Ô", "O") - .replace(u"Ï", "I") - .replace(u"Ö", "O") - .replace(u"À", "A") - .replace(u"Â", "A") - .replace(u"Ç", "C") - .replace(u"Û", "U") - .replace(u"Ù", "U") ).encode('ascii', 'ignore') # cut remaining chars return sanitized From fa6349d3444683995edf6d1d6ffc90dfd83b3d73 Mon Sep 17 00:00:00 2001 From: hparfr Date: Mon, 26 Nov 2018 11:28:31 +0100 Subject: [PATCH 2/4] Remove trace --- roulier/api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/roulier/api.py b/roulier/api.py index c6b5959..6ed83c1 100644 --- a/roulier/api.py +++ b/roulier/api.py @@ -34,12 +34,11 @@ def _normalize_coerce_zpl(self, value): for ctrl in ctrl_cars: val = val.replace("%c" % ctrl, "") return val - + def _normalize_coerce_accents(self, value): """Sanitize accents for some WS.""" if not isinstance(value, basestring): return value - import pdb; pdb.set_trace() sanitized = ( value # quick and dirty replacement From acca89e1ee579eb93117fa1d3976b118b3153a4d Mon Sep 17 00:00:00 2001 From: Hpar Date: Mon, 26 Nov 2018 12:05:12 +0100 Subject: [PATCH 3/4] Update changelog update version --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7892ddc..44c8125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Roadmap / TODO: - Support additionnal methods of api - Write tests +# 0.3.4 2018-11-26 + - DPD convert characters to ASCII (because issues on labels) + # 0.3.3 2018-02-19 - Geodis force ASCII conversion for EDI. From 38f677a242361db4e8e739953d92f2f427fc65fa Mon Sep 17 00:00:00 2001 From: Hpar Date: Mon, 26 Nov 2018 12:05:28 +0100 Subject: [PATCH 4/4] update version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1c09c74..42045ac 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.3 +0.3.4