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
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)
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
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
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)
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
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)
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)
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)
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)
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
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, description='items_descr') 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) t2_root4 = TreeItem(title='url quoting', tree=t2, url='url 2 put_var', urlaspattern=True) t2_root4.save(force_insert=True) t2_root5 = TreeItem(title='url quoting 1.5 style', tree=t2, url="'url' 2 put_var", urlaspattern=True) t2_root5.save(force_insert=True) t2_root6 = TreeItem(title='url quoting 1.5 style', tree=t2, url='"url" 2 put_var', urlaspattern=True) t2_root6.save(force_insert=True) t2_root7 = TreeItem(title='for guests only', tree=t2, url='/some_other/', access_guest=True) t2_root7.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 cls.t2_root4 = t2_root4 cls.t2_root5 = t2_root5 cls.t2_root6 = t2_root6 cls.t2_root7 = t2_root7 # set urlconf to test's one cls.old_urlconf = urlresolvers.get_urlconf() urlresolvers.set_urlconf('sitetree.tests')
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
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")
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, description="items_descr" ) 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) t2_root4 = TreeItem(title="url quoting", tree=t2, url="url 2 put_var", urlaspattern=True) t2_root4.save(force_insert=True) t2_root5 = TreeItem(title="url quoting 1.5 style", tree=t2, url="'url' 2 put_var", urlaspattern=True) t2_root5.save(force_insert=True) t2_root6 = TreeItem(title="url quoting 1.5 style", tree=t2, url='"url" 2 put_var', urlaspattern=True) t2_root6.save(force_insert=True) t2_root7 = TreeItem(title="for guests only", tree=t2, url="/some_other/", access_guest=True) t2_root7.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 cls.t2_root4 = t2_root4 cls.t2_root5 = t2_root5 cls.t2_root6 = t2_root6 cls.t2_root7 = t2_root7 # set urlconf to test's one cls.old_urlconf = urlresolvers.get_urlconf() urlresolvers.set_urlconf("sitetree.tests")
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
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')
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() cls.t3_root_child5 = t3_root_child5 t3_en = Tree(alias='tree3_en', title='tree3en_title') t3_en.save() cls.t3_en = t3_en t3_en_root = TreeItem(title='root_en', tree=t3_en, url='/') t3_en_root.save() cls.t3_en_root = t3_en_root t3_en_root_child1 = TreeItem(title='child1_en', tree=t3_en, parent=t3_en_root, url='/0_en/') t3_en_root_child1.save() t3_en_root_child2 = TreeItem(title='child2_en', tree=t3_en, parent=t3_en_root, url='/the_same_url/') t3_en_root_child2.save() ########################################################### tree_main = Tree(alias='main') tree_main.save() cls.tree_main = tree_main tree_main_root = TreeItem(title='root', tree=tree_main, url='/', alias='for_dynamic') tree_main_root.save() cls.tree_main_root = tree_main_root
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, description='items_descr') 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) t2_root4 = TreeItem(title='url quoting', tree=t2, url='url 2 put_var', urlaspattern=True) t2_root4.save(force_insert=True) t2_root5 = TreeItem(title='url quoting 1.5 style', tree=t2, url="'url' 2 put_var", urlaspattern=True) t2_root5.save(force_insert=True) t2_root6 = TreeItem(title='url quoting 1.5 style', tree=t2, url='"url" 2 put_var', urlaspattern=True) t2_root6.save(force_insert=True) t2_root7 = TreeItem(title='for guests only', tree=t2, url='/some_other/', access_guest=True) t2_root7.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 cls.t2_root4 = t2_root4 cls.t2_root5 = t2_root5 cls.t2_root6 = t2_root6 cls.t2_root7 = t2_root7
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='/2/', 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='/1_en/') 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
def test_no_tree(self): ti = TreeItem(title='notree_item') self.assertRaises(Exception, ti.save)
def test_admin_tree_item_move(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
def test_tree_item_admin_item_move(self): admin = TreeItemAdmin(TreeItem, site) new_item_1 = TreeItem(title='title_1', sort_order=1, tree_id=1) new_item_1.save() new_item_2 = TreeItem(title='title_2', sort_order=2, tree_id=1) new_item_2.save() new_item_3 = TreeItem(title='title_3', sort_order=3, tree_id=1) 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)
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