Example #1
0
def edit_action(request, key):
    action = Action.get(key)
    if not action:
        return redirect('/news/admin/actions/all/')
    form = ActionForm(instance=action)
    if request.method == 'POST' and form.validate(request.form):
        form.save()
        return redirect('/news/admin/actions/all/')
    images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % key)
    return render_to_response(
        'news/admin/actions_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget(),
         'action':action})
Example #2
0
def add_action_image(request, action_key):
    action = Action.get(action_key)
    if not action:
        return redirect('/news/admin/actions/all/')
    form = ActionForm(instance=action)
    images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % action_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 = ActionImage()
            news_image.title = title
            news_image.action = action
            news_image.image = thumb_img
            news_image.size = '%sx%s' % (width, height)
            news_image.put()
            return redirect('/news/admin/actions/edit/%s/' % action_key)
    return render_to_response('news/admin/actions_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget()})
Example #3
0
def delete_action(request, key):
    action = Action.get(key)
    if action:
        action.delete()
    return redirect('/news/admin/actions/all/')