forked from mirror/MrDoc
调整文件大小计算函数的位置
This commit is contained in:
parent
0df256dec9
commit
d1f4f52cf3
@ -23,33 +23,6 @@ def validateTitle(title):
|
||||
return new_title
|
||||
|
||||
|
||||
# 文件大小 字节转换
|
||||
def sizeFormat(size, is_disk=False, precision=2):
|
||||
'''
|
||||
size format for human.
|
||||
byte ---- (B)
|
||||
kilobyte ---- (KB)
|
||||
megabyte ---- (MB)
|
||||
gigabyte ---- (GB)
|
||||
terabyte ---- (TB)
|
||||
petabyte ---- (PB)
|
||||
exabyte ---- (EB)
|
||||
zettabyte ---- (ZB)
|
||||
yottabyte ---- (YB)
|
||||
'''
|
||||
formats = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
unit = 1000.0 if is_disk else 1024.0
|
||||
if not(isinstance(size, float) or isinstance(size, int)):
|
||||
raise TypeError('a float number or an integer number is required!')
|
||||
if size < 0:
|
||||
raise ValueError('number must be non-negative')
|
||||
for i in formats:
|
||||
size /= unit
|
||||
if size < unit:
|
||||
return f'{round(size, precision)}{i}'
|
||||
return f'{round(size, precision)}{i}'
|
||||
|
||||
|
||||
# 文集列表
|
||||
def project_list(request):
|
||||
kw = request.GET.get('kw','')
|
||||
@ -1178,6 +1151,31 @@ def manage_img_group(request):
|
||||
# 附件管理
|
||||
@login_required()
|
||||
def manage_attachment(request):
|
||||
# 文件大小 字节转换
|
||||
def sizeFormat(size, is_disk=False, precision=2):
|
||||
'''
|
||||
size format for human.
|
||||
byte ---- (B)
|
||||
kilobyte ---- (KB)
|
||||
megabyte ---- (MB)
|
||||
gigabyte ---- (GB)
|
||||
terabyte ---- (TB)
|
||||
petabyte ---- (PB)
|
||||
exabyte ---- (EB)
|
||||
zettabyte ---- (ZB)
|
||||
yottabyte ---- (YB)
|
||||
'''
|
||||
formats = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
unit = 1000.0 if is_disk else 1024.0
|
||||
if not (isinstance(size, float) or isinstance(size, int)):
|
||||
raise TypeError('a float number or an integer number is required!')
|
||||
if size < 0:
|
||||
raise ValueError('number must be non-negative')
|
||||
for i in formats:
|
||||
size /= unit
|
||||
if size < unit:
|
||||
return f'{round(size, precision)}{i}'
|
||||
return f'{round(size, precision)}{i}'
|
||||
if request.method == 'GET':
|
||||
try:
|
||||
search_kw = request.GET.get('kw', None)
|
||||
|
Loading…
Reference in New Issue
Block a user