Exemplo n.º 1
0
def hello(request):
    try:
        name = request.cookie["name"].value
        sign = request.cookie["sign"].value
        assert name in signed_cookie and signed_cookie[name] == sign
        if request.path == "/hello":
            blog = Blog.get(name=name)
            if blog is None:
                return render_for_response(request, "hello.html", name=name)
            request.status = "303 See Other"
            request.header.append(("Location", "/hello/" + blog.id))
            return request

        files = os.listdir(os.path.join(os.getcwd(), "file"))
        blog = Blog.get(id=request.path.replace("/hello/", ""))
        blogs = Blog.get_all(name=name)
        return render_for_response(request, "hello.html", files=files, name=name, blog=blog, blogs=blogs)
    except (KeyError, AssertionError):
        request.status = "303 See Other"
        request.header.append(("Location", "/"))
        return request
Exemplo n.º 2
0
def hello(blog_id=None):
    name = request.cookie.get('name')
    sign = request.cookie.get('sign')
    if not sign or sign != app.signed_cookie.get(name):
        return redirect('/')

    if request.path == '/hello':
        blog = Blog.get(name=name)
        if blog is None:
            return render('hello.html', name=name)
        return redirect('/hello/' + blog.id)

    if blog_id.startswith('File'):
        blog = Blog(title=blog_id, content="")
        return render('hello.html', name=name, blog=blog)

    blog = Blog.get(blog_id)
    files = os.listdir(os.path.join(os.getcwd(), 'file'))
    files = ((f, quote(f).replace('%', '-')) for f in files)
    blogs = Blog.get_all(name=name)
    return render('hello.html', name=name, blog=blog, files=files, blogs=blogs)
Exemplo n.º 3
0
def hello(request):
    try:
        name = request.cookie['name'].value
        sign = request.cookie['sign'].value
        assert name in signed_cookie and signed_cookie[name] == sign
        if request.path == '/hello':
            blog = Blog.get(name=name)
            if blog is None:
                return render_for_response(request, 'hello.html', name=name)
            request.status = '303 See Other'
            request.header.append(('Location', '/hello/' + blog.id))
            return request

        files = os.listdir(os.path.join(os.getcwd(), 'file'))
        blog = Blog.get(id=request.path.replace('/hello/', ''))
        blogs = Blog.get_all(name=name)
        return render_for_response(request, 'hello.html', files=files,
                                   name=name, blog=blog, blogs=blogs)
    except (KeyError, AssertionError):
        request.status = '303 See Other'
        request.header.append(('Location', '/'))
        return request
Exemplo n.º 4
0
def update_blog(request):
    blog = Blog.get(id=request.referer[-32:])
    return render_for_response(request, "update_blog.html", blog=blog)
Exemplo n.º 5
0
def update_blog(request):
    blog = Blog.get(id=request.referer[-32:])
    return render_for_response(request, 'update_blog.html', blog=blog)
Exemplo n.º 6
0
def update_blog():
    blog = Blog.get(id=request.referer[-32:])
    return render('update_blog.html', blog=blog)