[gen] More compact code.
This commit is contained in:
parent
f629f2b323
commit
90af2e5698
|
@ -586,21 +586,14 @@ class String(Field):
|
|||
break
|
||||
if error: return obj.translate('bad_select_value')
|
||||
|
||||
accents = {'é':'e','è':'e','ê':'e','ë':'e','à':'a','â':'a','ä':'a',
|
||||
'ù':'u','û':'u','ü':'u','î':'i','ï':'i','ô':'o','ö':'o',
|
||||
'ç':'c', 'Ç':'C',
|
||||
'Ù':'U','Û':'U','Ü':'U','Î':'I','Ï':'I','Ô':'O','Ö':'O',
|
||||
'É':'E','È':'E','Ê':'E','Ë':'E','À':'A','Â':'A','Ä':'A'}
|
||||
def applyTransform(self, value):
|
||||
'''Applies a transform as required by self.transform on single
|
||||
value p_value.'''
|
||||
if self.transform in ('uppercase', 'lowercase'):
|
||||
# For those transforms, I will remove any accent, because
|
||||
# (1) 'é'.upper() or 'Ê'.lower() has no effect;
|
||||
# (2) most of the time, if the user wants to apply such effect, it
|
||||
# is for ease of data manipulation, so I guess without accent.
|
||||
for c, n in self.accents.iteritems():
|
||||
if c in value: value = value.replace(c, n)
|
||||
# For those transforms, I will remove any accent, because, most of
|
||||
# the time, if the user wants to apply such effect, it is for ease
|
||||
# of data manipulation, so I guess without accent.
|
||||
value = sutils.normalizeString(value, usage='noAccents')
|
||||
# Apply the transform
|
||||
if self.transform == 'lowercase': return value.lower()
|
||||
elif self.transform == 'uppercase': return value.upper()
|
||||
|
|
|
@ -216,6 +216,7 @@ def normalizeString(s, usage='fileName'):
|
|||
* alphanum: it removes any non-alphanumeric char;
|
||||
* alpha: it removes any non-letter char.
|
||||
'''
|
||||
strNeeded = isinstance(s, str)
|
||||
# We work in unicode. Convert p_s to unicode if not unicode.
|
||||
if isinstance(s, str): s = s.decode('utf-8')
|
||||
elif not isinstance(s, unicode): s = unicode(s)
|
||||
|
@ -236,8 +237,12 @@ def normalizeString(s, usage='fileName'):
|
|||
res = ''
|
||||
for char in s:
|
||||
if rex.match(char): res += char
|
||||
elif usage == 'noAccents':
|
||||
res = s
|
||||
else:
|
||||
res = s
|
||||
# Re-code the result as a str if a str was given.
|
||||
if strNeeded: res = res.encode('utf-8')
|
||||
return res
|
||||
|
||||
def normalizeText(s):
|
||||
|
|
Loading…
Reference in a new issue