mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 22:52:23 +01:00
Fix song ratio check
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user