diff --git a/montage/rdb.py b/montage/rdb.py index 845d4cc0..3debe5bd 100644 --- a/montage/rdb.py +++ b/montage/rdb.py @@ -1526,11 +1526,7 @@ def activate_round(self, round_id): def add_entries_from_cat(self, round_id, cat_name): rnd = self.user_dao.get_round(round_id) - if ENV_NAME == 'dev': - source = 'remote' - else: - source = 'local' - entries = loaders.load_category(cat_name, source=source) + entries = loaders.load_category(cat_name, source=get_source()) entries, new_entry_count = self.add_entries(rnd, entries) msg = ('%s loaded %s entries from category (%s), %s new entries added' @@ -1541,11 +1537,7 @@ def add_entries_from_cat(self, round_id, cat_name): def add_entries_by_name(self, round_id, file_names): rnd = self.user_dao.get_round(round_id) - if ENV_NAME == 'dev': - source = 'remote' - else: - source = 'local' - entries = loaders.load_by_filename(file_names, source=source) + entries = loaders.load_by_filename(file_names, source=get_source()) entries, new_entry_count = self.add_entries(rnd, entries) msg = ('%s loaded %s entries from filenames, %s new entries added' @@ -1558,13 +1550,9 @@ def add_entries_from_csv(self, round_id, csv_url): # NOTE: this no longer creates RoundEntries, use # add_round_entries to do this. rnd = self.user_dao.get_round(round_id) - if ENV_NAME == 'dev': - source = 'remote' - else: - source = 'local' try: entries, warnings = loaders.get_entries_from_csv(csv_url, - source=source) + source=get_source()) except ValueError as e: raise InvalidAction('unable to load csv "%s"' % csv_url) @@ -3097,6 +3085,23 @@ def choose_eligible(eligible_users): 'task_count_mean': mean(vote_count_map.values())} +def get_source(): + from utils import load_env_config + + config = load_env_config() + + config_source = config.get('source') + if config_source: + return config_source + + if ENV_NAME == 'dev': + source = 'remote' + else: + source = 'local' + + return source + + def make_rdb_session(echo=True): from utils import load_env_config from sqlalchemy import create_engine