diff --git a/auto_pt/urls.py b/auto_pt/urls.py index 1061b21..a6d7c98 100644 --- a/auto_pt/urls.py +++ b/auto_pt/urls.py @@ -27,6 +27,7 @@ urlpatterns = [ path(r'sign_in_api', views.sign_in_api, name='sign_in_api'), path(r'update_site_api', views.update_site_api, name='update_site_api'), path(r'edit_site_api', views.edit_site_api, name='edit_site_api'), + path(r'site_sort_api', views.site_sort_api, name='site_sort_api'), path(r'get_log_list', views.get_log_list, name='get_log_list'), path(r'show_log_list', views.show_log_list, name='show_log_list'), path(r'get_log_content', views.get_log_content, name='get_log_content'), diff --git a/auto_pt/views.py b/auto_pt/views.py index 6cdfcc5..6b10700 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -624,6 +624,7 @@ def site_status_api(request): 'time_join': my_site.time_join, 'hr': my_site.my_hr, 'mail': my_site.mail, + 'sort_id': my_site.sort_id, 'sp': site_info.my_sp, 'bonus': site_info.my_bonus, # 'uploaded': FileSizeConvert.parse_2_file_size(site_info.uploaded), @@ -637,7 +638,7 @@ def site_status_api(request): status_list.append(site_info) # 按上传量排序 # status_list.sort(key=lambda x: x['mail'], reverse=False) - status_list.sort(key=lambda x: (x['mail'], x['uploaded']), reverse=True) + # status_list.sort(key=lambda x: (x['mail'], x['sort_id']), reverse=True) # sorted(status_list, key=lambda x: x['uploaded']) # 随机乱序 # random.shuffle(status_list) @@ -835,3 +836,29 @@ def get_log_content(request): def show_log_list(request): return render(request, 'auto_pt/showlog.html') + + +def site_sort_api(request): + try: + my_site_id = request.GET.get('id') + sort = request.GET.get('sort') + logger.info(f'ID值:{type(my_site_id)}') + my_site = MySite.objects.filter(id=my_site_id).first() + my_site.sort_id += int(sort) + + if int(my_site.sort_id) <= 0: + my_site.sort_id = 0 + my_site.save() + return JsonResponse(data=CommonResponse.success( + msg='排序已经最靠前啦,不要再点了!' + ).to_dict(), safe=False) + my_site.save() + return JsonResponse(data=CommonResponse.success( + msg='排序成功!' + ).to_dict(), safe=False) + except Exception as e: + logger.error(f'数据更新失败:{e}') + logger.error(traceback.format_exc(limit=3)) + return JsonResponse(data=CommonResponse.error( + msg=f'数据更新失败:{e}' + ).to_dict(), safe=False) diff --git a/static/js/utils.js b/static/js/utils.js index 2466e1d..70fff1b 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -28,6 +28,5 @@ function numberFormat(value) { param.value = ((value / Math.pow(k, i))).toFixed(2); param.unit = sizes[i]; } - console.log(param) return `${param.value}${param.unit}`; } diff --git a/templates/auto_pt/status.html b/templates/auto_pt/status.html index 62e1dca..f9c8bfd 100644 --- a/templates/auto_pt/status.html +++ b/templates/auto_pt/status.html @@ -68,6 +68,9 @@