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