From 32f2aaac7a51adb984b9a393e319902e9ae2ba51 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 6 Apr 2018 18:19:23 +0200 Subject: [PATCH] Fix song ratio check --- marietje/api/views.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/marietje/api/views.py b/marietje/api/views.py index 58816ab..d0cde8d 100644 --- a/marietje/api/views.py +++ b/marietje/api/views.py @@ -245,11 +245,17 @@ def upload(request): # - U = duration * songs uploaded # - Q = duration * songs queued # - If 3*U < Q: allow upload (otherwise don't) - stats = upload_stats(request.user) - ratio = stats['minutes_queued'] / (3.0 * stats['minutes_upload']) + try: + stats = upload_stats(request.user) + ratio = stats['minutes_queued'] / (3.0 * stats['minutes_upload']) + ratiostr = '{:.2f}'.format(ratio) + except ZeroDivisionError: + ratio = 99999.0 # high enough + ratiostr = "∞" + if not request.user.is_superuser and ratio < 1.0: - msg = 'Queue-to-upload ratio too high. Please queue some more before uploading. ({:.2f})' - return JsonResponse({'success': False, 'errorMessage': msg.format(ratio)}) + msg = 'Queue-to-upload ratio too high. Please queue some more before uploading. ({})' + return JsonResponse({'success': False, 'errorMessage': msg.format(ratiostr)}) for i, file in enumerate(files): duration = File(file).info.length