Scott Baker | ef14f72 | 2018-02-28 09:17:01 -0800 | [diff] [blame^] | 1 | |
| 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 | from xos.exceptions import * |
| 17 | from models_decl import * |
| 18 | |
| 19 | class EnterpriseLocation(EnterpriseLocation_decl): |
| 20 | class Meta: |
| 21 | proxy = True |
| 22 | |
| 23 | class OnosModel(OnosModel_decl): |
| 24 | class Meta: |
| 25 | proxy = True |
| 26 | |
| 27 | class UserNetworkInterface(UserNetworkInterface_decl): |
| 28 | class Meta: |
| 29 | proxy = True |
| 30 | |
| 31 | def save(self, *args, **kwargs): |
| 32 | if self.latlng: |
| 33 | try: |
| 34 | latlng_value = getattr(self, 'latlng').strip() |
| 35 | if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0): |
| 36 | lat = latlng_value[1: latlng_value.index(',')].strip() |
| 37 | lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip() |
| 38 | |
| 39 | # If lat and lng are not floats, the code below should result in an error. |
| 40 | lat_validation = float(lat) |
| 41 | lng_validation = float(lng) |
| 42 | else: |
| 43 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 44 | except: |
| 45 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 46 | |
| 47 | super(UserNetworkInterface, self).save(*args, **kwargs) |
| 48 | |
| 49 | class BandwidthProfile(BandwidthProfile_decl): |
| 50 | class Meta: |
| 51 | proxy = True |
| 52 | |
| 53 | class ELine(ELine_decl): |
| 54 | class Meta: |
| 55 | proxy = True |