def save_avatar(hash, avatar_data): q = models.AvatarModel.all(keys_only=True) q.filter("hash = ", hash) r = q.fetch(1) if len(r) == 0: avatar_key = models.avatarmodel_key(hash) kwds = dict(hash=hash, content=avatar_data) models.AvatarModel.get_or_insert(avatar_key.name(), **kwds)
def get(self): hash = self.request.get('h') if hash == '': self.response.set_status(400, 'need hash parameter') return obj = models.AvatarModel.get(models.avatarmodel_key(hash)) if not obj: self.response.set_status(400, 'avatar not found') return size = self.request.get('s') if size == '' or size == '64': self.set_caching_headers(MAX_AGE_SECONDS, public=True) self.response.headers['Content-Type'] = 'image/jpeg' self.response.out.write(obj.content) return self.response.set_status(400, 'size %s not supported' % size)