def parse(cls, config): if 'name' not in config: raise ConfigError('Dashboard name not specified.') name = config['name'] config.setdefault('title', name) name = utils.slugify(name) config['name'] = name # request interval is converted to milliseconds for client side config['poll_interval'] = utils.parse_interval(config['poll_interval']) if 'widgets' not in config: raise ConfigError("Dashboard '%s' has no widgets" % name) widgets = DashboardWidgetConfigs(config.pop('backend', {})) for widget in config['widgets']: if widget == 'new_row': widgets.new_row() else: widgets.add_widget(widget) config['widgets'] = widgets.to_list() config['rows'] = widgets.by_row() return config
def api_remove_dashboard(self, request, name): name = utils.slugify(name.encode('utf-8')) if not self.has_dashboard(name): return self.render_error_response( request, code=http.NOT_FOUND, message="Dashboard '%s' does not exist" % name) self.remove_dashboard(name) return self.api_success_response(request)
def parse_metric(cls, config): """ Parses a metric config given in a graph config into a config useable by the backend. """ if "name" not in config: raise ConfigError("Every chart metric needs a name.") name = config.pop("name") config["title"] = config.setdefault("title", name) config["name"] = utils.slugify(name) return config
def parse(cls, config): config['type_name'] = cls.TYPE_NAME if 'name' not in config: raise ConfigError('All widgets need a name.') name = config['name'] config.setdefault('title', name) name = utils.slugify(name) config['name'] = name config['width'] = cls.parse_width(config['width']) return config
def api_add_dashboard(self, request, replace): try: config = json.loads(request.content.read()) except: return self.api_error_response( request, code=http.BAD_REQUEST, message="Error parsing dashboard config as json object") if not isinstance(config, dict): return self.api_error_response( request, code=http.BAD_REQUEST, message="Dashboard configs need to be json objects") if 'name' not in config: return self.api_error_response( request, code=http.BAD_REQUEST, message="Dashboards need a name to be created") if not replace and self.has_dashboard(utils.slugify(config['name'])): return self.api_error_response( request, code=http.BAD_REQUEST, message="Dashboard with name '%s' already exists") config = self.config.apply_dashboard_defaults(config) try: config = DashboardConfig(config) except ConfigError, e: return self.api_error_response( request, code=http.BAD_REQUEST, message="Error parsing dashboard config: %r" % e)
def test_slugify(self): """Should change 'SomethIng_lIke tHis' to 'something-like-this'""" self.assertEqual(utils.slugify(u'SoMeThing_liKe!tHis'), 'something-like-this') self.assertEqual(utils.slugify(u'Godspeed You! Black Emperor'), 'godspeed-you-black-emperor')