Skip to content

Commit

Permalink
Remove all getter methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengyao Qian committed Sep 20, 2016
1 parent 49e8369 commit d4b2976
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __repr__(self):

@property
def cls_model(self):
return src_registry.get_cls_model(self.datasource_type)
return src_registry.sources[self.datasource_type]

@property
def datasource(self):
Expand Down
15 changes: 7 additions & 8 deletions caravel/source_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ class SourceRegistry(object):

sources = {}

def add_source(self, ds_type, cls):
self.sources[ds_type] = cls

def get_cls_model(self, ds_type):
return self.sources[ds_type]

def all_sources(self):
return self.sources
def add_source(self, ds_type, cls_model):
if ds_type not in self.sources:
self.sources[ds_type] = cls_model
if self.sources[ds_type] is not cls_model:
raise Exception(
'source type: {} is already associated with Model: {}'.format(
ds_type, self.sources[ds_type]))
6 changes: 3 additions & 3 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,9 @@ def add(self):
if not widget:
return redirect(self.get_redirect())

sources = src_registry.all_sources
sources = src_registry.sources
for source in sources:
ds = db.session.query(src_registry.get_cls_model(source)).first()
ds = db.session.query(src_registry.sources[source]).first()
if ds is not None:
url = "/{}/list/".format(ds.baselink)
msg = _("Click on a {} link to create a Slice".format(source))
Expand Down Expand Up @@ -973,7 +973,7 @@ class Caravel(BaseCaravelView):
@log_this
def explore(self, datasource_type, datasource_id, slice_id=None):
error_redirect = '/slicemodelview/list/'
datasource_class = src_registry.get_cls_model(datasource_type)
datasource_class = src_registry.sources[datasource_type]

datasources = (
db.session
Expand Down

0 comments on commit d4b2976

Please sign in to comment.