def add_new_thumb(request): if request.method == 'POST': gift_key = request.values.get('gift_key') gift = Gift.get(gift_key) if gift is None: return redirect('/gift/admin/edit/%s/' % gift_key) new_th_form = AddNewThumb() if request.form and new_th_form.validate(request.form, request.files): thumb = new_th_form['img'] content_type = 'image/jpeg' if gift.name: title = gift.name.replace('"', '"') else: title = '' thumb_img = ThumbImage() thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ), title=title, content_type=content_type) if not gift.thumbs.count(): thumb_img.main_gift = gift thumb_img.gift = gift thumb_img.put() return redirect('/gift/admin/edit/%s/' % gift_key) return redirect('/gift/admin/all/')
def upload_new_thumb(request): if request.method == 'POST': gift_key = request.values.get('gift_key') gift = Gift.get(gift_key) if gift is None: return redirect('/') new_th_form = AddNewThumb() if request.form and new_th_form.validate(request.form, request.files): thumb = new_th_form['img'] content_type = 'image/jpeg' if gift.name: title = gift.name.replace('"', '"') else: title = '' thumb_img = ThumbImage() thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ), title=title, content_type=content_type) thumb_img.put() gift.thumbs.append(str(thumb_img.key())) gift.put() get_gift(gift.uid, True) return redirect('/g/%s' % gift.uid) return redirect('/')