コード例 #1
0
ファイル: sheet.py プロジェクト: AmirKremer/openmuni-budgets
                if not level in keys_by_level:
                    keys_by_level[level] = []
                keys_by_level[level].append(parent_key)

            else:
                parent_key = node.path
                if parent_key not in children_lookup:
                    children_lookup[parent_key] = []
                keys_by_level[1].append(parent_key)

        levels = keys_by_level.keys()
        levels.sort(reverse=True)
        for level in levels:
            keys = keys_by_level[level]
            for key in keys:
                children = children_lookup[key]
                item = self.saved_cache[key]

                for child in children:
                    # set the item's parent for all children
                    child.parent = item
                    child.save()

                item.budget = reduce(_make_adder('budget'), children, None)
                item.actual = reduce(_make_adder('actual'), children, None)
                item.save()


register('sheet', SheetParser)
コード例 #2
0
ファイル: template.py プロジェクト: BeOleg/openmuni-budgets
        different = False

        if isinstance(obj, dict):
            name = obj.get('name')
        else:
            name = obj.name

        if name != parent_node.name:
            different = True
            diff.append('name')

        return different, diff

    def _diff_template(self):
        print 'diffing'
        #TODO: consider not declaring this tempalte as different if there are nodes left in parent cache
        # and instead, perhaps instantiate these also - maybe without an item? Or null amounts?
        #TODO: optimize process so container is only created at the end if it's different from its parent
        if not self.template_is_different and not len(self.parent_cache):
            print 'same'
            # this should also delete all TemplateNodeRelations to this template
            self.container_object.delete()
            # since all nodes already relate to the parent no need to do anything
            self.container_object = self.parent
        else:
            print 'nodes left in parent %s' % len(self.parent_cache)
            for key in self.parent_cache:
                print key

register('template', TemplateParser)