mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 09:02:20 +01:00
Fix song ratio check
This commit is contained in:
@ -245,11 +245,17 @@ def upload(request):
|
|||||||
# - U = duration * songs uploaded
|
# - U = duration * songs uploaded
|
||||||
# - Q = duration * songs queued
|
# - Q = duration * songs queued
|
||||||
# - If 3*U < Q: allow upload (otherwise don't)
|
# - If 3*U < Q: allow upload (otherwise don't)
|
||||||
stats = upload_stats(request.user)
|
try:
|
||||||
ratio = stats['minutes_queued'] / (3.0 * stats['minutes_upload'])
|
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:
|
if not request.user.is_superuser and ratio < 1.0:
|
||||||
msg = 'Queue-to-upload ratio too high. Please queue some more before uploading. ({:.2f})'
|
msg = 'Queue-to-upload ratio too high. Please queue some more before uploading. ({})'
|
||||||
return JsonResponse({'success': False, 'errorMessage': msg.format(ratio)})
|
return JsonResponse({'success': False, 'errorMessage': msg.format(ratiostr)})
|
||||||
|
|
||||||
for i, file in enumerate(files):
|
for i, file in enumerate(files):
|
||||||
duration = File(file).info.length
|
duration = File(file).info.length
|
||||||
|
|||||||
Reference in New Issue
Block a user