def loadSpring(*args): try: m = TreeItem() m.name, m.description = ya_loader.load_single_page() m.save() except OperationalError: print 'База заблокирована' print m.name
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 show_categories(self): """ Fetches the categories and subcategories from DB, builds tree and shows it in the GUI. """ cat_model = TreeModel(('Categories', )) self.categoriesView.setModel(cat_model) categories = self.orm.fetch_parents() for category in categories: item = TreeItem(category, cat_model.rootItem) cat_model.rootItem.appendChild(item) subs = self.orm.fetch_subcategories_for_parent(category) for sub in subs: sub_item = TreeItem(sub, item) item.appendChild(sub_item) self.categoriesView.expandAll()
def _update_accounts(self): """ Fetches account list from DB and builds a tree model of accounts. Adds subtotal and grand total to that model. """ accounts = self.orm.fetch_accounts_summary() account_dict = order_accounts(accounts) for key, accs in account_dict.items(): item = TreeItem((key, ''), self.rootItem) self.rootItem.appendChild(item) for acc in accs: acc_item = TreeItem(acc, item) item.appendChild(acc_item) # Add type total if len(accs) > 1: sub_balance = sum(acc.balance for acc in accs if not acc.exbudget) subtotal = TreeItem(('Total', sub_balance), item) item.appendChild(subtotal) # Add grand total total_balance = sum([acc.balance for acc in accounts if not acc.exbudget]) total = TreeItem(('Grand Total', total_balance), self.rootItem) self.rootItem.appendChild(total)
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
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 setUpClass(cls): cls.sitetree = SiteTree() t1 = Tree(alias='tree3') 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='/0/', inmenu=True, hidden=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=True, hidden=True) t1_root_child3.save(force_insert=True) t1_root_child4 = TreeItem(title='child4', tree=t1, parent=t1_root, url='/3/', inmenu=True, 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) 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