fix: allow comma in numeric filter input
just remove them and run with the remainder, on the SQL side
This commit is contained in:
parent
eff5341335
commit
1dc632174e
|
@ -26,6 +26,7 @@ Grid Filters
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
import decimal
|
||||||
import logging
|
import logging
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
@ -647,12 +648,22 @@ class AlchemyNumericFilter(AlchemyGridFilter):
|
||||||
|
|
||||||
# first just make sure it's somewhat numeric
|
# first just make sure it's somewhat numeric
|
||||||
try:
|
try:
|
||||||
float(value)
|
self.parse_decimal(value)
|
||||||
except ValueError:
|
except decimal.InvalidOperation:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return bool(value and len(str(value)) > 8)
|
return bool(value and len(str(value)) > 8)
|
||||||
|
|
||||||
|
def parse_decimal(self, value):
|
||||||
|
if value:
|
||||||
|
value = value.replace(',', '')
|
||||||
|
return decimal.Decimal(value)
|
||||||
|
|
||||||
|
def encode_value(self, value):
|
||||||
|
if value:
|
||||||
|
value = str(self.parse_decimal(value))
|
||||||
|
return super().encode_value(value)
|
||||||
|
|
||||||
def filter_equal(self, query, value):
|
def filter_equal(self, query, value):
|
||||||
if self.value_invalid(value):
|
if self.value_invalid(value):
|
||||||
return query
|
return query
|
||||||
|
|
Loading…
Reference in a new issue