Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add _() to Exception messages #3034

Merged
merged 7 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,9 @@ def fetch_metadata(self):
try:
table = self.get_sqla_table_object()
except Exception:
raise Exception(
raise Exception(_(
"Table doesn't seem to exist in the specified database, "
"couldn't fetch column information")
"couldn't fetch column information"))

TC = TableColumn # noqa shortcut to class
M = SqlMetric # noqa
Expand Down
4 changes: 2 additions & 2 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ def pre_add(self, table):
table.get_sqla_table_object()
except Exception as e:
logging.exception(e)
raise Exception(
raise Exception(_(
"Table [{}] could not be found, "
"please double check your "
"database connection, schema, and "
"table name".format(table.name))
"table name").format(table.name))

def post_add(self, table, flash_message=True):
table.fetch_metadata()
Expand Down
3 changes: 2 additions & 1 deletion superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from flask import g, redirect, Response, flash, abort
from flask_babel import gettext as __
from flask_babel import lazy_gettext as _

from flask_appbuilder import BaseView
from flask_appbuilder import ModelView
Expand Down Expand Up @@ -202,7 +203,7 @@ def validate_json(form, field): # noqa
json.loads(field.data)
except Exception as e:
logging.exception(e)
raise Exception("json isn't valid")
raise Exception(_("json isn't valid"))


class DeleteMixin(object):
Expand Down
2 changes: 1 addition & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ def sql_json(self):
query_id = query.id
session.commit() # shouldn't be necessary
if not query_id:
raise Exception("Query record was not created as expected.")
raise Exception(_("Query record was not created as expected."))
logging.info("Triggering query_id: {}".format(query_id))

# Async request.
Expand Down
73 changes: 37 additions & 36 deletions superset/viz.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BaseViz(object):

def __init__(self, datasource, form_data):
if not datasource:
raise Exception("Viz is missing a datasource")
raise Exception(_("Viz is missing a datasource"))
self.datasource = datasource
self.request = request
self.viz_type = form_data.get("viz_type")
Expand Down Expand Up @@ -155,7 +155,7 @@ def query_obj(self):
until = extra_filters.get('__to') or form_data.get("until", "now")
to_dttm = utils.parse_human_datetime(until)
if from_dttm > to_dttm:
raise Exception("From date cannot be larger than to date")
raise Exception(_("From date cannot be larger than to date"))

# extras are used to query elements specific to a datasource type
# for instance the extra where clause that applies only to Tables
Expand Down Expand Up @@ -331,19 +331,19 @@ def should_be_timeseries(self):
(fd.get('granularity_sqla') and fd.get('time_grain_sqla'))
)
if fd.get('include_time') and not conditions_met:
raise Exception(
raise Exception(_(
"Pick a granularity in the Time section or "
"uncheck 'Include Time'")
"uncheck 'Include Time'"))
return fd.get('include_time')

def query_obj(self):
d = super(TableViz, self).query_obj()
fd = self.form_data

if fd.get('all_columns') and (fd.get('groupby') or fd.get('metrics')):
raise Exception(
raise Exception(_(
"Choose either fields to [Group By] and [Metrics] or "
"[Columns], not both")
"[Columns], not both"))

if fd.get('all_columns'):
d['columns'] = fd.get('all_columns')
Expand Down Expand Up @@ -389,13 +389,13 @@ def query_obj(self):
if not groupby:
groupby = []
if not groupby:
raise Exception("Please choose at least one \"Group by\" field ")
raise Exception(_("Please choose at least one \"Group by\" field "))
if not metrics:
raise Exception("Please choose at least one metric")
raise Exception(_("Please choose at least one metric"))
if (
any(v in groupby for v in columns) or
any(v in columns for v in groupby)):
raise Exception(""""Group By" and "Columns" can't overlap""")
raise Exception(_("'Group By' and 'Columns' can't overlap"))
return d

def get_data(self, df):
Expand Down Expand Up @@ -683,7 +683,7 @@ def query_obj(self):
self.y_metric,
]
if not all(d['metrics'] + [self.entity]):
raise Exception("Pick a metric for x, y and size")
raise Exception(_("Pick a metric for x, y and size"))
return d

def get_data(self, df):
Expand Down Expand Up @@ -735,7 +735,7 @@ def as_floats(field):
self.metric,
]
if not self.metric:
raise Exception("Pick a metric to display")
raise Exception(_("Pick a metric to display"))
return d

def get_data(self, df):
Expand Down Expand Up @@ -766,7 +766,7 @@ def query_obj(self):
d = super(BigNumberViz, self).query_obj()
metric = self.form_data.get('metric')
if not metric:
raise Exception("Pick a metric!")
raise Exception(_("Pick a metric!"))
d['metrics'] = [self.form_data.get('metric')]
self.form_data['metric'] = metric
return d
Expand Down Expand Up @@ -795,7 +795,7 @@ def query_obj(self):
d = super(BigNumberTotalViz, self).query_obj()
metric = self.form_data.get('metric')
if not metric:
raise Exception("Pick a metric!")
raise Exception(_("Pick a metric!"))
d['metrics'] = [self.form_data.get('metric')]
self.form_data['metric'] = metric
return d
Expand Down Expand Up @@ -861,7 +861,7 @@ def get_data(self, df):
fd = self.form_data
df = df.fillna(0)
if fd.get("granularity") == "all":
raise Exception("Pick a time granularity for your time series")
raise Exception(_("Pick a time granularity for your time series"))

df = df.pivot_table(
index=DTTM_ALIAS,
Expand Down Expand Up @@ -951,12 +951,12 @@ def query_obj(self):
m2 = self.form_data.get('metric_2')
d['metrics'] = [m1, m2]
if not m1:
raise Exception("Pick a metric for left axis!")
raise Exception(_("Pick a metric for left axis!"))
if not m2:
raise Exception("Pick a metric for right axis!")
raise Exception(_("Pick a metric for right axis!"))
if m1 == m2:
raise Exception("Please choose different metrics"
" on left and right axis")
raise Exception(_("Please choose different metrics"
" on left and right axis"))
return d

def to_series(self, df, classed=''):
Expand Down Expand Up @@ -998,7 +998,7 @@ def get_data(self, df):
df = df.fillna(0)

if self.form_data.get("granularity") == "all":
raise Exception("Pick a time granularity for your time series")
raise Exception(_("Pick a time granularity for your time series"))

metric = fd.get('metric')
metric_2 = fd.get('metric_2')
Expand Down Expand Up @@ -1069,7 +1069,7 @@ def query_obj(self):
'row_limit', int(config.get('VIZ_ROW_LIMIT')))
numeric_column = self.form_data.get('all_columns_x')
if numeric_column is None:
raise Exception("Must have one numeric column specified")
raise Exception(_("Must have one numeric column specified"))
d['columns'] = [numeric_column]
return d

Expand All @@ -1094,11 +1094,12 @@ def query_obj(self):
len(d['groupby']) <
len(fd.get('groupby') or []) + len(fd.get('columns') or [])
):
raise Exception("Can't have overlap between Series and Breakdowns")
raise Exception(
_("Can't have overlap between Series and Breakdowns"))
if not fd.get('metrics'):
raise Exception("Pick at least one metric")
raise Exception(_("Pick at least one metric"))
if not fd.get('groupby'):
raise Exception("Pick at least one field for [Series]")
raise Exception(_("Pick at least one field for [Series]"))
return d

def get_data(self, df):
Expand Down Expand Up @@ -1191,7 +1192,7 @@ class SankeyViz(BaseViz):
def query_obj(self):
qry = super(SankeyViz, self).query_obj()
if len(qry['groupby']) != 2:
raise Exception("Pick exactly 2 columns as [Source / Target]")
raise Exception(_("Pick exactly 2 columns as [Source / Target]"))
qry['metrics'] = [
self.form_data['metric']]
return qry
Expand Down Expand Up @@ -1222,9 +1223,9 @@ def visit(vertex):

cycle = find_cycle(hierarchy)
if cycle:
raise Exception(
raise Exception(_(
"There's a loop in your Sankey, please provide a tree. "
"Here's a faulty link: {}".format(cycle))
"Here's a faulty link: {}").format(cycle))
return recs


Expand All @@ -1240,7 +1241,7 @@ class DirectedForceViz(BaseViz):
def query_obj(self):
qry = super(DirectedForceViz, self).query_obj()
if len(self.form_data['groupby']) != 2:
raise Exception("Pick exactly 2 columns to 'Group By'")
raise Exception(_("Pick exactly 2 columns to 'Group By'"))
qry['metrics'] = [self.form_data['metric']]
return qry

Expand Down Expand Up @@ -1374,7 +1375,7 @@ def query_obj(self):
qry = super(FilterBoxViz, self).query_obj()
groupby = self.form_data.get('groupby')
if len(groupby) < 1 and not self.form_data.get('date_filter'):
raise Exception("Pick at least one filter field")
raise Exception(_("Pick at least one filter field"))
qry['metrics'] = [
self.form_data['metric']]
return qry
Expand Down Expand Up @@ -1520,8 +1521,8 @@ def query_obj(self):

if label_col and len(label_col) >= 1:
if label_col[0] == "count":
raise Exception(
"Must have a [Group By] column to have 'count' as the [Label]")
raise Exception(_(
"Must have a [Group By] column to have 'count' as the [Label]"))
d['columns'].append(label_col[0])

if fd.get('point_radius') != 'Auto':
Expand All @@ -1533,18 +1534,18 @@ def query_obj(self):
if (label_col and len(label_col) >= 1 and
label_col[0] != "count" and
label_col[0] not in fd.get('groupby')):
raise Exception(
"Choice of [Label] must be present in [Group By]")
raise Exception(_(
"Choice of [Label] must be present in [Group By]"))

if (fd.get("point_radius") != "Auto" and
fd.get("point_radius") not in fd.get('groupby')):
raise Exception(
"Choice of [Point Radius] must be present in [Group By]")
raise Exception(_(
"Choice of [Point Radius] must be present in [Group By]"))

if (fd.get('all_columns_x') not in fd.get('groupby') or
fd.get('all_columns_y') not in fd.get('groupby')):
raise Exception(
"[Longitude] and [Latitude] columns must be present in [Group By]")
raise Exception(_(
"[Longitude] and [Latitude] columns must be present in [Group By]"))
return d

def get_data(self, df):
Expand Down