Beispiel #1
0
    def test_file_within_folder(self):
        test_folder = FolderRepo.create_folder(self.user.id, 'folder1')
        self.assertIsNotNone(test_folder)
        test_file = FileRepo.create_file(self.user.id, test_folder['id'],
                                         'test.txt', 'Hello, World')
        test_file_two = FileRepo.create_file(self.user.id, test_folder['id'],
                                             'test2.txt', 'Hello, World Two')

        res = FileRepo.get_files_within_folder(self.user.id, test_folder['id'])
        self.assertEqual(len(res), 2)
        self.assertIn(test_file, res)
        self.assertIn(test_file_two, res)
Beispiel #2
0
def folder(request, folder_id):
    context = {}
    current_user = request.user
    if current_user:
        folder_info = FolderRepo.get_folder(current_user.id, folder_id)
        child_folders_info = FolderRepo.get_all_folder_for_user_with_parent(
            current_user.id, folder_id)
        files_info = FileRepo.get_files_within_folder(
            current_user.id, folder_id)
        if not folder_info:
            return redirect('index')
        context['id'] = folder_info['id']
        context['name'] = folder_info['name']
        context['parent_id'] = folder_info['parent_id']
        context['files'] = files_info
        context['folders'] = child_folders_info
    return render(request, 'app/folder.html', context)