Esempio n. 1
0
def root_folder(request, user: User):
    root_folder_ = FolderInfo.objects.get(user=user, belong_folder=None)
    return JsonResponse({
        'msg': '',
        'code': 1,
        'root_folder': root_folder_.folder_id,
        'token': user.get_token()
    })
Esempio n. 2
0
def my_file_list(request, user: User):
    file_list = []
    folder_list = []
    file_type = request.POST.get('type')
    belong_folder = request.POST.get('belong_folder')
    belong_folder_obj = FolderInfo.objects.get(folder_id=belong_folder)
    if file_type:
        file_obj_list = FileInfo.objects.filter(
            user=user, file_type=file_type, belong_folder=belong_folder_obj)
    else:
        file_obj_list = FileInfo.objects.filter(
            user=user, belong_folder=belong_folder_obj)
        folder_obj_list = FolderInfo.objects.filter(
            user=user, belong_folder=belong_folder_obj)
        for folder in folder_obj_list:
            if not folder.belong_folder:
                continue
            folder_list.append({
                'folder_name':
                folder.folder_name,
                'folder_id':
                folder.folder_id,
                'update_time':
                folder.update_time.astimezone(pytz.timezone(
                    'Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S'),
                'belong_folder':
                folder.belong_folder.folder_id,
            })
    for file in file_obj_list:
        file_list.append({
            'file_name':
            file.file_name,
            'file_id':
            file.file_id,
            'file_size':
            file.file_size,
            'update_time':
            file.update_time.astimezone(
                pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S'),
            'belong_folder':
            file.belong_folder.folder_id
        })
    return JsonResponse({
        'msg': '',
        'code': 1,
        'data': {
            'file_list': file_list,
            'folder_list': folder_list
        },
        'token': user.get_token()
    })