blob: e87cfe7e66853745a5993de0657a0e4e44cdbabf [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -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
Murat Parlakisik638c65f2017-05-31 11:10:24 +030017default_attributes = {}
18def __init__(self, *args, **kwargs):
19 ceilometer_services = CeilometerService.get_service_objects().all()
20 if ceilometer_services:
21 self._meta.get_field("provider_service").default = ceilometer_services[0].id
22 super(MonitoringPublisher, self).__init__(*args, **kwargs)
23
24def can_update(self, user):
25 #Allow creation of this model instances for non-admin users also
26 return True
27
28@property
29def creator(self):
30 from core.models import User
31 if getattr(self, "cached_creator", None):
32 return self.cached_creator
33 creator_id=self.get_attribute("creator_id")
34 if not creator_id:
35 return None
36 users=User.objects.filter(id=creator_id)
37 if not users:
38 return None
39 user=users[0]
40 self.cached_creator = users[0]
41 return user
42
43@creator.setter
44def creator(self, value):
45 if value:
46 value = value.id
47 if (value != self.get_attribute("creator_id", None)):
48 self.cached_creator=None
49 self.set_attribute("creator_id", value)