From d1f4f52cf37f1524f0bec133e9c8ea5f33eec8bd Mon Sep 17 00:00:00 2001 From: yangjian Date: Mon, 6 Apr 2020 17:55:12 +0800 Subject: [PATCH] =?UTF-8?q?=20=E8=B0=83=E6=95=B4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E8=AE=A1=E7=AE=97=E5=87=BD=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_doc/views.py | 52 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/app_doc/views.py b/app_doc/views.py index 155c818..e296044 100644 --- a/app_doc/views.py +++ b/app_doc/views.py @@ -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)