From ade662da6565d8833ce9043529e1230bfcf2a5ed Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 23 Jun 2021 11:08:02 +0200 Subject: Import: upper/lower case formaters --- ishtar_common/data_importer.py | 24 ++++++++++++++++++++++++ ishtar_common/models_imports.py | 6 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'ishtar_common') diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index b777850c9..ea3054110 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -337,6 +337,30 @@ class InseeFormater(Formater): return code + "-" + exp[1] +class UpperCaseFormater(UnicodeFormater): + """ + To upper case + """ + + def format(self, value): + value = super(UpperCaseFormater, self).format(value) + if not value: + return value + return value.upper() + + +class LowerCaseFormater(UnicodeFormater): + """ + To lower case + """ + + def format(self, value): + value = super(LowerCaseFormater, self).format(value) + if not value: + return value + return value.lower() + + class YearFormater(Formater): def format(self, value): value = value.strip() diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 5d522df27..a90e16373 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -54,7 +54,7 @@ from ishtar_common.utils import create_slug, \ from ishtar_common.data_importer import Importer, ImportFormater, \ IntegerFormater, FloatFormater, UnicodeFormater, DateFormater, \ TypeFormater, YearFormater, StrToBoolean, FileFormater, InseeFormater, \ - ImporterError + ImporterError, UpperCaseFormater, LowerCaseFormater from ishtar_common.utils import task @@ -790,6 +790,8 @@ IMPORTER_TYPES = ( ('TypeFormater', _("Type")), ('YearFormater', _("Year")), ('InseeFormater', _("INSEE code")), + ('UpperFormater', _("Upper case")), + ('LowerFormater', _("Lower case")), ('StrToBoolean', _("String to boolean")), ('FileFormater', pgettext_lazy("filesystem", "File")), ('UnknowType', _("Unknow type")) @@ -805,6 +807,8 @@ IMPORTER_TYPES_DCT = { 'StrToBoolean': StrToBoolean, 'FileFormater': FileFormater, 'InseeFormater': InseeFormater, + 'UpperFormater': UpperCaseFormater, + 'LowerFormater': LowerCaseFormater, 'UnknowType': None, } -- cgit v1.2.3