格式化部分下载任务字段,优化显示

This commit is contained in:
ngfchl
2022-09-19 10:40:36 +08:00
parent 154fef31eb
commit 054d8397cd
2 changed files with 26 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ from pt_site import views as tasks
from pt_site.UtilityTool import FileSizeConvert
from pt_site.models import SiteStatus, MySite, Site, Downloader
from pt_site.views import scheduler, pt_spider
from ptools.base import CommonResponse, StatusCodeEnum, DownloaderCategory
from ptools.base import CommonResponse, StatusCodeEnum, DownloaderCategory, TorrentBaseInfo
def add_task(request):
@@ -141,7 +141,9 @@ def get_downloading(request):
'day,', ''
).replace(':', '小时', 1).replace(':', '', 1).split('.')[0] + ''
# 大小与速度处理
torrent['state'] = TorrentBaseInfo.download_state.get(torrent.get('state'))
torrent['ratio'] = '%.4f' % torrent.get('ratio') if torrent['ratio'] >= 0.0001 else 0
torrent['progress'] = '%.4f' % torrent.get('progress') if float(torrent['progress']) < 1 else 1
torrent['uploaded'] = '' if torrent['uploaded'] == 0 else torrent['uploaded']
torrent['upspeed'] = '' if torrent['upspeed'] == 0 else torrent['upspeed']
torrent['dlspeed'] = '' if torrent['dlspeed'] == 0 else torrent['dlspeed']

View File

@@ -131,6 +131,29 @@ class TorrentBaseInfo:
8: '6xFree'
}
download_state = {
'allocating': '分配',
'checkingDL': '校验中',
'checkingResumeData': '校验恢复数据',
'checkingUP': '',
'downloading': '下载中',
'error': '错误',
'forcedDL': '强制下载',
'forcedMetaDL': '强制下载元数据',
'forcedUP': '强制上传',
'metaDL': '下载元数据',
'missingFiles': '文件丢失',
'moving': '移动中',
'pausedDL': '暂停下载',
'pausedUP': '完成',
'queuedDL': '下载队列中',
'queuedUP': '下载队列中',
'stalledDL': '等待下载',
'stalledUP': '做种',
'unknown': '未知',
'uploading': '上传中',
}
class Trigger(models.TextChoices):
# date = 'date', '单次任务'