validate → clean
This commit is contained in:
parent
fce60cf8c3
commit
06797a99b8
2 changed files with 7 additions and 7 deletions
|
@ -171,7 +171,7 @@ class EditorFormBase(I18nModelFormMixin, ModelForm):
|
||||||
raise ValidationError(_('Invalid JSON.'))
|
raise ValidationError(_('Invalid JSON.'))
|
||||||
|
|
||||||
from c3nav.routing.locator import LocatorPoint
|
from c3nav.routing.locator import LocatorPoint
|
||||||
LocatorPoint.validate_scans(data)
|
LocatorPoint.clean_scans(data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Locator:
|
||||||
router = Router.load()
|
router = Router.load()
|
||||||
restrictions = router.get_restrictions(permissions)
|
restrictions = router.get_restrictions(permissions)
|
||||||
|
|
||||||
scan = LocatorPoint.validate_scan(scan, ignore_invalid_stations=True)
|
scan = LocatorPoint.clean_scan(scan, ignore_invalid_stations=True)
|
||||||
scan_values = LocatorPoint.convert_scan(scan, self.stations, create=False)
|
scan_values = LocatorPoint.convert_scan(scan, self.stations, create=False)
|
||||||
station_ids = frozenset(scan_values.keys())
|
station_ids = frozenset(scan_values.keys())
|
||||||
|
|
||||||
|
@ -179,26 +179,26 @@ class LocatorPoint(namedtuple('LocatorPoint', ('x', 'y', 'values'))):
|
||||||
allowed_keys = needed_keys | frozenset(('last', ))
|
allowed_keys = needed_keys | frozenset(('last', ))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_scans(cls, data, ignore_invalid_stations=False):
|
def clean_scans(cls, data, ignore_invalid_stations=False):
|
||||||
if not isinstance(data, list):
|
if not isinstance(data, list):
|
||||||
raise cls.invalid_scan
|
raise cls.invalid_scan
|
||||||
return tuple(cls.validate_scan(scan) for scan in data)
|
return tuple(cls.clean_scan(scan) for scan in data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_scan(cls, data, ignore_invalid_stations=False):
|
def clean_scan(cls, data, ignore_invalid_stations=False):
|
||||||
if not isinstance(data, list):
|
if not isinstance(data, list):
|
||||||
raise cls.invalid_scan
|
raise cls.invalid_scan
|
||||||
cleaned_scan = deque()
|
cleaned_scan = deque()
|
||||||
for scan_value in data:
|
for scan_value in data:
|
||||||
try:
|
try:
|
||||||
cleaned_scan.append(cls.validate_scan_value(scan_value))
|
cleaned_scan.append(cls.clean_scan_value(scan_value))
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
if not ignore_invalid_stations:
|
if not ignore_invalid_stations:
|
||||||
raise
|
raise
|
||||||
return tuple(cleaned_scan)
|
return tuple(cleaned_scan)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_scan_value(cls, data):
|
def clean_scan_value(cls, data):
|
||||||
if not isinstance(data, dict):
|
if not isinstance(data, dict):
|
||||||
raise cls.invalid_scan
|
raise cls.invalid_scan
|
||||||
keys = frozenset(data.keys())
|
keys = frozenset(data.keys())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue