From 7a4592ede30cc46e874c7c17b7fd010985b3467b Mon Sep 17 00:00:00 2001 From: wasswa-derick Date: Fri, 31 Aug 2018 09:20:43 +0300 Subject: [PATCH] Correct imports and structure of the try statements --- wger/manager/views/workout.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/wger/manager/views/workout.py b/wger/manager/views/workout.py index 3fb8e7bc..c1e39795 100644 --- a/wger/manager/views/workout.py +++ b/wger/manager/views/workout.py @@ -20,7 +20,9 @@ import json from decimal import Decimal -from django.shortcuts import render, redirect, get_object_or_404 +from django.http import HttpResponse +from django.utils.datastructures import MultiValueDictKeyError +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect, HttpResponseForbidden from django.contrib import messages from django.template.context_processors import csrf @@ -64,8 +66,6 @@ WgerDeleteMixin ) from wger.utils.helpers import make_token -from django.http import HttpResponse -from django.utils.datastructures import MultiValueDictKeyError logger = logging.getLogger(__name__) @@ -82,13 +82,11 @@ def overview(request): if request.method == 'POST': try: - request.FILES['workoutfile'] + file = request.FILES['workoutfile'] except MultiValueDictKeyError: messages.info(request, 'No File was Chosen for Importation!') return HttpResponseRedirect('overview') - file = request.FILES['workoutfile'] - try: data_bytes = file.read() data = data_bytes.decode("utf8") @@ -161,6 +159,7 @@ def overview(request): ) set_setting.save() + except (ValueError, KeyError, Exception) as e: messages.info(request, 'The Workout JSON file is invalid.') return HttpResponseRedirect('overview')