def add_news_image(request, news_key): news = News.get(news_key) if not news: news = News() news.put() form = NewsForm(instance=news) images_form = NewsImageForm(action='/news/admin/news/add_image/%s/' % news.key()) if request.method == 'POST': if images_form.validate(request.form, request.files): img = images_form['image_file'] content_type = 'image/jpeg' if not images_form['title']: title = '' else: title = images_form['title'] title = title.replace('"', '"') thumb_img = ThumbImage() thumb_img.add_new_thumb(blob_img=img, thumb_size=(100, 100), content_type=content_type, title=title) if not images_form['width'] or not images_form['height']: width = height = 300 else: width = images_form['width'] height = images_form['height'] thumb_img.add_new_thumb(blob_img=img, thumb_size=(width, height), content_type=content_type, title=title) thumb_img.put() news_image = NewsImage() news_image.title = title news_image.news = news news_image.image = thumb_img news_image.size = '%sx%s' % (width, height) news_image.put() return redirect('/news/admin/news/edit/%s/' % news.key()) return render_to_response('news/admin/news_add.html', {'form':form.as_widget(), 'images_form':images_form.as_widget()})
def news_add(request): news = News(title=u'Название новости', text=u'Текст новости') news.put() return redirect('/news/admin/news/edit/%s/' % news.key())