From 785845598f2a18f075c1306221e07a6c0d634dda Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 12 Sep 2022 20:50:57 +0300 Subject: [PATCH] catch crashes when no data has been imported --- core/views/logbooks.py | 6 +++++- core/views/uploads.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 6160de4..7f26687 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -84,7 +84,11 @@ def expedition(request, expeditionname): #print('! - expo {expeditionanme} using cached page') return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in }) - this_expedition = Expedition.objects.get(year=int(expeditionname)) + try: + this_expedition = Expedition.objects.get(year=int(expeditionname)) + except: + message = f'Expedition not found - database apparently empty, you probably need to do a full re-import of all data.' + return render(request, 'errors/generic.html', {'message': message}) expeditions = Expedition.objects.all() personexpeditiondays = [ ] diff --git a/core/views/uploads.py b/core/views/uploads.py index 860cba7..6b6161d 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -515,8 +515,13 @@ def scanupload(request, path=None): f = Path(settings.SURVEX_DATA) / svx if f.is_file(): path = svx.parent / svx.stem - #print(f' - {path=}') - svxfile = SurvexFile.objects.get(path=path) + #print(f' - {path=}') + try: + svxfile = SurvexFile.objects.get(path=path) + except: + message = f'Specified survex file not found - database apparently empty, you probably need to do a full re-import of all data.' + return render(request, 'errors/generic.html', {'message': message}) + print(f' - {svxfile=}') caves.append(svxfile.cave) caverefs.append(svxfile.cave.reference())