示例#1
0
文件: calendar.py 项目: qyqx/tracim
    def index(self):
        from tracim.config.app_cfg import CFG
        cfg = CFG.get_instance()

        # TODO BS 20160720: S'assurer d'être identifié !
        user = tmpl_context.identity.get('user')
        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)

        fake_api = DictLikeClass(
            current_user=dictified_current_user,
        )
        user_base_url = CalendarManager.get_user_base_url()
        workspace_base_url = CalendarManager.get_workspace_base_url()
        workspace_calendar_urls = CalendarManager\
            .get_workspace_readable_calendars_urls_for_user(user)
        base_href_url = \
            re.sub(r"^http[s]?://", '', cfg.RADICALE_CLIENT_BASE_URL_HOST)

        # Template will use User.auth_token, ensure it's validity
        user.ensure_auth_token()

        return DictLikeClass(
            fake_api=fake_api,
            user_base_url=user_base_url,
            workspace_base_url=workspace_base_url,
            workspace_clendar_urls=workspace_calendar_urls,
            auth_token=user.auth_token,
            base_href_url=base_href_url,
        )
示例#2
0
文件: content.py 项目: qyqx/tracim
    def get_one(self, page_id, revision_id=None):
        page_id = int(page_id)
        user = tmpl_context.current_user
        workspace = tmpl_context.workspace

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        content_api = ContentApi(
            user,
            show_deleted=True,
            show_archived=True,
        )
        if revision_id:
            page = content_api.get_one_from_revision(page_id, ContentType.Page,
                                                     workspace, revision_id)
        else:
            page = content_api.get_one(page_id, ContentType.Page, workspace)

        fake_api_breadcrumb = self.get_breadcrumb(page_id)
        fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
                                         current_user=current_user_content)
        fake_api = Context(CTX.FOLDER).toDict(fake_api_content)

        dictified_page = Context(CTX.PAGE).toDict(page, 'page')
        return DictLikeClass(result=dictified_page, fake_api=fake_api)
示例#3
0
文件: workspace.py 项目: buxx/tracim
    def get_one(self, workspace_id):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        workspace_api = WorkspaceApi(user)
        workspace = workspace_api.get_one(workspace_id)

        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(
            current_user=dictified_current_user,
            current_workspace_folders=dictified_folders,
            current_user_workspace_role=workspace.get_user_role(user)
        )

        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
            # TODO BS 20161209: Is the correct way to grab folders? No use API?
            workspace.get_valid_children(ContentApi.DISPLAYABLE_CONTENTS)
        )

        dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace')
        webdav_url = CFG.get_instance().WSGIDAV_CLIENT_BASE_URL

        return DictLikeClass(
            result=dictified_workspace,
            fake_api=fake_api,
            webdav_url=webdav_url,
        )
示例#4
0
    def get_one(self, thread_id, inverted: str = ''):
        thread_id = int(thread_id)
        user = tmpl_context.current_user
        workspace = tmpl_context.workspace

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        content_api = ContentApi(user)
        thread = content_api.get_one(thread_id, ContentType.Thread, workspace)

        fake_api_breadcrumb = self.get_breadcrumb(thread_id)
        fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
                                         current_user=current_user_content)
        fake_api = Context(CTX.FOLDER).toDict(fake_api_content)

        dictified_thread = Context(CTX.THREAD).toDict(thread, 'thread')

        if inverted:
            dictified_thread.thread.history = reversed(
                dictified_thread.thread.history)

        return DictLikeClass(result=dictified_thread,
                             fake_api=fake_api,
                             inverted=inverted)
示例#5
0
    def get_one(self, file_id, revision_id=None):
        file_id = int(file_id)
        user = tmpl_context.current_user
        workspace = tmpl_context.workspace
        workspace_id = tmpl_context.workspace_id

        current_user_content = Context(CTX.CURRENT_USER,
                                       current_user=user).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        content_api = ContentApi(user)
        if revision_id:
            file = content_api.get_one_from_revision(file_id, self._item_type,
                                                     workspace, revision_id)
        else:
            file = content_api.get_one(file_id, self._item_type, workspace)

        fake_api_breadcrumb = self.get_breadcrumb(file_id)
        fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
                                         current_user=current_user_content)
        fake_api = Context(CTX.FOLDER,
                           current_user=user).toDict(fake_api_content)

        dictified_file = Context(self._get_one_context,
                                 current_user=user).toDict(file, 'file')
        return DictLikeClass(result=dictified_file, fake_api=fake_api)
示例#6
0
文件: __init__.py 项目: qyqx/tracim
    def _struct_new_serialized(self, workspace_id, parent_id):
        print('values are: ', workspace_id, parent_id)
        result = DictLikeClass(
            item=DictLikeClass(parent=DictLikeClass(id=parent_id),
                               workspace=DictLikeClass(id=workspace_id)))

        return result
示例#7
0
    def index(self):
        user = tmpl_context.identity.get('user')
        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)

        fake_api = DictLikeClass(current_user=dictified_current_user, )

        return DictLikeClass(fake_api=fake_api)
示例#8
0
    def edit(self, id, next_url=None):
        id = tmpl_context.current_user.user_id
        current_user = tmpl_context.current_user
        assert id == current_user.user_id

        dictified_user = Context(CTX.USER).toDict(current_user, 'user')
        fake_api = DictLikeClass(next_url=next_url)
        return DictLikeClass(result=dictified_user, fake_api=fake_api)
示例#9
0
    def get_one(self, workspace_id, **kwargs):
        """
        :param workspace_id: Displayed workspace id
        :param kwargs:
          * show_deleted: bool: Display deleted contents or hide them if False
          * show_archived: bool: Display archived contents or hide them
            if False
        """
        show_deleted = str_as_bool(kwargs.get('show_deleted', False))
        show_archived = str_as_bool(kwargs.get('show_archived', ''))
        user = tmpl_context.current_user

        workspace_api = WorkspaceApi(user)
        workspace = workspace_api.get_one(workspace_id)

        unread_contents = ContentApi(user).get_last_unread(None,
                                                           ContentType.Any,
                                                           workspace=workspace)
        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)



        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(
            last_unread=Context(CTX.CONTENT_LIST).toDict(unread_contents,
                                                         'contents',
                                                         'nb'),
            current_user=dictified_current_user,
            current_workspace_folders=dictified_folders,
            current_user_workspace_role=workspace.get_user_role(user)
        )

        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
            # TODO BS 20161209: Is the correct way to grab folders? No use API?
            workspace.get_valid_children(
                ContentApi.DISPLAYABLE_CONTENTS,
                show_deleted=show_deleted,
                show_archived=show_archived,
            )
        )

        dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace')
        webdav_url = CFG.get_instance().WSGIDAV_CLIENT_BASE_URL

        return DictLikeClass(
            result=dictified_workspace,
            fake_api=fake_api,
            webdav_url=webdav_url,
            show_deleted=show_deleted,
            show_archived=show_archived,
        )
示例#10
0
文件: user.py 项目: norsig/tracim
    def get_one(self, user_id):
        user_id = tmpl_context.current_user.user_id

        current_user = tmpl_context.current_user
        assert user_id==current_user.user_id
        api = UserApi(current_user)
        current_user = api.get_one(current_user.user_id)
        dictified_user = Context(CTX.USER).toDict(current_user, 'user')
        current_user_content = Context(CTX.CURRENT_USER).toDict(tmpl_context.current_user)
        fake_api_content = DictLikeClass(current_user=current_user_content)
        fake_api = Context(CTX.WORKSPACE).toDict(fake_api_content)

        return DictLikeClass(result=dictified_user, fake_api=fake_api)
示例#11
0
    def test_is_item_still_editable(self):
        config = CFG.get_instance()
        item = DictLikeClass()

        config.DATA_UPDATE_ALLOWED_DURATION = 0
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)

        item.type = DictLikeClass({'id': 5})
        eq_(False, h.is_item_still_editable(config, item))

        item.type.id = 'comment'
        eq_(False, h.is_item_still_editable(config, item))

        config.DATA_UPDATE_ALLOWED_DURATION = -1
        item.type.id = 'comment'
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
        eq_(True, h.is_item_still_editable(config, item))

        config.DATA_UPDATE_ALLOWED_DURATION = 12
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
        eq_(
            True, h.is_item_still_editable(config, item),
            'created: {}, now: {}'.format(item.created,
                                          datetime.datetime.now())
        )  # This test will pass only if the test duration is less than 120s !!!

        config.DATA_UPDATE_ALLOWED_DURATION = 8
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
        eq_(False, h.is_item_still_editable(config, item))
示例#12
0
    def iconset_fa(self, **kw):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        fake_api = Context(CTX.CURRENT_USER).toDict({'current_user': current_user_content})

        return DictLikeClass(fake_api=fake_api)
示例#13
0
    def edit(self):
        if not tg.config.get('auth_is_internal'):
            raise HTTPForbidden()

        dictified_user = Context(CTX.USER).toDict(tmpl_context.current_user,
                                                  'user')
        return DictLikeClass(result=dictified_user)
示例#14
0
文件: root.py 项目: norsig/tracim
    def home(self):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        fake_api = Context(CTX.CURRENT_USER).toDict(
            {'current_user': current_user_content})

        last_active_contents = ContentApi(user).get_last_active(
            None, ContentType.Any, None)
        fake_api.last_actives = Context(CTX.CONTENT_LIST).toDict(
            last_active_contents, 'contents', 'nb')

        unread_contents = ContentApi(user).get_last_unread(
            None, ContentType.Any, None)
        fake_api.last_unread = Context(CTX.CONTENT_LIST).toDict(
            unread_contents, 'contents', 'nb')

        # INFO - D.A. - 2015-05-20
        # For now, we do not have favorties and read/unread status
        # so we only show:
        # - workspaces
        # - last activity
        # - oldest open stuff

        items = ContentApi(user).get_all_without_exception(
            ContentType.Any, None)[:4]
        fake_api.favorites = Context(CTX.CONTENT_LIST).toDict(
            items, 'contents', 'nb')
        return DictLikeClass(fake_api=fake_api)
示例#15
0
    def get_one(self, folder_id):
        folder_id = int(folder_id)
        user = tmpl_context.current_user
        workspace = tmpl_context.workspace
        workspace_id = tmpl_context.workspace_id

        current_user_content = Context(CTX.CURRENT_USER,
                                       current_user=user).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        content_api = ContentApi(user)
        folder = content_api.get_one(folder_id, ContentType.Folder, workspace)

        fake_api_breadcrumb = self.get_breadcrumb(folder_id)
        fake_api_subfolders = self.get_all_fake(workspace,
                                                folder.content_id).result
        fake_api_pages = self.pages.get_all_fake(workspace, folder).result
        fake_api_files = self.files.get_all_fake(workspace, folder).result
        fake_api_threads = self.threads.get_all_fake(workspace, folder).result

        fake_api_content = DictLikeClass(
            current_user=current_user_content,
            breadcrumb=fake_api_breadcrumb,
            current_folder_subfolders=fake_api_subfolders,
            current_folder_pages=fake_api_pages,
            current_folder_files=fake_api_files,
            current_folder_threads=fake_api_threads,
        )

        fake_api = Context(CTX.FOLDER).toDict(fake_api_content)

        sub_items = content_api.get_children(
            parent_id=folder.content_id,
            content_types=[
                ContentType.Folder,
                ContentType.File,
                ContentType.Page,
                ContentType.Thread,
            ],
        )
        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(sub_items)

        fake_api.content_types = Context(CTX.DEFAULT).toDict(
            content_api.get_all_types())

        dictified_folder = Context(CTX.FOLDER).toDict(folder, 'folder')
        return DictLikeClass(result=dictified_folder, fake_api=fake_api)
示例#16
0
文件: __init__.py 项目: qyqx/tracim
    def new(self, parent_id=None, workspace_id=None):
        """ Show the add form """
        tg.override_template(self.new, self.TEMPLATE_NEW)

        workspace_id = tg.request.GET['workspace_id']
        parent_id = tg.request.GET['parent_id'] if 'parent_id' in tg.request.GET else None

        return DictLikeClass(result=self._struct_new_serialized(workspace_id, parent_id))
示例#17
0
    def edit(self, id):
        current_user = tmpl_context.current_user
        api = UserApi(current_user)

        user = api.get_one(id)

        dictified_user = Context(CTX.USER).toDict(user, 'user')
        return DictLikeClass(result=dictified_user)
示例#18
0
    def me(self):
        current_user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(current_user)
        fake_api = Context(CTX.ADMIN_WORKSPACE).toDict(
            {'current_user': current_user_content})

        return DictLikeClass(fake_api=fake_api)
示例#19
0
文件: workspace.py 项目: qyqx/tracim
    def edit(self, id):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)

        workspace = workspace_api_controller.get_one(id)

        dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace')
        return DictLikeClass(result = dictified_workspace)
示例#20
0
文件: user.py 项目: norsig/tracim
    def get_one(self, user_id):
        current_user = tmpl_context.current_user
        api = UserApi(current_user)
        # role_api = RoleApi(tg.tmpl_context.current_user)
        # user_api = UserApi(tg.tmpl_context.current_user)

        user = api.get_one(user_id)  # FIXME

        role_api = RoleApi(tg.tmpl_context.current_user)
        role_list = role_api.get_roles_for_select_field()

        dictified_user = Context(CTX.ADMIN_USER).toDict(user, 'user')
        current_user_content = Context(CTX.CURRENT_USER).toDict(tmpl_context.current_user)
        fake_api_content = DictLikeClass(current_user=current_user_content,
                                         role_types=role_list)
        fake_api = Context(CTX.ADMIN_USER).toDict(fake_api_content)

        return DictLikeClass(result=dictified_user, fake_api=fake_api)
示例#21
0
文件: user.py 项目: norsig/tracim
    def get_all(self, *args, **kw):
        current_user = tmpl_context.current_user
        api = UserApi(current_user)

        users = api.get_all()

        current_user_content = Context(CTX.CURRENT_USER).toDict(current_user)
        fake_api = Context(CTX.USERS).toDict({'current_user': current_user_content})

        dictified_users = Context(CTX.USERS).toDict(users, 'users', 'user_nb')
        return DictLikeClass(result=dictified_users, fake_api=fake_api)
示例#22
0
    def mark_read(self, workspace_id, **kwargs):

        user = tmpl_context.current_user
        workspace_api = WorkspaceApi(user)
        workspace = workspace_api.get_one(workspace_id)

        content_api = ContentApi(user)
        content_api.mark_read__workspace(workspace)

        tg.redirect('/workspaces/{}'.format(workspace_id))
        return DictLikeClass(fake_api=fake_api)
示例#23
0
文件: __init__.py 项目: qyqx/tracim
    def new(self, parent_id=None, workspace_id=None):
        """ Show the add form
         Note: parent is the /folders/{parent_id} value
         When refactoring urls, this may be need somme update
        """
        tg.override_template(self.new, self.TEMPLATE_NEW)

        workspace_id = tg.request.GET['workspace_id']
        parent_id = tg.request.GET['parent_id'] if 'parent_id' in tg.request.GET else None

        return DictLikeClass(result=self._struct_new_serialized(workspace_id, parent_id))
示例#24
0
文件: workspace.py 项目: qyqx/tracim
    def get_all(self, *args, **kw):

        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)

        workspaces = workspace_api_controller.get_all()

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        fake_api = Context(CTX.ADMIN_WORKSPACE).toDict({'current_user': current_user_content})

        dictified_workspaces = Context(CTX.ADMIN_WORKSPACES).toDict(workspaces, 'workspaces', 'workspace_nb')
        return DictLikeClass(result = dictified_workspaces, fake_api=fake_api)
示例#25
0
    def edit(self, item_id):
        """
        Show the edit form (do not really edit the data)

        :param item_id:
        :return:
        """
        current_user_content = Context(CTX.CURRENT_USER).toDict(
            tmpl_context.current_user)
        fake_api = Context(CTX.FOLDER).toDict(
            DictLikeClass(current_user=current_user_content))

        item_id = int(item_id)
        user = tmpl_context.current_user
        workspace = tmpl_context.workspace

        content_api = ContentApi(user)
        item = content_api.get_one(item_id, ContentType.Any, workspace)

        dictified_item = Context(CTX.DEFAULT).toDict(item, 'item')
        return DictLikeClass(result=dictified_item, fake_api=fake_api)
示例#26
0
    def test_DictLikeClass(self):
        instance = DictLikeClass()

        instance.bob = 'titi'
        ok_(instance.bob == instance['bob'])

        instance['titi'] = 'bob'
        ok_(instance.titi == instance['titi'])

        instance2 = DictLikeClass(instance)
        ok_(instance2.bob == instance2['bob'])
        ok_(instance2.bob == instance.bob)
        ok_(instance2.titi == instance2['titi'])
        ok_(instance2.titi == instance.titi)

        instance3 = DictLikeClass({'bob': 'titi', 'toto': 'bib'})
        ok_(instance3.bob == 'titi')
        ok_(instance3.bob == instance3['bob'])

        ok_(instance3.toto == 'bib')
        ok_(instance3.toto == instance3['toto'])
示例#27
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        workspace_api = WorkspaceApi(user)
        workspace = workspace_api.get_one(workspace_id)

        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(current_user=dictified_current_user,
                                 current_workspace_folders=dictified_folders)\
        # ,
        #                      sub_items=Context(CTX.FOLDER_CONTENT_LIST).toDict(dictified_folders))

        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(workspace.get_valid_children())

        dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace')

        return DictLikeClass(result = dictified_workspace, fake_api=fake_api)
示例#28
0
    def index(self):
        # TODO BS 20160720: S'assurer d'être identifié !
        user = tmpl_context.identity.get('user')
        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)

        fake_api = DictLikeClass(current_user=dictified_current_user, )
        user_base_url = CalendarManager.get_user_base_url()
        workspace_base_url = CalendarManager.get_workspace_base_url()
        workspace_calendar_urls = CalendarManager\
            .get_workspace_readable_calendars_urls_for_user(user)

        # Template will use User.auth_token, ensure it's validity
        user.ensure_auth_token()

        return DictLikeClass(
            fake_api=fake_api,
            user_base_url=user_base_url,
            workspace_base_url=workspace_base_url,
            workspace_clendar_urls=workspace_calendar_urls,
            auth_token=user.auth_token,
        )
示例#29
0
    def test_DictLikeClass(self):
        instance = DictLikeClass()

        instance.bob = 'titi'
        ok_(instance.bob==instance['bob'])

        instance['titi'] = 'bob'
        ok_(instance.titi==instance['titi'])

        instance2 = DictLikeClass(instance)
        ok_(instance2.bob==instance2['bob'])
        ok_(instance2.bob==instance.bob)
        ok_(instance2.titi==instance2['titi'])
        ok_(instance2.titi==instance.titi)

        instance3 = DictLikeClass({'bob': 'titi', 'toto': 'bib'})
        ok_(instance3.bob=='titi')
        ok_(instance3.bob==instance3['bob'])

        ok_(instance3.toto=='bib')
        ok_(instance3.toto==instance3['toto'])
示例#30
0
    def test_is_item_still_editable(self):
        config = CFG.get_instance()
        item = DictLikeClass()

        config.DATA_UPDATE_ALLOWED_DURATION = 0
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)

        item.type = DictLikeClass({'id': 5})
        eq_(False, h.is_item_still_editable(config, item))

        item.type.id = 'comment'
        eq_(False, h.is_item_still_editable(config, item))

        config.DATA_UPDATE_ALLOWED_DURATION = -1
        item.type.id = 'comment'
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
        eq_(True, h.is_item_still_editable(config, item))

        config.DATA_UPDATE_ALLOWED_DURATION = 12
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
        eq_(True, h.is_item_still_editable(config, item), 'created: {}, now: {}'.format(item.created, datetime.datetime.now())) # This test will pass only if the test duration is less than 120s !!!

        config.DATA_UPDATE_ALLOWED_DURATION = 8
        item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
        eq_(False, h.is_item_still_editable(config, item))
示例#31
0
文件: content.py 项目: qyqx/tracim
    def get_one(self, thread_id, **kwargs):
        """
        :param thread_id: content_id of Thread
        :param inverted: fill with True equivalent to invert order of comments
                         NOTE: This parameter is in kwargs because prevent URL
                         changes.
        """
        inverted = kwargs.get('inverted')
        thread_id = int(thread_id)
        user = tmpl_context.current_user
        workspace = tmpl_context.workspace

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        content_api = ContentApi(
            user,
            show_deleted=True,
            show_archived=True,
        )
        thread = content_api.get_one(thread_id, ContentType.Thread, workspace)

        fake_api_breadcrumb = self.get_breadcrumb(thread_id)
        fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
                                         current_user=current_user_content)
        fake_api = Context(CTX.FOLDER).toDict(fake_api_content)

        dictified_thread = Context(CTX.THREAD).toDict(thread, 'thread')

        if inverted:
            dictified_thread.thread.history = \
                reversed(dictified_thread.thread.history)

        return DictLikeClass(
            result=dictified_thread,
            fake_api=fake_api,
            inverted=inverted,
        )
示例#32
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

        workspace_api = WorkspaceApi(user)
        workspace = workspace_api.get_one(workspace_id)

        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(
            current_user=dictified_current_user,
            current_workspace_folders=dictified_folders,
            current_user_workspace_role=workspace.get_user_role(user))

        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
            workspace.get_valid_children(ContentApi.DISPLAYABLE_CONTENTS))

        dictified_workspace = Context(CTX.WORKSPACE).toDict(
            workspace, 'workspace')

        return DictLikeClass(result=dictified_workspace, fake_api=fake_api)
示例#33
0
文件: content.py 项目: qyqx/tracim
    def get_one(self, file_id, revision_id=None):
        file_id = int(file_id)
        cache_path = CFG.get_instance().PREVIEW_CACHE
        preview_manager = PreviewManager(cache_path, create_folder=True)
        user = tmpl_context.current_user
        workspace = tmpl_context.workspace
        current_user_content = Context(CTX.CURRENT_USER,
                                       current_user=user).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)
        content_api = ContentApi(user, show_archived=True, show_deleted=True)
        if revision_id:
            file = content_api.get_one_from_revision(file_id, self._item_type,
                                                     workspace, revision_id)
        else:
            file = content_api.get_one(file_id, self._item_type, workspace)
            revision_id = file.revision_id

        file_path = content_api.get_one_revision_filepath(revision_id)
        nb_page = preview_manager.get_nb_page(file_path=file_path)
        preview_urls = []
        for page in range(int(nb_page)):
            url_str = '/previews/{}/pages/{}?revision_id={}'
            url = url_str.format(file_id, page, revision_id)
            preview_urls.append(url)

        fake_api_breadcrumb = self.get_breadcrumb(file_id)
        fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
                                         current_user=current_user_content)
        fake_api = Context(CTX.FOLDER,
                           current_user=user).toDict(fake_api_content)
        dictified_file = Context(self._get_one_context,
                                 current_user=user).toDict(file, 'file')
        result = DictLikeClass(result=dictified_file,
                               fake_api=fake_api,
                               nb_page=nb_page,
                               url=preview_urls)
        return result
示例#34
0
文件: __init__.py 项目: qyqx/tracim
    def get_all_fake(self, context_workspace: Workspace, context_folder: Content) -> [Content]:
        """
        fake methods are used in other controllers in order to simulate a client/server api.
        the "client" controller method will include the result into its own fake_api object
        which will be available in the templates

        :param context_workspace: the workspace which would be taken from tmpl_context if we were in the normal behavior
        :return:
        """
        workspace = context_workspace
        content_api = ContentApi(tmpl_context.current_user)
        items = content_api.get_all(context_folder.content_id, self._item_type, workspace)

        dictified_items = Context(self._get_all_context).toDict(items)
        return DictLikeClass(result = dictified_items)