当前位置: 首页>>代码示例>>Python>>正文


Python Content.tags方法代码示例

本文整理汇总了Python中kotti.resources.Content.tags方法的典型用法代码示例。如果您正苦于以下问题:Python Content.tags方法的具体用法?Python Content.tags怎么用?Python Content.tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kotti.resources.Content的用法示例。


在下文中一共展示了Content.tags方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_association_proxy

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_association_proxy(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'tag 1', u'tag 2']
        assert root[u'content_1'].tags == [u'tag 1', u'tag 2']
        assert type(root[u'content_1']._tags[0]) == TagsToContents
        assert type(root[u'content_1']._tags[0].tag) == Tag
        assert root[u'content_1']._tags[0].tag.title == u'tag 1'
        assert root[u'content_1']._tags[0].position == 0
        assert root[u'content_1']._tags[1].tag.title == u'tag 2'
        assert root[u'content_1']._tags[1].position == 1
        assert len(root[u'content_1']._tags) == 2

        root[u'content_2'] = Content()
        root[u'content_2'].tags = [u'tag 1', u'tag 3']
        assert len(root[u'content_2']._tags) == 2
        assert root[u'content_2']._tags[0].tag.title == u'tag 1'
        assert root[u'content_2']._tags[0].position == 0
        assert root[u'content_2']._tags[1].tag.title == u'tag 3'
        assert root[u'content_2']._tags[1].position == 1
        assert len(DBSession.query(Tag).all()) == 3
开发者ID:pombredanne,项目名称:Kotti,代码行数:27,代码来源:test_tags.py

示例2: test_delete_content_deletes_orphaned_tags

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_delete_content_deletes_orphaned_tags(self, root, events):
        from kotti.resources import Tag, Content

        root['content_1'] = Content()
        root['content_2'] = Content()
        root['content_1'].tags = ['tag 1', 'tag 2']
        root['content_2'].tags = ['tag 2']
        assert Tag.query.count() == 2
        del root['content_1']
        assert Tag.query.one().title == 'tag 2'
开发者ID:castaf,项目名称:Kotti,代码行数:12,代码来源:test_tags.py

示例3: test_get_content_items_for_tag_title

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_get_content_items_for_tag_title(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.util import content_with_tags

        root["folder_1"] = Content()
        root["folder_1"].tags = ["first tag", "second tag"]
        root["folder_1"]["content_1"] = Content()
        root["folder_1"]["content_1"].tags = ["third tag"]
        root["folder_1"]["content_2"] = Content()
        root["folder_1"]["content_2"].tags = ["first tag", "third tag"]

        result = (
            Content.query.join(TagsToContents)
            .join(Tag)
            .filter(Tag.title == "first tag")
            .all()
        )
        assert [res.name for res in result] == ["folder_1", "content_2"]
        result = (
            Content.query.join(TagsToContents)
            .join(Tag)
            .filter(Tag.title == "second tag")
            .all()
        )
        assert [res.name for res in result] == ["folder_1"]
        result = (
            Content.query.join(TagsToContents)
            .join(Tag)
            .filter(Tag.title == "third tag")
            .all()
        )
        assert sorted(res.name for res in result) == sorted(["content_1", "content_2"])

        # The same tests again, using content_with_tags():
        #
        #     About expected sort order:
        #
        #         In the first set of tests below, where we search by single
        #         tags, the query in the content_with_tags() function returns
        #         results in hierarchical order, from root.
        #
        # content_with_tags() is written to take a list of tags, but in the
        # default Kotti, presently, after some consideration about specialized
        # add-ons for searching, we do not support multiple tags searching, in
        # part to avoid establishing a specification.
        #
        result = content_with_tags(["first tag"])
        assert sorted([res.name for res in result]) == sorted(["folder_1", "content_2"])
        result = content_with_tags(["second tag"])
        assert sorted([res.name for res in result]) == sorted(["folder_1"])
        result = content_with_tags(["third tag"])
        assert sorted([res.name for res in result]) == sorted(
            ["content_1", "content_2"]
        )
开发者ID:Kotti,项目名称:Kotti,代码行数:56,代码来源:test_tags.py

示例4: test_delete_content_deletes_orphaned_tags

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_delete_content_deletes_orphaned_tags(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_1'].tags = [u'tag 1', u'tag 2']
        root[u'content_2'].tags = [u'tag 2']
        assert DBSession.query(Tag).count() == 2
        del root[u'content_1']
        assert DBSession.query(Tag).one().title == u'tag 2'
开发者ID:pombredanne,项目名称:Kotti,代码行数:15,代码来源:test_tags.py

示例5: test_search_results_for_tag_title

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_search_results_for_tag_title(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from substancek_cms_theme.views.search import search_results_for_tag

        root[u'folder_1'] = Content()
        root[u'folder_1'].tags = [u'first tag', u'second tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [u'third tag']
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'first tag', u'third tag']

        result = Content.query.join(TagsToContents).join(Tag).filter(
            Tag.title == u'first tag').all()
        assert [res.name for res in result] == [u'folder_1', u'content_2']
        result = Content.query.join(TagsToContents).join(Tag).filter(
            Tag.title == u'second tag').all()
        assert [res.name for res in result] == [u'folder_1']
        result = Content.query.join(TagsToContents).join(Tag).filter(
            Tag.title == u'third tag').all()
        assert [res.name for res in result] == [u'content_1', u'content_2']

        # The same tests again, using content_with_tags():
        #
        #     About expected sort order:
        #
        #         In the first set of tests below, where we search by single
        #         tags, the query in the content_with_tags() function returns
        #         results in hierarchical order, from root.
        #
        # content_with_tags() is written to take a list of tags, but in the
        # default Kotti, presently, after some consideration about specialized
        # add-ons for searching, we do not support multiple tags searching, in
        # part to avoid establishing a specification.
        #
        import mock
        from kotti.testing import DummyRequest
        dummy_request = DummyRequest()
        with mock.patch('substancek_cms_theme.views.util.has_permission') \
                as has_permission:
            has_permission.return_value = True
            dummy_request.GET['tag'] = u'first tag'
            result = search_results_for_tag(None, dummy_request)['results']
            assert [res['name'] for res in result] == [u'folder_1', u'content_2']
            dummy_request.GET['tag'] = u'second tag'
            result = search_results_for_tag(None, dummy_request)['results']
            assert [res['name'] for res in result] == [u'folder_1']
            dummy_request.GET['tag'] = u'third tag'
            result = search_results_for_tag(None, dummy_request)['results']
            assert [res['name'] for res in result] == [u'content_1', u'content_2']
开发者ID:substancek,项目名称:substancek_cms_theme,代码行数:51,代码来源:test_tags.py

示例6: test_get_content_items_from_tag

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_get_content_items_from_tag(self, root):
        from kotti.resources import Tag, Content

        root["folder_1"] = Content()
        root["folder_1"].tags = ["first tag", "second tag"]
        root["folder_1"]["content_1"] = Content()
        root["folder_1"]["content_1"].tags = ["third tag"]
        root["folder_1"]["content_2"] = Content()
        root["folder_1"]["content_2"].tags = ["first tag", "third tag"]
        first_tag = Tag.query.filter(Tag.title == "first tag").one()
        assert [rel.name for rel in first_tag.items] == ["folder_1", "content_2"]
        second_tag = Tag.query.filter(Tag.title == "second tag").one()
        assert [rel.name for rel in second_tag.items] == ["folder_1"]
        third_tag = Tag.query.filter(Tag.title == "third tag").one()
        assert [rel.name for rel in third_tag.items] == ["content_1", "content_2"]
开发者ID:Kotti,项目名称:Kotti,代码行数:17,代码来源:test_tags.py

示例7: test_get_content_items_from_tag

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_get_content_items_from_tag(self, root):
        from kotti.resources import Tag, Content

        root['folder_1'] = Content()
        root['folder_1'].tags = ['first tag', 'second tag']
        root['folder_1']['content_1'] = Content()
        root['folder_1']['content_1'].tags = ['third tag']
        root['folder_1']['content_2'] = Content()
        root['folder_1']['content_2'].tags = ['first tag', 'third tag']
        first_tag = Tag.query.filter(Tag.title == 'first tag').one()
        assert [rel.name for rel in first_tag.items] == [
            'folder_1', 'content_2']
        second_tag = Tag.query.filter(Tag.title == 'second tag').one()
        assert [rel.name for rel in second_tag.items] == ['folder_1']
        third_tag = Tag.query.filter(Tag.title == 'third tag').one()
        assert [rel.name for rel in third_tag.items] == [
            'content_1', 'content_2']
开发者ID:castaf,项目名称:Kotti,代码行数:19,代码来源:test_tags.py

示例8: test_delete_content_delete_tags_and_assignments

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_delete_content_delete_tags_and_assignments(self, root, events):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit.actions import NodeActions

        root['folder_1'] = Content()
        root['folder_1'].tags = ['first tag']
        root['folder_1']['content_1'] = Content()
        root['folder_1']['content_1'].tags = ['second tag']
        root['folder_1']['content_2'] = Content()
        root['folder_1']['content_2'].tags = ['third tag']
        assert Tag.query.count() == 3
        assert TagsToContents.query.count() == 3

        request = DummyRequest()
        request.POST['delete'] = 'delete'
        NodeActions(root['folder_1'], request).delete_node()
        assert Tag.query.count() == 0
        assert TagsToContents.query.count() == 0
开发者ID:castaf,项目名称:Kotti,代码行数:20,代码来源:test_tags.py

示例9: test_delete_tag_doesnt_touch_content

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_delete_tag_doesnt_touch_content(self, root, db_session):
        from kotti.resources import Tag, Content

        root['content_1'] = Content()
        root['content_1'].tags = ['my tag']

        assert Content.query.filter_by(name='content_1').count() == 1
        db_session.delete(Tag.query.filter_by(title='my tag').one())
        assert Content.query.filter_by(name='content_1').count() == 1
开发者ID:castaf,项目名称:Kotti,代码行数:11,代码来源:test_tags.py

示例10: test_delete_tag_assignment_delete_tag

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_delete_tag_assignment_delete_tag(self, root, events, db_session):
        from kotti.resources import Tag, TagsToContents, Content

        root['content_1'] = Content()
        root['content_1'].tags = ['my tag']

        assert Tag.query.count() == 1
        db_session.delete(TagsToContents.query.one())
        assert Tag.query.count() == 0
开发者ID:castaf,项目名称:Kotti,代码行数:11,代码来源:test_tags.py

示例11: test_get_content_items_for_tag_title

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_get_content_items_for_tag_title(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.util import content_with_tags

        ses = DBSession
        root = get_root()
        root[u'folder_1'] = Content()
        root[u'folder_1'].tags = [u'first tag', u'second tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [u'third tag']
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'first tag', u'third tag']

        result = ses.query(Content).join(TagsToContents).join(Tag).filter(
            Tag.title == u'first tag').all()
        assert [res.name for res in result] == [u'folder_1', u'content_2']
        result = ses.query(Content).join(TagsToContents).join(Tag).filter(
            Tag.title == u'second tag').all()
        assert [res.name for res in result] == [u'folder_1']
        result = ses.query(Content).join(TagsToContents).join(Tag).filter(
            Tag.title == u'third tag').all()
        assert [res.name for res in result] == [u'content_1', u'content_2']

        # The same tests again, using content_with_tags():
        #
        #     About expected sort order:
        #
        #         In the first set of tests below, where we search by single
        #         tags, the query in the content_with_tags() function returns
        #         results in hierarchical order, from root.
        #
        # content_with_tags() is written to take a list of tags, but in the
        # default Kotti, presently, after some consideration about specialized
        # add-ons for searching, we do not support multiple tags searching, in
        # part to avoid establishing a specification.
        #
        result = content_with_tags([u'first tag'])
        assert [res.name for res in result] == [u'folder_1', u'content_2']
        result = content_with_tags([u'second tag'])
        assert [res.name for res in result] == [u'folder_1']
        result = content_with_tags([u'third tag'])
        assert [res.name for res in result] == [u'content_1', u'content_2']
开发者ID:pombredanne,项目名称:Kotti,代码行数:46,代码来源:test_tags.py

示例12: test_get_content_items_from_tag

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_get_content_items_from_tag(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, Content

        ses = DBSession
        root = get_root()
        root[u'folder_1'] = Content()
        root[u'folder_1'].tags = [u'first tag', u'second tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [u'third tag', ]
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'first tag', u'third tag']
        first_tag = ses.query(Tag).filter(Tag.title == u'first tag').one()
        assert [rel.name for rel in first_tag.items] == [u'folder_1', u'content_2']
        second_tag = ses.query(Tag).filter(Tag.title == u'second tag').one()
        assert [rel.name for rel in second_tag.items] == [u'folder_1']
        third_tag = ses.query(Tag).filter(Tag.title == u'third tag').one()
        assert [rel.name for rel in third_tag.items] == [u'content_1', u'content_2']
开发者ID:fschulze,项目名称:Kotti,代码行数:21,代码来源:test_tags.py

示例13: test_delete_tag_assignment_doesnt_touch_content

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_delete_tag_assignment_doesnt_touch_content(self, root, db_session):
        from kotti.resources import Tag, TagsToContents, Content

        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        assert Tag.query.count() == 1
        assert Content.query.filter_by(name=u'content_1').count() == 1
        db_session.delete(TagsToContents.query.one())
        assert Content.query.filter_by(name=u'content_1').count() == 1
开发者ID:disko,项目名称:Kotti,代码行数:12,代码来源:test_tags.py

示例14: test_delete_tag_doesnt_touch_content

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_delete_tag_doesnt_touch_content(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        ses = DBSession
        assert ses.query(Content).filter_by(name=u'content_1').count() == 1
        ses.delete(ses.query(Tag).filter_by(title=u'my tag').one())
        assert ses.query(Content).filter_by(name=u'content_1').count() == 1
开发者ID:pombredanne,项目名称:Kotti,代码行数:15,代码来源:test_tags.py

示例15: test_association_proxy

# 需要导入模块: from kotti.resources import Content [as 别名]
# 或者: from kotti.resources.Content import tags [as 别名]
    def test_association_proxy(self, root):
        from kotti.resources import Tag, TagsToContents, Content

        root["content_1"] = Content()
        root["content_1"].tags = ["tag 1", "tag 2"]
        assert root["content_1"].tags == ["tag 1", "tag 2"]
        assert type(root["content_1"]._tags[0]) == TagsToContents
        assert type(root["content_1"]._tags[0].tag) == Tag
        assert root["content_1"]._tags[0].tag.title == "tag 1"
        assert root["content_1"]._tags[0].position == 0
        assert root["content_1"]._tags[1].tag.title == "tag 2"
        assert root["content_1"]._tags[1].position == 1
        assert len(root["content_1"]._tags) == 2

        root["content_2"] = Content()
        root["content_2"].tags = ["tag 1", "tag 3"]
        assert len(root["content_2"]._tags) == 2
        assert root["content_2"]._tags[0].tag.title == "tag 1"
        assert root["content_2"]._tags[0].position == 0
        assert root["content_2"]._tags[1].tag.title == "tag 3"
        assert root["content_2"]._tags[1].position == 1
        assert len(Tag.query.all()) == 3
开发者ID:Kotti,项目名称:Kotti,代码行数:24,代码来源:test_tags.py


注:本文中的kotti.resources.Content.tags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。