Skip to content

Commit 30a36ea

Browse files
committed
updated unit display
1 parent 75bc761 commit 30a36ea

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,16 @@ def edit(id):
324324
user.save()
325325
return redirect(url_for('manage_users'))
326326
else:
327-
form['quota'].data = str(user.get_quota()) + 'KiB' if user.get_quota() else None
327+
quota = user.get_quota()
328+
if quota:
329+
units = ['KiB', 'MiB', 'GiB', 'TiB']
330+
cnt = 0
331+
while quota & ((1 << 9) - 1) == 0 and cnt < 3:
332+
quota = quota >> 10
333+
cnt = cnt + 1
334+
form['quota'].data = f"{quota}{units[cnt]}"
335+
else:
336+
form['quota'].data = None
328337
return render_template('edit.html', form=form, email=user.email)
329338

330339

0 commit comments

Comments
 (0)