Pingping Lin | 4730a3f | 2018-04-19 16:06:08 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Matteo Scandolo | c48a0fc | 2018-01-31 11:38:11 -0800 | [diff] [blame] | 15 | from xos.exceptions import XOSValidationError |
| 16 | |
| 17 | from models_decl import MCordSubscriberService_decl |
| 18 | from models_decl import MCordSubscriberInstance_decl |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | class MCordSubscriberService(MCordSubscriberService_decl): |
| 24 | class Meta: |
| 25 | proxy = True |
| 26 | |
| 27 | |
| 28 | class MCordSubscriberInstance(MCordSubscriberInstance_decl): |
| 29 | class Meta: |
| 30 | proxy = True |
| 31 | |
| 32 | def save(self, *args, **kwargs): |
Matteo Scandolo | 95f585e | 2018-02-14 15:21:29 -0800 | [diff] [blame] | 33 | # if we don't have a name, use the IMSI number has a name |
| 34 | if not self.name: |
| 35 | self.name = self.imsi_number |
| 36 | |
Matteo Scandolo | ffdd083 | 2018-02-01 15:52:37 -0800 | [diff] [blame] | 37 | # prevent IMSI duplicate |
| 38 | try: |
| 39 | instance_with_same_imsi = MCordSubscriberInstance.objects.get(imsi_number=self.imsi_number) |
| 40 | |
| 41 | if (not self.pk and instance_with_same_imsi) or (self.pk and self.pk != instance_with_same_imsi.pk): |
| 42 | raise XOSValidationError("An MCORDSubscriber with imsi_number '%s' already exists" % self.imsi_number) |
| 43 | except self.DoesNotExist: |
| 44 | pass |
| 45 | |
Matteo Scandolo | 8fdf409 | 2018-02-05 13:15:54 -0800 | [diff] [blame] | 46 | if self.is_new and not self.created_by: |
| 47 | # NOTE if created_by is null it has been created by XOS |
| 48 | self.created_by = "XOS" |
| 49 | |
Matteo Scandolo | 95f585e | 2018-02-14 15:21:29 -0800 | [diff] [blame] | 50 | self.backend_code = 0 |
| 51 | self.backend_status = "In Progress" |
| 52 | |
Matteo Scandolo | c48a0fc | 2018-01-31 11:38:11 -0800 | [diff] [blame] | 53 | super(MCordSubscriberInstance, self).save(*args, **kwargs) |