Ejemplo n.º 1
0
 def post(self):
     data = self.request.get("img_data")
     name = self.request.get("img_name")
     if data == "":
         logging.info("image upload missing data")
     elif name == "":
         logging.info("image upload missing name")
     else:
         image = Image()
         image.name = name
         image.data = db.Blob(data)
         image.put()
     self.redirect("/admin/?image=" + name)
Ejemplo n.º 2
0
def send_img(name, role):
    filename = IMG_PATH + name
    name = name[:-4]
    logging.debug("try to send %s" % name)
    img = Image.gql("WHERE name = :1", name).get()
    if img is not None:
        logging.info("image %s exists" % name)
        return False
    try:
        f = open(filename, 'r')
    except IOError:
        logging.info("missing file %s" % name)
        return False
    data = f.read()
    f.close()
    image = Image()
    image.name = name
    image.data = db.Blob(data)
    image.role = role
    image.put()
    logging.debug("sent ok")
    return True