示例#1
0
    def parse_json(self):

        if self.request.method not in JSON_METHODS:
            return None

        body = self.request.body

        try:
            self.json = json.loads(body)

            blob_key = self.json.get('blob_key')
            if blob_key:
                self.blob_info = BlobInfo.get(BlobKey(blob_key))

            log = pretty_json(self.json)
            logging.info('body: {}'.format(log))

        except ValueError:
            logging.info('body: {}'.format(body))
示例#2
0
文件: views.py 项目: jsa/pore
def photo(request, entry_id, photo_n, params):
    entry = ndb.Key(PhotoEntry, int(entry_id)).get()
    if not (entry and entry.is_public()):
        raise http.Http404, "Photo %s-%s not found" % (entry_id, photo_n)

    blob_key = entry.photos[int(photo_n)]
    blob_info = BlobInfo.get(blob_key)

    if not params:
        rs = http.HttpResponse('', blob_info.content_type)
        rs[BLOB_KEY_HEADER] = blob_key
        return rs

    img = images.Image(blob_key=blob_key)
    if params:
        _apply_img_params(img, params)
    img.im_feeling_lucky()
    img_data = img.execute_transforms(output_encoding=images.JPEG)

    return http.HttpResponse(img_data, blob_info.content_type)