Exemplo n.º 1
0
    def update_item(self, id, item_changes):
        """Update an item with the fields from item_changes"""

        if id.name == 'exchange_id':
            itemid = id.attr['id']
            if id.attr.has_key('changekey'):
                changekey = id.attr['changekey']
            else:
                raise ValueError("Changekey is needed to updatea an item")
        else:
            raise ValueError("Unknown item %s" % str(id))

        ewsitem = Erebus2EWSUpdate(item_changes).run()
        xmlitem = cnode2xml(ewsitem)
        xmlitem = ET.tostring(xmlitem)

        up = self.query.update_item(itemid, changekey, xmlitem)
        return up
Exemplo n.º 2
0
    def create_item(self, item):
        if not item.search('event'):
            return

        ewsitem = Erebus2EWSVisitor(item).run()
        xml = cnode2xml(ewsitem)

        print ToStringVisitor(with_types=True).visit(ewsitem)
        tmpnam= os.tmpnam() + '.xml'
        print "Writing query to " + tmpnam
        f = open(tmpnam,'w')
        f.write(ET.tostring(xml))
        f.close()

        res = self.query.create_items(ET.tostring(xml))
        cn = xml2cnode(ET.XML(res))
        StripNamespaceVisitor().visit(cn)

        eid = CNode('exchange_id')
        itemid = cn.search('ItemId')
        eid.attr['id'] = itemid.attr['Id']
        eid.attr['changekey'] = itemid.attr['ChangeKey']

        return eid