本文整理汇总了Python中sitetree.models.Tree类的典型用法代码示例。如果您正苦于以下问题:Python Tree类的具体用法?Python Tree怎么用?Python Tree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tree类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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
示例3: test_create_rename_delete
def test_create_rename_delete(self):
tree = Tree(alias='mytree')
tree.save(force_insert=True)
self.assertIsNotNone(tree.id)
self.assertEqual(tree.alias, 'mytree')
tree.alias = 'not_mytree'
tree.save(force_update=True)
self.assertEqual(tree.alias, 'not_mytree')
tree.delete()
self.assertIsNone(tree.id)
示例4: 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
示例5: test_model_tree
def test_model_tree():
from sitetree.models import Tree
tree = Tree(alias='test')
tree.save()
assert str(tree) == tree.alias
assert tree.get_title() == tree.alias
with pytest.raises(Exception):
Tree(alias='test').save() # Unique alias
示例6: 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
示例7: 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')
示例8: setUpClass
def setUpClass(cls):
cls.sitetree = SiteTree()
t1 = Tree(alias='tree3')
t1.save(force_insert=True)
t1_root = TreeItem(title='root', tree=t1, url='/', hidden=True)
t1_root.save(force_insert=True)
t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/0/', access_loggedin=True)
t1_root_child1.save(force_insert=True)
t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='/1/', inmenu=True, hidden=True)
t1_root_child2.save(force_insert=True)
t1_root_child3 = TreeItem(title='child3', tree=t1, parent=t1_root, url='/the_same_url/', inmenu=False)
t1_root_child3.save(force_insert=True)
t1_root_child4 = TreeItem(title='child4', tree=t1, parent=t1_root, url='/3/', hidden=True)
t1_root_child4.save(force_insert=True)
t1_root_child5 = TreeItem(title='child5', tree=t1, parent=t1_root, url='/4/', inmenu=True, hidden=True)
t1_root_child5.save(force_insert=True)
t2 = Tree(alias='tree3_en', title='tree3en_title')
t2.save(force_insert=True)
t2_root = TreeItem(title='root_en', tree=t2, url='/')
t2_root.save(force_insert=True)
t2_root_child1 = TreeItem(title='child1_en', tree=t2, parent=t2_root, url='/0_en/')
t2_root_child1.save(force_insert=True)
t2_root_child2 = TreeItem(title='child2_en', tree=t2, parent=t2_root, url='/the_same_url/')
t2_root_child2.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 = t1_root_child3
cls.t1_root_child2 = t1_root_child4
cls.t1_root_child2 = t1_root_child5
cls.t2 = t2
cls.t2_root = t2_root
示例9: setUpClass
def setUpClass(cls):
cls.sitetree = SiteTree()
t1 = Tree(alias="tree3")
t1.save(force_insert=True)
t1_root = TreeItem(title="root", tree=t1, url="/", hidden=True)
t1_root.save(force_insert=True)
t1_root_child1 = TreeItem(title="child1", tree=t1, parent=t1_root, url="/0/", access_loggedin=True)
t1_root_child1.save(force_insert=True)
t1_root_child2 = TreeItem(title="child2", tree=t1, parent=t1_root, url="/1/", inmenu=True, hidden=True)
t1_root_child2.save(force_insert=True)
t1_root_child3 = TreeItem(title="child3", tree=t1, parent=t1_root, url="/the_same_url/", inmenu=False)
t1_root_child3.save(force_insert=True)
t1_root_child4 = TreeItem(title="child4", tree=t1, parent=t1_root, url="/3/", hidden=True)
t1_root_child4.save(force_insert=True)
t1_root_child5 = TreeItem(title="child5", tree=t1, parent=t1_root, url="/4/", inmenu=True, hidden=True)
t1_root_child5.save(force_insert=True)
t2 = Tree(alias="tree3_en")
t2.save(force_insert=True)
t2_root = TreeItem(title="root_en", tree=t2, url="/")
t2_root.save(force_insert=True)
t2_root_child1 = TreeItem(title="child1_en", tree=t2, parent=t2_root, url="/0_en/")
t2_root_child1.save(force_insert=True)
t2_root_child2 = TreeItem(title="child2_en", tree=t2, parent=t2_root, url="/the_same_url/")
t2_root_child2.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 = t1_root_child3
cls.t1_root_child2 = t1_root_child4
cls.t1_root_child2 = t1_root_child5
cls.t2_root = t2_root
示例10: test_unique_aliases
def test_unique_aliases(self):
tree1 = Tree(alias='mytree')
tree1.save(force_insert=True)
tree2 = Tree(alias='mytree')
self.assertRaises(Exception, tree2.save)
示例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()
#.........这里部分代码省略.........