예제 #1
0
파일: admin.py 프로젝트: gmist/f-toy
def news_edit(request, key):
    news = News.get(key)
    images_form = NewsImageForm(action='/news/admin/news/add_image/%s/' % key)
    if news is None:
        return redirect('/news/admin/news/all')
    form = NewsForm(instance=news)
    if request.method == 'POST' and form.validate(request.form):
        form.save()
        return redirect('/news/admin/news/all/')
    return render_to_response('news/admin/news_add.html',
            {'form':form.as_widget(),
             'images_form':images_form.as_widget(),
             'news':news})
예제 #2
0
파일: admin.py 프로젝트: gmist/f-toy
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()})