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,9 +156,14 @@ class CleanDecimal(CleanText):
|
|||
"""
|
||||
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):
|
||||
text = super(CleanDecimal, self).filter(text)
|
||||
text = text.replace('.','').replace(',','.')
|
||||
if self.replace_dots:
|
||||
text = text.replace('.','').replace(',','.')
|
||||
return Decimal(re.sub(ur'[^\d\-\.]', '', text))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue