Beispiel #1
0
def add_image_to_new_action(request):
    action = Action(title=u'Новая  акция', discount=0.0)
    action.put()
    action_key = action.key()
    form = ActionForm(instance=action)
    images_form = ActionImageForm(action='/news/admin/actions/add_image_action/')
    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()
            images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % action_key)
            return redirect('/news/admin/actions/edit/%s/' % action_key)
    images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % action_key)
    return render_to_response('news/admin/actions_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget()})
Beispiel #2
0
def show_all(request):
    actions = Action.all().order('-add_time')
    paginator = Paginator(actions, 25)
    try:
        page = int(request.args.get('page',1))
    except ValueError:
        page = 1

    try:
        actions = paginator.page(page)
    except (EmptyPage, InvalidPage):
        actions = paginator.page(paginator.num_pages())
    return render_to_response('news/admin/actions_all.html', {'actions':actions})
Beispiel #3
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})
Beispiel #4
0
def show_action(request, id):
    action = Action.get_by_id(id)
    if action is None:
        return redirect('/news/')
    return render_to_response('news/show_action.html', {'action':action})
Beispiel #5
0
def index(request):
    newss = News.all().order('-add_time')
    actions = Action.all().order('-add_time')
    return render_to_response('news/index.html', {'newss': newss, 'actions':actions})
Beispiel #6
0
def delete_action(request, key):
    action = Action.get(key)
    if action:
        action.delete()
    return redirect('/news/admin/actions/all/')