Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    def treeview_root(self, id='#',
                      current_id=None,
                      all_workspaces=True,
                      folder_allowed_content_types='',
                      ignore_id=None,
                      ignore_workspace_id=None):
        all_workspaces = bool(int(all_workspaces))

        # ignore_workspace_id is a string like 3,12,78,15
        ignored_ids = [int(id) for id in ignore_workspace_id.split(',')] if ignore_workspace_id else None

        if not current_id:
            # Default case is to return list of workspaces
            api = WorkspaceApi(tmpl_context.current_user)
            workspaces = api.get_all_for_user(tmpl_context.current_user,
                                              ignored_ids)
            dictified_workspaces = Context(CTX.MENU_API).toDict(workspaces, 'd')
            return dictified_workspaces

        allowed_content_types = ContentType.allowed_types_from_str(folder_allowed_content_types)
        ignored_item_ids = [int(ignore_id)] if ignore_id else []

        # Now complex case: we must return a structured tree
        # including the selected node, all parents (and their siblings)
        workspace, content = convert_id_into_instances(current_id)

        # The following step allow to select the parent folder when content itself is not visible in the treeview
        if content and content.type!=ContentType.Folder and CFG.CST.TREEVIEW_ALL!=CFG.get_instance().WEBSITE_TREEVIEW_CONTENT:
            content = content.parent if content.parent else None

        # This is the init of the recursive-like build of the tree
        content_parent = content
        tree_items = []

        # The first step allow to load child of selected item
        # (for example, when you select a folder in the windows explorer,
        # then the selected folder is expanded by default)
        content_api = ContentApi(tmpl_context.current_user)
        child_folders = content_api.get_child_folders(content_parent, workspace, allowed_content_types, ignored_item_ids)

        if len(child_folders)>0:
            first_child = child_folders[0]
            content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, first_child, tree_items, False, allowed_content_types, ignored_item_ids)

        content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items, True, allowed_content_types, ignored_item_ids)
        while content_parent:
            # Do the same for the parent level
            content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items)
        # Now, we have a tree_items list that is the root folders list,
        # so we now have to put it as a child of a list of workspaces
        should_select_workspace = not content

        full_tree = self._build_sibling_list_of_workspaces(workspace, tree_items, should_select_workspace, all_workspaces)

        return Context(CTX.MENU_API_BUILD_FROM_TREE_ITEM).toDict(full_tree, 'd')
Ejemplo n.º 8
0
    def test_serialize_ActionDescription_DEFAULT(self):
        obj = ActionDescription('archiving')
        obj.icon = 'places/folder-remote'
        obj.label = 'edit the content'

        res = Context(CTX.DEFAULT).toDict(obj)
        eq_(res.__class__, DictLikeClass)
        eq_(obj.id, res.id)
        eq_(obj.label, res.label)
        eq_(obj.icon, res.icon)
        eq_(3, len(res.keys()))
Ejemplo n.º 9
0
    def test_serialize_ActionDescription_DEFAULT(self):
        obj = ActionDescription('archiving')
        obj.icon = 'places/folder-remote'
        obj.label = 'edit the content'

        res = Context(CTX.DEFAULT).toDict(obj)
        eq_(res.__class__, DictLikeClass)
        eq_(obj.id, res.id)
        eq_(obj.label, res.label)
        eq_(obj.icon, res.icon)
        eq_(3, len(res.keys()))
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
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,
        )
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
Archivo: api.py Proyecto: qyqx/tracim
    def index(self):
        # NOTE BS 20161025: I can't use tmpl_context.current_user,
        # I d'ont know why
        user = tmpl_context.identity.get('user')
        calendar_workspaces = CalendarManager\
            .get_workspace_readable_calendars_for_user(user)
        calendars = Context(CTX.API_CALENDAR_WORKSPACE)\
            .toDict(calendar_workspaces)

        # Manually add information about user calendar
        calendars.append(Context(CTX.API_CALENDAR_USER).toDict(user))

        return {'value_list': calendars}
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    def test_serializer_toDict_int_str_and_LazyString(self):
        s = Context(CTX.DEFAULT).toDict(5)
        ok_(isinstance(s, int))
        eq_(5, s)

        s2 = Context(CTX.DEFAULT).toDict('bob')
        ok_(isinstance(s2, str))
        eq_('bob', s2)

        lazystr = LazyString('bob')
        s3 = Context(CTX.DEFAULT).toDict(lazystr)
        ok_(isinstance(s3, LazyString))
        eq_(lazystr, s3)
Ejemplo n.º 16
0
Archivo: api.py Proyecto: buxx/tracim
    def index(self):
        # NOTE BS 20161025: I can't use tmpl_context.current_user,
        # I d'ont know why
        user = tmpl_context.identity.get('user')
        calendar_workspaces = CalendarManager\
            .get_workspace_readable_calendars_for_user(user)
        calendars = Context(CTX.API_CALENDAR_WORKSPACE)\
            .toDict(calendar_workspaces)

        # Manually add information about user calendar
        calendars.append(Context(CTX.API_CALENDAR_USER).toDict(user))

        return {
            'value_list': calendars
        }
Ejemplo n.º 17
0
    def treeview_children(self,
                          id='#',
                          ignore_id=None,
                          allowed_content_types=None):
        """
        id must be "#" or something like "workspace_3__document_8"
        """
        if id == '#':
            return self.treeview_root()

        ignore_item_ids = [int(ignore_id)] if ignore_id else []
        workspace, content = convert_id_into_instances(id)

        viewable_content_types = []
        if allowed_content_types:
            viewable_content_types = allowed_content_types.split(',')
        else:
            viewable_content_types = self._get_treeviewable_content_types_or_none(
            )
        contents = ContentApi(tmpl_context.current_user).get_child_folders(
            content, workspace, [], ignore_item_ids, viewable_content_types)
        # This allow to show contents and folders group by type
        sorted_contents = ContentApi.sort_content(contents)

        dictified_contents = Context(CTX.MENU_API).toDict(sorted_contents, 'd')
        return dictified_contents
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
    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,
        )
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)
        role_api = RoleApi(tg.tmpl_context.current_user)
        user_api = UserApi(tg.tmpl_context.current_user)

        workspace = workspace_api_controller.get_one(workspace_id)
        role_list = role_api.get_roles_for_select_field()
        user_list = user_api.get_all()

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)

        dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace')
        fake_api_content = DictLikeClass(role_types=role_list, users=user_list, current_user=current_user_content)
        fake_api = Context(CTX.ADMIN_WORKSPACE).toDict(fake_api_content)

        return dict(result = dictified_workspace, fake_api = fake_api)
Ejemplo n.º 23
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)
Ejemplo n.º 24
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)
Ejemplo n.º 25
0
Archivo: api.py Proyecto: qyqx/tracim
    def index(self):
        # NOTE BS 20161025: I can't use tmpl_context.current_user,
        # I d'ont know why
        workspace_api = WorkspaceApi(tmpl_context.identity.get('user'))
        workspaces = workspace_api.get_all()
        serialized_workspaces = Context(CTX.API_WORKSPACE).toDict(workspaces)

        return {'value_list': serialized_workspaces}
Ejemplo n.º 26
0
    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)
Ejemplo n.º 27
0
    def test_serializer_get_converter_raise_ContextConverterNotFoundException(self):
        class A(object):
            pass

        @pod_serializer(A, CTX.PAGE)
        def dummy_converter(item: A, context: Context):
            return DictLikeClass({'a': 'agaga'})

        converter = Context.get_converter(CTX.FILE, A)
Ejemplo n.º 28
0
    def test_serializer_get_converter_raise_ContextConverterNotFoundException(
            self):
        class A(object):
            pass

        @pod_serializer(A, CTX.PAGE)
        def dummy_converter(item: A, context: Context):
            return DictLikeClass({'a': 'agaga'})

        converter = Context.get_converter(CTX.FILE, A)
Ejemplo n.º 29
0
    def test_serializer_get_converter_return_CTX_DEFAULT(self):
        class A(object):
            pass

        @pod_serializer(A, CTX.DEFAULT)
        def dummy_converter(item: A, context: Context):
            return DictLikeClass({'a': 'agaga'})

        converter = Context.get_converter(CTX.FILE, A)
        eq_(converter, dummy_converter)
Ejemplo n.º 30
0
    def test_serializer_get_converter_return_CTX_DEFAULT(self):
        class A(object):
            pass

        @pod_serializer(A, CTX.DEFAULT)
        def dummy_converter(item: A, context: Context):
            return DictLikeClass({'a': 'agaga'})

        converter = Context.get_converter(CTX.FILE, A)
        eq_(converter, dummy_converter)
Ejemplo n.º 31
0
    def search(self, keywords = ''):
        from tracim.lib.content import ContentApi

        user = tmpl_context.current_user
        api = ContentApi(user)

        items = []
        keyword_list = api.get_keywords(keywords)

        result = api.search(keyword_list)
        if result:
            items = result.limit(ContentApi.SEARCH_DEFAULT_RESULT_NB).all()

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

        search_results = Context(CTX.SEARCH).toDict(items, 'results', 'result_nb')
        search_results.keywords = keyword_list

        return DictLikeClass(fake_api=fake_api, search=search_results)
Ejemplo n.º 32
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)

        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
            folder.get_valid_children([ContentType.Folder,
                                       ContentType.File,
                                       ContentType.Page,
                                       ContentType.Thread]))

        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)
Ejemplo n.º 33
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)
Ejemplo n.º 34
0
    def test_serialize_Content_DEFAULT(self):
        self.app.get('/_test_vars')  # Allow to create fake context

        obj = Content()
        obj.content_id = 132
        obj.label = 'Some label'
        obj.description = 'Some Description'

        res = Context(CTX.DEFAULT).toDict(obj)
        eq_(res.__class__, DictLikeClass, res)
        eq_(obj.content_id, res.id, res)
        eq_(obj.label, res.label, res)

        ok_('folder' in res.keys())
        ok_('id' in res.folder.keys())
        eq_(None, res.folder.id)
        eq_(1, len(res.folder.keys()))

        ok_('workspace' in res.keys())
        eq_(None, res.workspace, res)
        eq_(4, len(res.keys()), res)
Ejemplo n.º 35
0
    def test_serialize_Content_DEFAULT(self):
        self.app.get('/_test_vars')  # Allow to create fake context

        obj = Content()
        obj.content_id = 132
        obj.label = 'Some label'
        obj.description = 'Some Description'

        res = Context(CTX.DEFAULT).toDict(obj)
        eq_(res.__class__, DictLikeClass, res)
        eq_(obj.content_id, res.id, res)
        eq_(obj.label, res.label, res)

        ok_('folder' in res.keys())
        ok_('id' in res.folder.keys())
        eq_(None, res.folder.id)
        eq_(1, len(res.folder.keys()))

        ok_('workspace' in res.keys())
        eq_(None, res.workspace, res)
        eq_(4, len(res.keys()), res)
Ejemplo n.º 36
0
    def search(self, keywords = ''):
        from tracim.lib.content import ContentApi

        user = tmpl_context.current_user
        api = ContentApi(user)

        items = []
        keyword_list = api.get_keywords(keywords)

        result = api.search(keyword_list)
        if result:
            items = result.limit(ContentApi.SEARCH_DEFAULT_RESULT_NB).all()
        api.exclude_unavailable(items)

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

        search_results = Context(CTX.SEARCH).toDict(items, 'results', 'result_nb')
        search_results.keywords = keyword_list

        return DictLikeClass(fake_api=fake_api, search=search_results)
Ejemplo n.º 37
0
    def test_serializer_toDict_for_list_of_objects(self):
        class A(object):
            def __init__(self, name):
                self.name = name

        @pod_serializer(A, CTX.DEFAULT)
        def dummy_converter(item: A, context: Context):
            return DictLikeClass({'name': item.name})

        mylist = [
            A('a'), A('b'), A('C')
        ]

        s = Context(CTX.DEFAULT).toDict(mylist)
        ok_('name' in s[0].keys())
        eq_('a', s[0].name)
        ok_('name' in s[1].keys())
        eq_('b', s[1].name)
        ok_('name' in s[2].keys())
        eq_('C', s[2].name)
        eq_(3, len(s))

        s2 = Context(CTX.DEFAULT).toDict(mylist, 'subitems', 'subitems_nb')

        ok_('subitems' in s2.keys(), s2)

        ok_('name' in s2.subitems[0].keys())
        eq_('a', s2.subitems[0].name)
        ok_('name' in s2.subitems[1].keys())
        eq_('b', s2.subitems[1].name)
        ok_('name' in s2.subitems[2].keys())
        eq_('C', s2.subitems[2].name)

        ok_('subitems' in s2.keys())
        ok_('subitems_nb' in s2.keys())
        eq_(3, s2.subitems_nb)
        eq_(3, len(s2.subitems))

        eq_(2, len(s2))
Ejemplo n.º 38
0
    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,
        )
Ejemplo n.º 39
0
    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)
Ejemplo n.º 40
0
    def test_serialize_Content_comment_THREAD(self):
        wor = Workspace()
        wor.workspace_id = 4

        fol = Content()
        fol.type = ContentType.Folder
        fol.content_id = 72
        fol.workspace = wor

        par = Content()
        par.type = ContentType.Thread
        par.content_id = 37
        par.parent = fol
        par.workspace = wor
        par.created = datetime.now()

        obj = Content()
        obj.type = ContentType.Comment
        obj.content_id = 132
        obj.label = 'some label'
        obj.description = 'Some Description'
        obj.parent = par
        obj.created = datetime.now()

        print('LANGUAGES #2 ARE', tg.i18n.get_lang())
        res = Context(CTX.THREAD).toDict(obj)
        eq_(res.__class__, DictLikeClass, res)

        ok_('label' in res.keys())
        eq_(obj.label, res.label, res)

        ok_('content' in res.keys())
        eq_(obj.description, res.content, res)

        ok_('created' in res.keys())

        ok_('icon' in res.keys())
        eq_(ContentType.get_icon(obj.type), res.icon, res)

        ok_('delete' in res.urls.keys())

        eq_(10, len(res.keys()), len(res.keys()))