Esempio n. 1
0
File: views.py Progetto: piranha/piu
def new():
    if not request.POST.get('data'):
        abort(400, "You have to supply 'data' field")

    data = dec(request.POST['data'])
    if not data:
        abort(400, "Empty 'data' field")

    if SPAMRE.search(data):
        abort(402, 'Wanna spam? Pay me money! ;)')

    lexer = request.POST.get('lexer', 'guess')
    item = store.new()
    paste(item, data, lexer)
    return redirect('/%s/' % item.id, 303)
Esempio n. 2
0
File: views.py Progetto: piranha/piu
def new():
    if not request.POST.get('data'):
        abort(400, "You have to supply 'data' field")

    data = dec(request.POST['data'])
    if not data:
        abort(400, "Empty 'data' field")

    if SPAMRE.search(data):
        abort(402, 'Wanna spam? Pay me money! ;)')

    lexer = request.POST.get('lexer', 'guess')
    item = store.new()
    paste(item, data, lexer)
    return redirect('/%s/' % item.id, 303)
Esempio n. 3
0
File: views.py Progetto: piranha/piu
def edit(id):
    try:
        item = store[int(id)]
    except (ValueError, KeyError):
        return redirect('/', 302)

    owner = bool(request.get_cookie('edit-%s' % id, secret=SECRET))
    if not owner:
        return redirect('/%s/' % id, 302)

    if request.method == 'POST':
        data = dec(request.POST.get('data'))
        lexer = request.POST.get('lexer', 'guess')
        paste(item, data, lexer)
        return redirect('/%s/' % id, 302)

    return template('index', data=item['raw'], id=id,
                    deflexer=item['lexer'], lexers=lexerlist())
Esempio n. 4
0
File: views.py Progetto: piranha/piu
def edit(id):
    try:
        item = store[int(id)]
    except (ValueError, KeyError):
        return redirect('/', 302)

    owner = bool(request.get_cookie('edit-%s' % id, secret=SECRET))
    if not owner:
        return redirect('/%s/' % id, 302)

    if request.method == 'POST':
        data = dec(request.POST.get('data'))
        lexer = request.POST.get('lexer', 'guess')
        paste(item, data, lexer)
        return redirect('/%s/' % id, 302)

    return template('index',
                    data=item['raw'],
                    id=id,
                    deflexer=item['lexer'],
                    lexers=lexerlist())