Exemplo n.º 1
0
def preview_form(environ, start_response):
    req = webob.Request(environ)  
    meta = {
        'title': req.POST['title'].replace(':', '.'),
        'subtitle': req.POST['subtitle'].replace(':', '.'),
        'byline': req.POST['byline'].replace(':', '.')}
    lines = [''] + req.POST['text'].split('\r\n')
    song = Song(lines, meta)

    if req.POST.get('action') == 'Save':
        id = title_to_id(req.POST['title'])
        Songs().write(id, song)
        start_response("302 Found", [('Location', '/d/songs/' + id)])
        return []
    else:
        start_response("200 OK", [('Content-type', 'text/html')])
        return [song.get_html()]
Exemplo n.º 2
0
def preview_text(environ, start_response):
    song = Song(read_request_body(environ))
    start_response("200 OK", [('Content-type', 'text/html')])
    return [song.get_html()]