def delete(self, *args, **kwargs): if self.dependents.all().count(): raise IntegrityError("This series has dependent virtual series.") if not self.is_virtual: database_client = get_client() database_client.delete(self.slug) super(TimeSeries, self).delete(*args, **kwargs)
def save(self, *args, **kwargs): if self._config_new is not None: self._config = pickle.dumps(self._config_new) if self.is_virtual: equation = combine.evaluate_equation(self.equation) #else: # tz = pytz.timezone(settings.TIME_ZONE) # start = self.config['start'] # if self.config.start.tzinfo: # self.start = self.start.astimezone(tz) # else: # self.start = tz.localize(self.start) create_timeseries = not self.is_virtual and not self.pk super(TimeSeries, self).save(*args, **kwargs) if create_timeseries: database_client = get_client() database_client.create(self.slug, **self.config) if self.is_virtual: self.depends_on = TimeSeries.objects.filter(slug__in=equation.get_slugs()) else: for vts in self.dependents.all(): vts.save(*args, **kwargs)
def testCreateReal(self): response = self.client.post( "/admin/", data=json.dumps(self.real_timeseries), content_type="application/json", REMOTE_USER="******" ) self.assertEqual(response.status_code, 201) self.assertTrue("Location" in response) # Check that the config matches that we supplied client = get_client() config = client.get_config(self.real_timeseries["slug"]) original_config = dict(self.real_timeseries["config"]) # We provided an ISO8601 timestamp, which will have been converted to a datetime original_config["start"] = dateutil.parser.parse(original_config["start"]) self.assertEqual(config, original_config) # Check that we have permissions to do everything to this timeseries time_series = TimeSeries.objects.get(slug=self.real_timeseries["slug"]) user = User.objects.get(username="******") self.assertEqual( set(user.get_perms(time_series)), set("openorg_timeseries.%s_timeseries" % p for p in "view change append delete".split()), )
def fetch(self, aggregation_type, interval, period_start=None, period_end=None): database_client = get_client() return database_client.fetch(self.slug, aggregation_type, interval, period_start, period_end)
def append(self, readings): database_client = get_client() result = database_client.append(self.slug, readings) self.last = result['last'] self.save() return result