def get(self): # Access the Google Documents List API. client = gdata.docs.client.DocsClient(source=oauth2.Config.APP_PLACE) client.ssl = True # This is the token instantiated in the first section. client = (oauth2.session.token).authorize(client) # self.response.out.write("Creation Page<br> ") # circle = gdata.data.MediaSource(content_type="image/png", file_name="PCScreen.png") # client.update_resource(layer1entry, media=circle) documents_feed = client.get_all_resources(uri="/feeds/default/private/full/-/folder") download_doc_feed = client.get_resources() mapb = True for entry in documents_feed: if entry.title.text == "Map": mapb = False map = entry break if mapb: # self.response.out.write("In mapb!") always triggers col = Resource("folder", "Map") map = client.create_resource(col) mapfeed = client.get_all_resources(uri=map.content.src) l1b = True l2b = True for entry in mapfeed: if entry.title.text == "Layer1": l1b = False layer1entry = entry link = entry.get_resumable_edit_media_link() elif entry.title.text == "Layer2": l2b = False layer2entry = entry # elif entry.title.text == 'PC Screen' : #testing purposes, never got this working if l1b: layer1 = Resource(type="drawing", title="Layer1") layer1entry = client.create_resource(layer1, collection=map) if l2b: layer2 = Resource(type="drawing", title="Layer2") layer2entry = client.create_resource(layer2, collection=map) # Putting this info together... # 1. Import the template importedfile = templ() temp = Template(importedfile) # 2. Generate what we want to substute in layer1sub = ( " <img id = 'incoming' alt = '" + layer1entry.content.src + "' src = '" + layer1entry.content.src + "'>" ) # 3. get the substituted version output = temp.substitute(layer1=layer1sub) # 4. print out the result self.response.out.write(output)
def DrawRect(self, *args): client = gdata.docs.client.DocsClient(source=oauth2.Config.APP_PLACE) client.ssl = True # This is the token instantiated in the oauth section. client = (oauth2.session.token).authorize(client) folders_feed = client.get_all_resources(uri='/feeds/default/private/full/-/folder') x = args[0] y = args[1] width = args[2] height = args[3] #Grab layer1 for entry in folders_feed : if entry.title.text == 'Map' : map = entry break mapfeed = client.get_all_resources(uri=map.content.src) for entry in mapfeed: if entry.title.text == "Layer1" : layer1entry = entry if entry.title.text == "Layer2" : layer2entry = entry link = entry.get_resumable_edit_media_link() #Optional: download layer1 as an SVG content = client.download_resource_to_memory(layer1entry) oldcontent = content #Replace it's content with our content #layer = layer1entry.content.src layer = '<svg xmlns:ns0="http://www.w3.org/2005/Atom" width="800" height="600"><g id="box_0"><rect x="' + str(x) + '" y="' + str(y) + '" width="' + str(width) + '" height="' + str(height) + '" fill="blue" stroke="blue" stroke-width="4"></rect></g></svg>' #SVG("rect", x=10, y=10, width=60, height=60, id='star') #Stated that strings lack the attribue "_become_child" #g.save("tmp.svg") #Reupload #layer2entry.content.src = layer1entry.content.src #client.update(layer2entry) #return (layer1entry.get_elements())[24].to_string() + (layer1entry.get_elements())[25].to_string() #response = client.put(link, layer1entry.to_string()) href = "https://docs.google.com/feeds" + (link.href)[51:] #/feeds/upload/create-session/default/private/full/" myHeaders = {"GData-Version" : 3, "X-Upload-Content-Length" : 0, "Content-Type" : "image/svg+xml", "Authorization" : oauth2.session.token.access_token} #"X-Upload-Content-Length" : 1000, "X-Upload-Content-Type" : "application/atom+xml" } payload2 = '<?xml version="1.0" encoding="UTF-8"?>' + '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007">' + '<title>Legal Contract</title>' + '</entry>' #'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' + '<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" /></svg>' try : result = urlfetch.fetch(url = link.href, payload = payload2, #'<?xml version="1.0" encoding="utf-8"?><atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:scope ="http://schemas.google.com/acl/2007:scope" xmlns:apps="http://schemas.google.com/apps/2006"></atom:entry>', #payload = layer, method = urlfetch.POST, headers = myHeaders) except urllib2.URLError, e: return e
def get(self): # Access the Google Documents List API. client = gdata.docs.client.DocsClient(source=oauth2.Config.APP_PLACE) client.ssl = True # This is the token instantiated in the first section. client = (oauth2.session.token).authorize(client) #self.response.out.write("Creation Page<br> ") #circle = gdata.data.MediaSource(content_type="image/png", file_name="PCScreen.png") #client.update_resource(layer1entry, media=circle) documents_feed = client.get_all_resources(uri='/feeds/default/private/full/-/folder') download_doc_feed = client.get_resources() mapb = True for entry in documents_feed : if entry.title.text == 'Map' : mapb = False map = entry break if mapb : #self.response.out.write("In mapb!") always triggers col = Resource('folder', 'Map') map = client.create_resource(col) mapfeed = client.get_all_resources(uri=map.content.src) l1b = True l2b = True for entry in mapfeed: if entry.title.text == "Layer1" : l1b = False layer1entry = entry link = entry.get_resumable_edit_media_link() elif entry.title.text == "Layer2" : l2b = False layer2entry = entry #elif entry.title.text == 'PC Screen' : #testing purposes, never got this working if l1b : layer1 = Resource(type='drawing', title='Layer1') layer1entry = client.create_resource(layer1, collection=map) if l2b : layer2 = Resource(type='drawing', title='Layer2') layer2entry = client.create_resource(layer2, collection=map) self.writeJavascript() self.response.out.write('<body>\n') self.response.out.write("<div id = 'top' style = 'position:absolute;top:0px;left:0px;height:100%;width:100%'>\n") self.response.out.write(" <div style = 'position:absolute;top:0px;width:100%'>\n") #self.response.out.write(" <img id = " + '"incoming2"' + " alt = '" + layer2entry.content.src + "' src = '" + layer2entry.content.src +"'>") self.response.out.write(" </div>") self.response.out.write(" <div style = 'position:absolute;top:0px;width:100%'>\n") #self.response.out.write(" <img id = " + '"incoming"' + " alt = '" + layer1entry.content.src + "' src = '" + layer1entry.content.src +"'>") #self.response.out.write( layer1MediaContent.file_size ) self.response.out.write(" </div>\n") self.response.out.write(" <div id = 'drawSpace' style = 'position:absolute;top:0px;width:800px;height:600px;border-style:double;border-width:5px;margin-left:auto;margin-right:auto;'>\n") self.response.out.write(" </div>\n") self.response.out.write(" <span id='theplace'>\n") self.response.out.write(" " + layer1entry.content.to_string() + "\n") self.response.out.write(" </span>\n") self.response.out.write(" </div>\n") self.response.out.write("</div>\n\n") self.writeBottom()