예제 #1
0
 def __init__(self, current_path, username):
     # 使用文件模块读取当前路径列表
     # 将URL正斜杠转换为操作系统的文件分割符
     current_path = os.path.sep.join(current_path.split('/'))
     d = StorageDirectory(current_path=current_path,
                          real_name='',
                          username=username)
     self.current_path_directory_list, self.current_path_file_list = d.get_inner_objects(
     )
예제 #2
0
 def move_directory(current_path, real_name, target_real_name, username):
     current_path = os.sep.join(current_path.split('/'))
     storage_directory = StorageDirectory(current_path=current_path,
                                          real_name=real_name,
                                          username=username)
     storage_directory.copy(target_dir_real_name=target_real_name)
     storage_directory.delete()
예제 #3
0
 def recover_directory(current_path, real_name, username):
     current_path = os.sep.join(current_path.split('/'))
     storage_directory = StorageDirectory(current_path=current_path,
                                          real_name=real_name,
                                          username=username)
     storage_directory.recover()
예제 #4
0
 def delete_directory(current_path, real_name, username):
     current_path = os.path.sep.join(current_path.split('/'))
     storage_directory = StorageDirectory(current_path=current_path,
                                          real_name=real_name,
                                          username=username)
     storage_directory.delete()
예제 #5
0
 def create_directory(current_path, name, username):
     current_path = os.path.sep.join(current_path.split('/'))
     storage_directory = StorageDirectory(current_path=current_path,
                                          database_name=name,
                                          username=username)
     storage_directory.create()
예제 #6
0
def show_file_list_page(request, path):
    """
    显示目录文件列表页面。
    :param path: 要查看的目录路径
    """
    try:
        user = RoleUser(request.session)
        auth = AuthController(user)
        auth.do_auth()
        if path == '-/':
            # 根目录
            d = StorageDirectory(current_path='',
                                 real_name='',
                                 username=user.get_username())
            path = ''
            if_root = True
            # 用于回退网页
            last_path = None
        else:
            # 其他目录
            path_list_temp = path.split('/')
            path_list = []
            for p in path_list_temp:
                if p != '':
                    path_list.append(p)
            real_name = path_list[-1]
            if len(path_list) > 1:
                real_path = os.path.sep.join(path_list[0:-1])
                last_path = '/'.join(path_list[0:-1])
            else:
                real_path = ''
                last_path = '-'
            d = StorageDirectory(current_path=real_path,
                                 real_name=real_name,
                                 username=user.get_username())
            if_root = False
            print('path_list: ', path_list, 'real_path: ', real_path,
                  'last_path: ', last_path)
        dir_list, file_list = d.get_inner_objects()
        context = {
            'back_url': request.get_full_path(),
            'if_root': if_root,
            'last_path': last_path,
            'current_path': path,
            'dir': [],
            'file': []
        }
        i = 0
        for di in dir_list:
            if path == '':
                di_path = di.real_name
            else:
                di_path = path + di.real_name
            context['dir'].append(
                [di.database_name, di.real_name, di.create_time, i, di_path])
            i = i + 1
        for fi in file_list:
            context['file'].append([
                fi.database_name, fi.real_name, fi.create_time, fi.size, i,
                fi.file_type
            ])
            i = i + 1
        # 获取服务器状态
        context['username'] = user.get_username()
        status_controller = UserSpaceController(user.get_username())
        context['total_space'] = status_controller.get_user_space()
        context[
            'remain_space'] = status_controller.get_user_remain_space_in_gb()
        context['space_rate'] = round(100 -
                                      (float(context['remain_space']) /
                                       float(context['total_space']) * 100))
        context['time'] = datetime.now()
        # 获取文件类型数据
        context['file_type'] = FileController.get_all_file_type()
        if 'if_copy' not in request.session:
            if_copy = False
        else:
            if_copy = request.session['if_copy']
        if 'if_move' not in request.session:
            if_move = False
        else:
            if_move = request.session['if_move']
        if if_move or if_copy:
            context['if_pofn'] = True
        else:
            context['if_pofn'] = False
        return render(request, 'management/index.html', context)
    except HasNoPermissionError:
        # 未登录
        return redirect('/user/login/')
    except UserHasNotBeenPermittedError as e:
        user.logout()
        return __return_error_page(request, e, '/user/login/')