示例#1
0
    def handle(self, *args, **options):
        print "bla for the win"
        reader = self._parse_csv(SCHEME_FILENAME)

        # Create all the nodes in a linear way.
        # We Create dictionary in the following format
        # { node_code : [node_object, node_parent_code] }
        nodes = {line["CODE"]: [Tree(name=line["NAME"], code=line["CODE"]), line["PARENT"]] for line in reader}
        root = Tree()

        # We go through the dict to create the hierarchy.
        for [node, parent] in nodes.values():
            if not parent:
                root.add_child(node)
            else:
                nodes[parent][0].add_child(node)

        # Upload the Tree to the DB.
        dataset = tree_Dataset("scheme", 0, clean=True)
        dataset.insert(root.to_dict())
        # bla = root.to_db(dataset)
        # dict = Tree.from_db(dataset,dataset.find_one({'_id':bla}))
        dataset.close()

        print dict
示例#2
0
    def handle(self, *args, **options):
        print "bla for the win"
        # get the db, exit if exists
        dataset = get_scheme()
        if dataset.count() > 0:
            if options['clean']:
                dataset.delete_many({})
            else:
                print 'Schema is already uploaded. Exiting.'
                return
        reader = self._parse_csv(SCHEME_FILENAME)
        # Create all the nodes in a linear way.
        # We Create dictionary in the following format
        # { node_code : [node_object, node_parent_code] }
        nodes = {
            line['CODE']: [
                Tree(name=line['NAME'],
                     code=line['CODE'],
                     expense=line['DIRECTION']), line['PARENT']
            ]
            for line in reader
        }
        root = Tree()

        expenditure_root = Tree(name=u'הוצאות',
                                amount=None,
                                code=None,
                                expense=True,
                                _id=None)
        revenue_root = Tree(name=u'הכנסות',
                            amount=None,
                            code=None,
                            expense=False,
                            _id=None)
        root.add_child(expenditure_root)
        root.add_child(revenue_root)

        # We go through the dict to create the hierarchy.
        for [node, parent] in nodes.values():
            if not parent:
                if node.expense:
                    expenditure_root.add_child(node)
                else:
                    revenue_root.add_child(node)
            else:
                nodes[parent][0].add_child(node)

        # Upload the Tree to the DB.
        dataset.insert(root.to_dict())
        dataset.close()