def post(self): req = self.request creator = users.get_current_user().email() template_name = sanitize.remove_tags(req.get('template_name')) original_image_data = req.get('image_data') if not template_name: self.error(400) return existing_template = MemeTemplate.get_by_key_name(template_name) if existing_template: self.error(400) return (image_data, width, height) = images.create_image(original_image_data) (thumbnail_image_data, _, _) = images.create_thumbnail_image(original_image_data) meme_template = MemeTemplate( key_name=template_name, creator=creator, image_data=db.Blob(image_data), thumbnail_image_data=db.Blob(thumbnail_image_data), name=template_name, height=height, width=width) key = meme_template.put() # This should probably redirect to create meme. self.redirect('/meme?template_name=' + key.name())
def get(self): req = self.request count = int(req.get('count', 75)) if count > 100: count = 100 q = MemeTemplate.all() q.order('-last_used') cursor = req.get('cursor') if cursor: q.with_cursor(cursor) templates = [] for template in q.run(limit=count): template_data = Expando({ 'name': template.name, 'width': template.width, 'height': template.height }) templates.append(template_data) sorted_templates = sorted(templates[:], sort_templates) html = template_helper.render('view_templates.html', templates=templates, alpha_sorted_templates=sorted_templates, cursor=q.cursor) self.response.write(html)
def get(self, template_name): req = self.request meme_template = MemeTemplate.get_by_key_name(template_name) if not meme_template: self.error(404) return self.response.headers['Content-Type'] = 'image/png' self.response.headers['Cache-Control'] = 'private, max-age=3600' is_thumbnail = req.get('size') == 'thumbnail' if is_thumbnail: self.response.write(meme_template.thumbnail_image_data) else: self.response.write(meme_template.image_data)
def post(self, template_name): req = self.request template = MemeTemplate.get_by_key_name(template_name) if not template: self.error(404) return if not template.is_owner(): self.error(400) return template.delete() # Write an empty 200 response self.response.headers['Content-Type'] = 'application/json' self.response.write('{}')
def get(self): req = self.request template_name = sanitize.remove_tags(req.get('template_name')) if not template_name: self.error(400) return template = MemeTemplate.get_by_key_name(template_name) if not template: self.error(400) return is_owner = users.get_current_user().email() == template.creator html = template_helper.render('create_meme.html', name=template.name, is_owner=is_owner) self.response.write(html)
def post(self): req = self.request data_url = req.get('image_data') if not data_url: self.error(400) return bottom_text = sanitize.remove_tags(req.get('upper_text')) upper_text = sanitize.remove_tags(req.get('lower_text')) texts =[] if bottom_text: texts.append(bottom_text) if upper_text: texts.append(upper_text) text = '\n'.join(texts) encoded_image_data = DATA_URL_PATTERN.match(data_url).group(2) if encoded_image_data is None or len(encoded_image_data) == 0: self.error(400) return image_data = base64.b64decode(encoded_image_data) creator = users.get_current_user().email() listed = req.get('listed') == 'true' template_name = sanitize.remove_tags(req.get('template_name')) key = insert_meme(creator, listed, template_name, image_data, text) meme_template = MemeTemplate.get_by_key_name(template_name) if meme_template: meme_template.last_used = datetime.now() meme_template.put() data = { 'id': key.name() } self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps(data))