diff --git a/client/src/components/campaign/round-new/round-new.component.js b/client/src/components/campaign/round-new/round-new.component.js index f72784b1..68315216 100644 --- a/client/src/components/campaign/round-new/round-new.component.js +++ b/client/src/components/campaign/round-new/round-new.component.js @@ -138,7 +138,7 @@ function controller($filter, $mdDialog, $state, adminService, alertService, data .filter((value, index, array) => array.indexOf(value) === index) .join('\n'); - const text = `${warningsList.join(', ')}\n\n${filesList}`; + const text = `${warningsList.join('\n\n')}\n\n${filesList}`; const dialog = $mdDialog .confirm() diff --git a/montage/admin_endpoints.py b/montage/admin_endpoints.py index b2f1f1fc..b9b51a73 100644 --- a/montage/admin_endpoints.py +++ b/montage/admin_endpoints.py @@ -356,7 +356,13 @@ def import_entries(user_dao, round_id, request_dict): 'round_id': prev_round_id} elif import_method == SELECTED_METHOD: file_names = request_dict['file_names'] - entries = coord_dao.add_entries_by_name(round_id, file_names) + entries, warnings = coord_dao.add_entries_by_name(round_id, file_names) + if warnings: + formatted_warnings = '\n'.join([ + '- {}'.format(warning) for warning in warnings + ]) + msg = 'unable to load {} files:\n{}'.format(len(warnings), formatted_warnings) + import_warnings.append({'import issues', msg}) params = {'file_names': file_names} else: raise NotImplementedResponse() diff --git a/montage/labs.py b/montage/labs.py index 30e79a4d..f53d2eba 100644 --- a/montage/labs.py +++ b/montage/labs.py @@ -90,8 +90,9 @@ def get_file_info(filename): params = (filename.replace(' ', '_'),) results = fetchall_from_commonswiki(query, params) if results: - results = results[0] - return results + return results[0] + else: + return None if __name__ == '__main__': diff --git a/montage/loaders.py b/montage/loaders.py index e968ea34..57ba5001 100644 --- a/montage/loaders.py +++ b/montage/loaders.py @@ -126,8 +126,10 @@ def load_name_list(file_obj, source='local'): edicts, warnings = get_by_filename_remote(rl) else: for filename in rl: - edict, warnings = get_file_info(filename) - edicts.append(edict) + file_info = get_file_info(filename) + if file_info is not None: + edict, warnings = file_info + edicts.append(edict) for edict in edicts: try: @@ -182,18 +184,25 @@ def get_entries_from_gsheet(raw_url, source='local'): def load_by_filename(filenames, source='local'): - ret = [] + entries = [] + warnings = [] if source == 'remote': files, warnings = get_by_filename_remote(filenames) else: files = [] for filename in filenames: file_info = get_file_info(filename) - files.append(file_info) + if file_info is not None: + files.append(file_info) + else: + warnings.append( + 'file "%s" does not exist, please check that its name is spelled correctly, ' + 'that it has not been renamed or removed' % (filename,) + ) for edict in files: entry = make_entry(edict) - ret.append(entry) - return ret + entries.append(entry) + return entries, warnings def load_category(category_name, source='local'): diff --git a/montage/rdb.py b/montage/rdb.py index 845d4cc0..afb2b365 100644 --- a/montage/rdb.py +++ b/montage/rdb.py @@ -1545,14 +1545,14 @@ def add_entries_by_name(self, round_id, file_names): source = 'remote' else: source = 'local' - entries = loaders.load_by_filename(file_names, source=source) + entries, warnings = loaders.load_by_filename(file_names, source=source) entries, new_entry_count = self.add_entries(rnd, entries) msg = ('%s loaded %s entries from filenames, %s new entries added' % (self.user.username, len(entries), new_entry_count)) self.log_action('add_entries', message=msg, round=rnd) - return entries + return entries, warnings def add_entries_from_csv(self, round_id, csv_url): # NOTE: this no longer creates RoundEntries, use