blob: 121611ed33fdd5ac5a9e809f13b4ef75aedc0fb9 [file] [log] [blame]
Andrea Campanella95c02bd2017-09-01 16:51:03 +02001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Scott Bakerf7acc7d2017-10-18 10:55:47 -070017def __xos_save_base(self, *args, **kwargs):
Andrea Campanella95c02bd2017-09-01 16:51:03 +020018
19 if self.latlng:
20 try:
21 latlng_value = getattr(self, 'latlng').strip()
22 if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0):
23 lat = latlng_value[1: latlng_value.index(',')].strip()
24 lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip()
25
26 # If lat and lng are not floats, the code below should result in an error.
27 lat_validation = float(lat)
28 lng_validation = float(lng)
29 else:
30 raise ValueError("The lat/lng value is not formatted correctly.")
31 except:
32 raise ValueError("The lat/lng value is not formatted correctly.")
33
Scott Bakerf7acc7d2017-10-18 10:55:47 -070034 return False # let xosbase know to save the model
35