Add replace_dots option to CleanDecimal
This commit is contained in:
parent
ff04016c8c
commit
0feae01a9c
1 changed files with 6 additions and 1 deletions
|
|
@ -156,8 +156,13 @@ class CleanDecimal(CleanText):
|
||||||
"""
|
"""
|
||||||
Get a cleaned Decimal value from an element.
|
Get a cleaned Decimal value from an element.
|
||||||
"""
|
"""
|
||||||
|
def __init__(self, selector, replace_dots=True):
|
||||||
|
super(CleanDecimal, self).__init__(selector)
|
||||||
|
self.replace_dots = replace_dots
|
||||||
|
|
||||||
def filter(self, text):
|
def filter(self, text):
|
||||||
text = super(CleanDecimal, self).filter(text)
|
text = super(CleanDecimal, self).filter(text)
|
||||||
|
if self.replace_dots:
|
||||||
text = text.replace('.','').replace(',','.')
|
text = text.replace('.','').replace(',','.')
|
||||||
return Decimal(re.sub(ur'[^\d\-\.]', '', text))
|
return Decimal(re.sub(ur'[^\d\-\.]', '', text))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue