blob: 9769591259084b7bd922107184225613f19063cd [file] [log] [blame]
Murat Parlakisik638c65f2017-05-31 11:10:24 +03001default_attributes = {}
2def __init__(self, *args, **kwargs):
3 ceilometer_services = CeilometerService.get_service_objects().all()
4 if ceilometer_services:
5 self._meta.get_field("provider_service").default = ceilometer_services[0].id
6 super(MonitoringPublisher, self).__init__(*args, **kwargs)
7
8def can_update(self, user):
9 #Allow creation of this model instances for non-admin users also
10 return True
11
12@property
13def creator(self):
14 from core.models import User
15 if getattr(self, "cached_creator", None):
16 return self.cached_creator
17 creator_id=self.get_attribute("creator_id")
18 if not creator_id:
19 return None
20 users=User.objects.filter(id=creator_id)
21 if not users:
22 return None
23 user=users[0]
24 self.cached_creator = users[0]
25 return user
26
27@creator.setter
28def creator(self, value):
29 if value:
30 value = value.id
31 if (value != self.get_attribute("creator_id", None)):
32 self.cached_creator=None
33 self.set_attribute("creator_id", value)