Exemple #1
0
    def add_extra_instance(self):

        for obj in self.session.new:
            core = None
            if hasattr(obj, "_from_load"):
                continue
            table = get_table_from_instance(obj, self.database)
            if table.entity == True:
                core = obj._rel__core
                if not core:
                    core = self.database.get_instance("_core")
                    obj._rel__core = core
                core.type = unicode(table.name)
                entity = self.database.get_instance("_core_entity")
                entity.table = unicode(table.name)
                core._rel_primary_entity = entity
                self.add(obj)
                self.add(core)
                self.add(entity)
            elif table.relation == True:
                core = obj._rel__core
                if not core:
                    core = self.database.get_instance("_core")
                    obj._rel__core = core
                core.type = unicode(table.name)
                table = obj._table
                primary_id = obj._primary
                secondary_id = obj._secondary
                core_entity_cls = self.database["_core_entity"].sa_class
                primary_obj = self.query(core_entity_cls).get(primary_id)
                secondary_obj = self.query(core_entity_cls).get(secondary_id)
                ##FIXME make a better error, a validation rule?
                assert(primary_obj.table) in table.primary_entities
                assert(secondary_obj.table) in table.secondary_entities
                core._rel_primary_entity = primary_obj
                core._rel_secondary_entity = secondary_obj
                self.add(primary_obj)
                self.add(secondary_obj)
                self.add(core)
                self.add(obj)
            elif table.info_table == True:
                if not obj._rel__core:
                    core_id = obj._core_id
                    core_cls = self.database["_core"].sa_class
                    core = self.query(core_cls).get(core_id)
                    assert(core.type) in table.valid_core_types
                    obj._rel__core = core
                    self.add(core)
                    self.add(obj)
                else:
                    core = obj._rel__core

            if core:
                self.object_store["core"].add(core)
Exemple #2
0
    def __init__(self, obj, database, log=False, id=False, modified=False):

        self.obj = obj
        self.database = database
        self.table = util.get_table_from_instance(obj, database)
        self.paths = self.table.paths
        self.log = log
        self.id = id
        self.modified = modified

        self.next_keys = {}
        self.get_next_keys()

        self.data = self.make_single_row(obj, "root", self.table)
Exemple #3
0
    def add_logged_instances(self):

        for obj in self.session.dirty:
            table = get_table_from_instance(obj, self.database)
            if not table.logged:
                continue
            logged_instance = self.database.get_instance("_log_%s"%table.name)
            changed = False
            for column in table.columns.keys():
                a, b, c = attributes.get_history(obj, column,
                                              passive = False)
                #logger.info (repr(a)+repr(b)+repr(c))
                if c:
                    setattr(logged_instance, column, c[0])
                    changed = True
                else:
                    setattr(logged_instance, column, getattr(obj, column))
            if changed:
                setattr(logged_instance, "_logged_table_id", obj.id)
                #setattr(logged_instance, table.name + "_logged", obj)
                self.add(logged_instance)