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


Python models.TreeItem类代码示例

本文整理汇总了Python中sitetree.models.TreeItem的典型用法代码示例。如果您正苦于以下问题:Python TreeItem类的具体用法?Python TreeItem怎么用?Python TreeItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_admin_tree_item_move

def test_admin_tree_item_move(mock_request, common_tree):
    from sitetree.models import TreeItem, Tree

    main_tree = Tree(alias='main')
    main_tree.save()

    new_item_1 = TreeItem(title='title_1', sort_order=1, tree_id=main_tree.pk)
    new_item_1.save()

    new_item_2 = TreeItem(title='title_2', sort_order=2, tree_id=main_tree.pk)
    new_item_2.save()

    new_item_3 = TreeItem(title='title_3', sort_order=3, tree_id=main_tree.pk)
    new_item_3.save()

    admin = get_item_admin()

    admin.item_move(None, None, new_item_2.id, 'up')

    assert TreeItem.objects.get(pk=new_item_1.id).sort_order == 2
    assert TreeItem.objects.get(pk=new_item_2.id).sort_order == 1
    assert TreeItem.objects.get(pk=new_item_3.id).sort_order == 3

    admin.item_move(None, None, new_item_1.id, 'down')

    assert TreeItem.objects.get(pk=new_item_1.id).sort_order == 3
    assert TreeItem.objects.get(pk=new_item_2.id).sort_order == 1
    assert TreeItem.objects.get(pk=new_item_3.id).sort_order == 2
开发者ID:hajime-nishida,项目名称:django-sitetree,代码行数:28,代码来源:test_admin.py

示例2: test_tree_item_admin_item_move

    def test_tree_item_admin_item_move(self):
        main_tree = Tree.objects.get(alias='main')

        admin = TreeItemAdmin(TreeItem, site)

        new_item_1 = TreeItem(title='title_1', sort_order=1, tree_id=main_tree.pk)
        new_item_1.save()

        new_item_2 = TreeItem(title='title_2', sort_order=2, tree_id=main_tree.pk)
        new_item_2.save()

        new_item_3 = TreeItem(title='title_3', sort_order=3, tree_id=main_tree.pk)
        new_item_3.save()

        admin.item_move(None, None, new_item_2.id, 'up')

        self.assertEqual(TreeItem.objects.get(pk=new_item_1.id).sort_order, 2)
        self.assertEqual(TreeItem.objects.get(pk=new_item_2.id).sort_order, 1)
        self.assertEqual(TreeItem.objects.get(pk=new_item_3.id).sort_order, 3)

        admin.item_move(None, None, new_item_1.id, 'down')

        self.assertEqual(TreeItem.objects.get(pk=new_item_1.id).sort_order, 3)
        self.assertEqual(TreeItem.objects.get(pk=new_item_2.id).sort_order, 1)
        self.assertEqual(TreeItem.objects.get(pk=new_item_3.id).sort_order, 2)
开发者ID:elpaquete,项目名称:django-sitetree,代码行数:25,代码来源:tests.py

示例3: setUpClass

    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias="main")
        t1.save(force_insert=True)

        t1_root = TreeItem(title="root", tree=t1, url="/", alias="for_dynamic")
        t1_root.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
开发者ID:robcharlwood,项目名称:django-sitetree,代码行数:11,代码来源:tests.py

示例4: attach_items

        def attach_items(tree, items, parent=None):
            for item_dict in items:
                children = item_dict.pop('children', [])

                access_permissions = item_dict.pop('access_permissions', [])

                item = TreeItem(**item_dict)
                item.tree = tree
                item.parent = parent
                item.save()

                for permission in access_permissions:
                    item.access_permissions.add(Permission.objects.get(codename=permission))

                items_map['%s' % item.url] = item

                children and attach_items(tree, children, parent=item)
开发者ID:,项目名称:,代码行数:17,代码来源:

示例5: test_create_rename_delete

 def test_create_rename_delete(self):
     ti1 = TreeItem(title='new_root_item', tree=self.t1)
     ti1.save(force_insert=True)
     self.assertIsNotNone(ti1.id)
     self.assertEqual(ti1.title, 'new_root_item')
     ti1.title = 'not_new_root_item'
     ti1.save(force_update=True)
     self.assertEqual(ti1.title, 'not_new_root_item')
     ti1.delete()
     self.assertIsNone(ti1.id)
开发者ID:Guest007,项目名称:django-sitetree,代码行数:10,代码来源:tests.py

示例6: on_author_add

def on_author_add(instance, created, **kwargs):
    if created:
        tree_item = TreeItem(title=instance.name, tree_id=2,
                             url=instance.get_absolute_url(), author = instance)
        tree_item.save(force_insert=True)
    else:
        tree_item = TreeItem.objects.get(author = instance)
        tree_item.title = instance.name
        tree_item.url = instance.get_absolute_url()
        tree_item.save(force_update=True)
开发者ID:maremaremare,项目名称:biblio,代码行数:10,代码来源:receivers.py

示例7: on_category_add

def on_category_add(instance, created, **kwargs):
    parent_treeitem_id = TreeItem.objects.get(url=instance.author.get_absolute_url()).id
    if created:
        tree_item = TreeItem(
            title=instance.title, tree_id=2,  parent_id=parent_treeitem_id,
            url=instance.get_absolute_url())
        tree_item.save(force_insert=True)
    else:
        tree_item = TreeItem.objects.get(category = instance)
        tree_item.title = instance.title
        tree_item.url = instance.get_absolute_url()
        tree_item.save(force_update=True)
        
开发者ID:maremaremare,项目名称:biblio,代码行数:12,代码来源:receivers.py

示例8: test_no_recursive_parents

    def test_no_recursive_parents(self):
        """Verify that treeitems cannot be their own parent."""
        tree = Tree(alias="mytree")
        tree.save()
        tree_item = TreeItem(title="i'm my own grandpa", tree=tree)
        # This item needs to be saved, otherwise it cannot be set
        # as a parent.
        tree_item.save()

        tree_item.parent = tree_item
        tree_item.save()
        self.assertNotEqual(tree_item, tree_item.parent)
开发者ID:elpaquete,项目名称:django-sitetree,代码行数:12,代码来源:tests.py

示例9: setUpClass

    def setUpClass(cls):
        cls.sitetree = SiteTree()

        tree_ttags = Tree(alias='ttags')
        tree_ttags.save()
        cls.tree_ttags = tree_ttags

        tree_ttags_root = TreeItem(
            title='root', tree=tree_ttags, url='/',
            insitetree=True, inbreadcrumbs=True, inmenu=True
        )
        tree_ttags_root.save()
        cls.tree_ttags_root = tree_ttags_root

        tree_ttags_root_child1 = TreeItem(
            title='sometitle', tree=tree_ttags, parent=tree_ttags_root, url='/child1',
            insitetree=True, inbreadcrumbs=True, inmenu=True,
            hint='somehint', description='somedescr'
        )
        tree_ttags_root_child1.save()
        cls.tree_ttags_root_child1 = tree_ttags_root_child1
开发者ID:wengole,项目名称:django-sitetree,代码行数:21,代码来源:tests.py

示例10: setUpClass

    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias="tree1")
        t1.save(force_insert=True)

        t1_root = TreeItem(title="root", tree=t1, url="/")
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title="child1", tree=t1, parent=t1_root, url="/about/")
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title="child2", tree=t1, parent=t1_root, url="articles_list", urlaspattern=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(
            title="subchild1", tree=t1, parent=t1_root_child2, url="articles_detailed art_id", urlaspattern=True
        )
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title="subchild2", tree=t1, parent=t1_root_child2, url="/not_articles/10/")
        t1_root_child2_sub2.save(force_insert=True)

        t1_root_child3 = TreeItem(
            title="child_with_var_str", tree=t1, parent=t1_root, url="somevar_str", urlaspattern=True
        )
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(
            title="child_with_var_list", tree=t1, parent=t1_root, url="somevar_list", urlaspattern=True
        )
        t1_root_child4.save(force_insert=True)

        t2 = Tree(alias="tree2")
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title="{{ t2_root1_title }}", tree=t2, url="/")
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title="put {{ t2_root2_title }} inside", tree=t2, url="/sub/")
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title="for logged in only", tree=t2, url="/some/", access_loggedin=True)
        t2_root3.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child3 = t1_root_child3
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3

        # set urlconf to test's one
        cls.old_urlconf = urlresolvers.get_urlconf()
        urlresolvers.set_urlconf("sitetree.tests")
开发者ID:artursvonda,项目名称:django-sitetree,代码行数:62,代码来源:tests.py

示例11: init_trees

    def init_trees(cls):
        cls.sitetree = SiteTree()

        ###########################################################

        t1 = Tree(alias='tree1')
        t1.save()
        cls.t1 = t1

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save()
        cls.tree_ttags_root = t1_root

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/about/')
        t1_root_child1.save()
        cls.tree_ttags_root_child1 = t1_root_child1

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='articles_list', urlaspattern=True,
                                  description='items_descr')
        t1_root_child2.save()
        cls.t1_root_child2 = t1_root_child2

        t1_root_child2_sub1 = TreeItem(title='subchild1', tree=t1, parent=t1_root_child2,
                                       url='articles_detailed art_id', urlaspattern=True)
        t1_root_child2_sub1.save()
        cls.t1_root_child2_sub1 = t1_root_child2_sub1

        t1_root_child2_sub2 = TreeItem(title='subchild2', tree=t1, parent=t1_root_child2, url='/not_articles/10/')
        t1_root_child2_sub2.save()
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        t1_root_child3 = TreeItem(title='child_with_var_str', tree=t1, parent=t1_root, url='somevar_str',
                                  urlaspattern=True)
        t1_root_child3.save()
        cls.t1_root_child3 = t1_root_child3

        t1_root_child4 = TreeItem(title='child_with_var_list', tree=t1, parent=t1_root, url='somevar_list',
                                  urlaspattern=True)
        t1_root_child4.save()

        t2 = Tree(alias='tree2')
        t2.save()
        cls.t2 = t2

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save()
        cls.t2_root1 = t2_root1

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside', tree=t2, url='/sub/')
        t2_root2.save()
        cls.t2_root2 = t2_root2

        t2_root3 = TreeItem(title='for logged in only', tree=t2, url='/some/', access_loggedin=True)
        t2_root3.save()
        cls.t2_root3 = t2_root3

        t2_root4 = TreeItem(title='url quoting', tree=t2, url='url 2 put_var', urlaspattern=True)
        t2_root4.save()
        cls.t2_root4 = t2_root4

        t2_root5 = TreeItem(title='url quoting 1.5 style', tree=t2, url="'url' 2 put_var", urlaspattern=True)
        t2_root5.save()
        cls.t2_root5 = t2_root5

        t2_root6 = TreeItem(title='url quoting 1.5 style', tree=t2, url='"url" 2 put_var', urlaspattern=True)
        t2_root6.save()
        cls.t2_root6 = t2_root6

        t2_root7 = TreeItem(title='for guests only', tree=t2, url='/some_other/', access_guest=True)
        t2_root7.save()
        cls.t2_root7 = t2_root7

        ###########################################################

        t3 = Tree(alias='tree3')
        t3.save()
        cls.t3 = t3

        t3_en_root = TreeItem(title='root', tree=t3, url='/', hidden=True)
        t3_en_root.save()
        cls.t3_root = t3_en_root

        t3_root_child1 = TreeItem(title='child1', tree=t3, parent=t3_en_root, url='/0/', access_loggedin=True)
        t3_root_child1.save()
        cls.t3_root_child1 = t3_root_child1

        t3_root_child2 = TreeItem(title='child2', tree=t3, parent=t3_en_root, url='/1/', inmenu=True, hidden=True)
        t3_root_child2.save()
        cls.t3_root_child2 = t3_root_child2

        t3_root_child3 = TreeItem(title='child3', tree=t3, parent=t3_en_root, url='/the_same_url/', inmenu=False)
        t3_root_child3.save()
        cls.t3_root_child3 = t3_root_child3

        t3_root_child4 = TreeItem(title='child4', tree=t3, parent=t3_en_root, url='/3/', hidden=True)
        t3_root_child4.save()
        cls.t3_root_child4 = t3_root_child4

        t3_root_child5 = TreeItem(title='child5', tree=t3, parent=t3_en_root, url='/4/', inmenu=True, hidden=True)
        t3_root_child5.save()
#.........这里部分代码省略.........
开发者ID:elpaquete,项目名称:django-sitetree,代码行数:101,代码来源:tests.py

示例12: test_model_tree_item

def test_model_tree_item():
    from sitetree.models import Tree, TreeItem

    tree1 = Tree(alias='test')
    tree1.save()

    item1 = TreeItem(tree=tree1, alias='only', title='only title')
    item1.save()

    assert str(item1) == item1.title

    item2 = TreeItem(tree=tree1, alias='other', parent=item1)
    item2.save()

    item3 = TreeItem(tree=tree1, parent=item1)
    item3.save()

    item3.sort_order = 100
    item3.parent = item3
    item3.save()

    assert item3.parent is None  # Can't be itself
    assert item3.sort_order == 100

    item3.sort_order = 0
    item3.save()

    assert item3.sort_order == item3.id  # Automatic ordering

    with pytest.raises(Exception):
        TreeItem(tree=tree1, alias='only').save()  # Unique alias within tree
开发者ID:hajime-nishida,项目名称:django-sitetree,代码行数:31,代码来源:test_models.py

示例13: setUpClass

    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='tree1')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/about/')
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='articles_list', urlaspattern=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(title='subchild1', tree=t1, parent=t1_root_child2,
            url='articles_detailed art_id', urlaspattern=True)
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title='subchild2', tree=t1, parent=t1_root_child2, url='/not_articles/10/')
        t1_root_child2_sub2.save(force_insert=True)

        t2 = Tree(alias='tree2')
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside', tree=t2, url='/sub/')
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title='for logged in only', tree=t2, url='/some/', access_loggedin=True)
        t2_root3.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3

        # set urlconf to test's one
        cls.old_urlconf = urlresolvers.get_urlconf()
        urlresolvers.set_urlconf('sitetree.tests')
开发者ID:Brendtron5000,项目名称:django-sitetree,代码行数:50,代码来源:tests.py


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