def get(self, key):
     test = db.get(key)
     if str(test.kind()).__eq__("RealmKeys"):
         realm = test
         if not realm:
             self.error(404)
         newupload = UploadRequestKeys()
         newupload.realm_key = realm
         newupload.put()
         result = dict(type="blob", upload_url=str(self.request.url).replace(key, str(newupload.key())))
         json = simplejson.JSONEncoder().encode(result)
         self.response.headers["Content-Type"] = "application/json"
         self.response.out.write(json)
     elif str(test.kind()).__eq__("UploadRequestKeys"):
         url = self.request.url
         context = {"type": "blob", "url": url}
         path = os.path.join(os.path.dirname(__file__), "templates", "upload_form.html")
         # render the template with the provided context
         self.response.out.write(template.render(path, context))
    def post(self, key):
        checkkey = UploadRequestKeys.get(key)
        if not checkkey:
            self.error(404)
        if checkkey.expire_date < datetime.now():
            self.error(404)
        img = self.request.get("img")
        # if we don't have image data we'll quit now
        if not img:
            return None
        try:
            width = int(self.request.get("width"))
            hight = int(self.request.get("height"))
        except ValueError:
            image_content = img
        else:
            image_content = images.resize(img, width, height)

        original_content = img

        thumb_content = images.resize(img, 100, 100)

        image = Image()

        image.image = db.Blob(image_content)

        image.original = db.Blob(original_content)
        image.thumb = db.Blob(thumb_content)
        image.user = users.get_current_user()
        image.realm = RealmKeys.get(checkkey.realm_key)
        image.put()
        checkkey.delete()
        # self.response.out.write(simplejson.dumps({'img_url'::}))
        context = {
            "image": True,
            "img_url": "http://org-images.appspot.com/i/img?id=%s" % image.key(),
            "thumb_url": "http://org-images.appspot.com/i/thumb?id=%s" % image.key(),
        }
        path = os.path.join(os.path.dirname(__file__), "templates", "show_links.html")
        # render the template with the provided context
        self.response.out.write(template.render(path, context))
 def get(self):
     allkeys = UploadRequestKeys.all()
     for key in allkeys:
         if not key.expire_date > datatime.now():
             key.delete()