blob: e48251c60ecc965dbf77bb8d425a07d781f70529 [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
17def __unicode__(self): return u'%s' % (self.name)
18
19def save(self, *args, **kwargs):
20
21 if self.latlng:
22 try:
23 latlng_value = getattr(self, 'latlng').strip()
24 if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0):
25 lat = latlng_value[1: latlng_value.index(',')].strip()
26 lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip()
27
28 # If lat and lng are not floats, the code below should result in an error.
29 lat_validation = float(lat)
30 lng_validation = float(lng)
31 else:
32 raise ValueError("The lat/lng value is not formatted correctly.")
33 except:
34 raise ValueError("The lat/lng value is not formatted correctly.")
35
36 super(UserNetworkInterface, self).save(*args, **kwargs)