def data(self): """Data representation of the datasource sent to the frontend""" order_by_choices = [] for s in sorted(self.column_names): order_by_choices.append((json.dumps([s, True]), s + ' [asc]')) order_by_choices.append((json.dumps([s, False]), s + ' [desc]')) verbose_map = {'__timestamp': 'Time'} verbose_map.update({ o.metric_name: o.verbose_name or o.metric_name for o in self.metrics }) verbose_map.update({ o.column_name: o.verbose_name or o.column_name for o in self.columns }) return { # simple fields 'id': self.id, 'column_formats': self.column_formats, 'description': self.description, 'database': self.database.data, # pylint: disable=no-member 'default_endpoint': self.default_endpoint, 'filter_select': self.filter_select_enabled, # TODO deprecate 'filter_select_enabled': self.filter_select_enabled, 'name': self.name, 'datasource_name': self.datasource_name, 'type': self.type, 'schema': self.schema, 'offset': self.offset, 'cache_timeout': self.cache_timeout, 'params': self.params, 'perm': self.perm, # sqla-specific 'sql': self.sql, # additional fields 'unformatted_columns': utils.choicify(self.column_names), # computed fields 'all_cols': utils.choicify(self.column_names), 'columns': [o.data for o in self.columns], 'edit_url': self.url, 'filterable_cols': utils.choicify(self.filterable_column_names), 'gb_cols': utils.choicify(self.groupby_column_names), 'metrics': [o.data for o in self.metrics], 'metrics_combo': self.metrics_combo, 'order_by_choices': order_by_choices, 'owner': self.owner.id if self.owner else None, 'verbose_map': verbose_map, 'select_star': self.select_star, }
def data(self): """Data representation of the datasource sent to the frontend""" order_by_choices = [] for s in sorted(self.column_names): order_by_choices.append((json.dumps([s, True]), s + ' [asc]')) order_by_choices.append((json.dumps([s, False]), s + ' [desc]')) verbose_map = {'__timestamp': 'Time'} verbose_map.update({ o.metric_name: o.verbose_name or o.metric_name for o in self.metrics }) verbose_map.update({ o.column_name: o.verbose_name or o.column_name for o in self.columns }) return { # simple fields 'id': self.id, 'column_formats': self.column_formats, 'description': self.description, 'database': self.database.data, # pylint: disable=no-member 'default_endpoint': self.default_endpoint, 'filter_select': self.filter_select_enabled, # TODO deprecate 'filter_select_enabled': self.filter_select_enabled, 'name': self.name, 'datasource_name': self.datasource_name, 'type': self.type, 'schema': self.schema, 'offset': self.offset, 'cache_timeout': self.cache_timeout, 'params': self.params, 'perm': self.perm, # sqla-specific 'sql': self.sql, # computed fields 'all_cols': utils.choicify(self.column_names), 'columns': [o.data for o in self.columns], 'edit_url': self.url, 'filterable_cols': utils.choicify(self.filterable_column_names), 'gb_cols': utils.choicify(self.groupby_column_names), 'metrics': [o.data for o in self.metrics], 'metrics_combo': self.metrics_combo, 'order_by_choices': order_by_choices, 'owner': self.owner.id if self.owner else None, 'verbose_map': verbose_map, 'select_star': self.select_star, }
def data(self): d = super(SqlaTable, self).data if self.type == 'table': grains = self.database.grains() or [] if grains: grains = [(g.duration, g.name) for g in grains] d['granularity_sqla'] = utils.choicify(self.dttm_cols) d['time_grain_sqla'] = grains d['main_dttm_col'] = self.main_dttm_col return d
def data(self): d = super(SqlaTable, self).data if self.type == 'table': grains = self.database.grains() or [] if grains: grains = [(g.duration, g.name) for g in grains] d['granularity_sqla'] = utils.choicify(self.dttm_cols) d['time_grain_sqla'] = grains d['main_dttm_col'] = self.main_dttm_col d['fetch_values_predicate'] = self.fetch_values_predicate return d
def data(self): d = super(SqlaTable, self).data if self.type == "table": grains = self.database.grains() or [] if grains: grains = [(g.duration, g.name) for g in grains] d["granularity_sqla"] = utils.choicify(self.dttm_cols) d["time_grain_sqla"] = grains d["main_dttm_col"] = self.main_dttm_col d["fetch_values_predicate"] = self.fetch_values_predicate d["template_params"] = self.template_params return d