コード例 #1
0
ファイル: webobject.py プロジェクト: odinlake/tstp
    def propose_edit_object(cls, cat1, name1, cat2, name2, attrs, vals):
        table = "web_connections"
        dt = datetime.datetime.now()
        cat, name = esc(cat, name)
        attrstr = cls.sql_filter_list(attrs)
        oldvalue = None
        alu = dict(izip(attrs, vals))
        evidbase = "ev.%d-" % uuid("event")
        idx = 0

        events = []
        updates = []

        for attr, oldvalue in do("""
            SELECT attr, value FROM `%s` WHERE 
            category1 = "%s" AND name1 = "%s" AND
            category2 = "%s" AND name2 = "%s" AND
            attr IN %s LIMIT 1
        """ % (table, cat1, name1, cat2, name2, attrstr)):
            evid = evidbase + str(idx)
            idx += 1
            newvalue = alu[attr]
            event = (evid, "odinlake", dt, "edit", "event", "", 
                cat1, name1, cat2, name2, attr, oldvalue, newvalue, "pending")
            update = ("featureof", cat1, name1, cat2, name2, attr, newvalue)

            events.append(event)
            updates.append(update)
            
        return events, updates
コード例 #2
0
ファイル: webobject.py プロジェクト: odinlake/tstp
    def propose_edit_object(cls, cat1, name1, cat2, name2, attrs, vals):
        table = "web_connections"
        dt = datetime.datetime.now()
        cat, name = esc(cat, name)
        attrstr = cls.sql_filter_list(attrs)
        oldvalue = None
        alu = dict(izip(attrs, vals))
        evidbase = "ev.%d-" % uuid("event")
        idx = 0

        events = []
        updates = []

        for attr, oldvalue in do("""
            SELECT attr, value FROM `%s` WHERE 
            category1 = "%s" AND name1 = "%s" AND
            category2 = "%s" AND name2 = "%s" AND
            attr IN %s LIMIT 1
        """ % (table, cat1, name1, cat2, name2, attrstr)):
            evid = evidbase + str(idx)
            idx += 1
            newvalue = alu[attr]
            event = (evid, "odinlake", dt, "edit", "event", "", cat1, name1,
                     cat2, name2, attr, oldvalue, newvalue, "pending")
            update = ("featureof", cat1, name1, cat2, name2, attr, newvalue)

            events.append(event)
            updates.append(update)

        return events, updates
コード例 #3
0
ファイル: webobject.py プロジェクト: odinlake/tstp
    def edit_object(cls, cat, name, attrs, vals):
        table = "web_attributes"
        dt = datetime.datetime.now()
        cat, name = esc(cat, name)
        attrstr = cls.sql_filter_list(attrs)
        #vals = [ esc(x) for x in vals_in ]
        oldvalue = None
        alu = dict(izip(attrs, vals))
        evidbase = "ev.%d-" % uuid("event")
        idx = 0

        events = []
        updates = []

        for attr, oldvalue in do("""
            SELECT attr, value FROM `%s` WHERE 
            category = "%s" AND name = "%s" AND attr IN %s
            LIMIT 1
        """ % (table, cat, name, attrstr)):
            evid = evidbase + str(idx)
            idx += 1
            newvalue = alu[attr]
            event = (evid, "odinlake", dt, "edit", "event", "", 
                cat, name, "", "", attr, oldvalue, newvalue, "pending")
            update = (cat, name, attr, newvalue)
            obj = (cat, name)

            events.append(event)
            updates.append(update)

        evfields = [
            "eventid",
            "userid",
            "entrytime",
            "action",
            "category",
            "refcategory",
            "category1",
            "name1",
            "category2", 
            "name2",
            "field", 
            "oldvalue", 
            "newvalue",
            "eventstate",
        ]
        fstr = ", ".join('`%s`' % s for s in evfields)
        vstr = ", ".join("%s" for s in evfields)
        do("REPLACE INTO `web_events` (%s) values (%s)" % (fstr, vstr), events)

        cls.commit_updates(updates)
コード例 #4
0
ファイル: webobject.py プロジェクト: odinlake/tstp
    def edit_object(cls, cat, name, attrs, vals):
        table = "web_attributes"
        dt = datetime.datetime.now()
        cat, name = esc(cat, name)
        attrstr = cls.sql_filter_list(attrs)
        #vals = [ esc(x) for x in vals_in ]
        oldvalue = None
        alu = dict(izip(attrs, vals))
        evidbase = "ev.%d-" % uuid("event")
        idx = 0

        events = []
        updates = []

        for attr, oldvalue in do("""
            SELECT attr, value FROM `%s` WHERE 
            category = "%s" AND name = "%s" AND attr IN %s
            LIMIT 1
        """ % (table, cat, name, attrstr)):
            evid = evidbase + str(idx)
            idx += 1
            newvalue = alu[attr]
            event = (evid, "odinlake", dt, "edit", "event", "", cat, name, "",
                     "", attr, oldvalue, newvalue, "pending")
            update = (cat, name, attr, newvalue)
            obj = (cat, name)

            events.append(event)
            updates.append(update)

        evfields = [
            "eventid",
            "userid",
            "entrytime",
            "action",
            "category",
            "refcategory",
            "category1",
            "name1",
            "category2",
            "name2",
            "field",
            "oldvalue",
            "newvalue",
            "eventstate",
        ]
        fstr = ", ".join('`%s`' % s for s in evfields)
        vstr = ", ".join("%s" for s in evfields)
        do("REPLACE INTO `web_events` (%s) values (%s)" % (fstr, vstr), events)

        cls.commit_updates(updates)
コード例 #5
0
ファイル: webobject.py プロジェクト: odinlake/tstp
    def commit_many(cls, events):
        """
        Commit a batch of unsaved events. This will update
        objects and insert events for the updates.
        """
        evidbase = "ev.%d-" % uuid("event")
        idx = 0
        catmap = {
            ('story', ''): Story,
            ('theme', ''): Theme,
            ('story', 'theme'): StoryTheme,
        }
        klassmap = { klass: set() for klass in catmap.values() }
        klassevmap = { klass: [] for klass in catmap.values() }
        objmap = {}

        #: find previous object names for all classes
        for event in events:
            klass = catmap[(event.category1, event.category2)]
            klassmap[klass].add((event.name1, event.name2))

        #: batch load objects for every class
        for klass, items in klassmap.iteritems():
            if "name2" in klass.fields:
                name1s = set( x[0] for x in items )
                name2s = set( x[1] for x in items )
                for obj in klass.load(name1s, name2s):
                    objmap[(klass, obj.name1, obj.name2)] = obj
            elif "name" in klass.fields:
                name1s = set( x[0] for x in items )
                for obj in klass.load(name1s):
                    objmap[(klass, obj.name, None)] = obj
            else:
                raise ValueError, "Unknown object type"

        #: fill in missing info on event: id and old-value
        for event in events:
            event.eventid = evidbase + str(idx)
            idx += 1
            klass = catmap[(event.category1, event.category2)]
            oldobject = objmap.get((klass, event.name1, event.name2), None)

            if oldobject:
                event.action = "edit"
                event.oldvalue = getattr(oldobject, event.field)
            else:
                event.action = "insert"
                event.oldvalue = ""

            klassevmap[klass].append(event)

        for klass, events in klassevmap.iteritems():
            updates = []

            for event in events:
                if 'name2' in klass.fields:
                    updates.append([
                        event.refcategory,
                        event.category1,
                        event.name1,
                        event.category2,
                        event.name2,
                        event.field,
                        event.newvalue,
                    ])
                else:
                    updates.append([
                        event.category1,
                        event.name1,
                        event.field,
                        event.newvalue,
                    ])
    
            if events:
                cls.write_many(events)
                klass.commit_updates(updates)
コード例 #6
0
ファイル: webobject.py プロジェクト: odinlake/tstp
    def commit_many(cls, events):
        """
        Commit a batch of unsaved events. This will update
        objects and insert events for the updates.
        """
        evidbase = "ev.%d-" % uuid("event")
        idx = 0
        catmap = {
            ('story', ''): Story,
            ('theme', ''): Theme,
            ('story', 'theme'): StoryTheme,
        }
        klassmap = {klass: set() for klass in catmap.values()}
        klassevmap = {klass: [] for klass in catmap.values()}
        objmap = {}

        #: find previous object names for all classes
        for event in events:
            klass = catmap[(event.category1, event.category2)]
            klassmap[klass].add((event.name1, event.name2))

        #: batch load objects for every class
        for klass, items in klassmap.iteritems():
            if "name2" in klass.fields:
                name1s = set(x[0] for x in items)
                name2s = set(x[1] for x in items)
                for obj in klass.load(name1s, name2s):
                    objmap[(klass, obj.name1, obj.name2)] = obj
            elif "name" in klass.fields:
                name1s = set(x[0] for x in items)
                for obj in klass.load(name1s):
                    objmap[(klass, obj.name, None)] = obj
            else:
                raise ValueError, "Unknown object type"

        #: fill in missing info on event: id and old-value
        for event in events:
            event.eventid = evidbase + str(idx)
            idx += 1
            klass = catmap[(event.category1, event.category2)]
            oldobject = objmap.get((klass, event.name1, event.name2), None)

            if oldobject:
                event.action = "edit"
                event.oldvalue = getattr(oldobject, event.field)
            else:
                event.action = "insert"
                event.oldvalue = ""

            klassevmap[klass].append(event)

        for klass, events in klassevmap.iteritems():
            updates = []

            for event in events:
                if 'name2' in klass.fields:
                    updates.append([
                        event.refcategory,
                        event.category1,
                        event.name1,
                        event.category2,
                        event.name2,
                        event.field,
                        event.newvalue,
                    ])
                else:
                    updates.append([
                        event.category1,
                        event.name1,
                        event.field,
                        event.newvalue,
                    ])

            if events:
                cls.write_many(events)
                klass.commit_updates(updates)