Exemplo n.º 1
0
def add (request):
    if request.method == 'GET':
        return render_template ('add.html')
    elif request.method == 'POST':
        post = Post (
                text=request.form.get ('message'),
                user_name=request.form.get ('name'),
                title=request.form.get ('title'),
                date = datetime.now())
        post.save ()
    return redirect ("/")
Exemplo n.º 2
0
def comment (request):
    if request.method == 'POST':
        post = Post.objects(id = request.form.get ('id')).first ()
        comment = Comment (text = request.form.get ('text'), date = datetime.now ())
        post.comments.append (comment)
        post.save ()
        return Response ()
    raise NotFound ()
Exemplo n.º 3
0
def index(request, page_id = 1):
    begin = (page_id-1) * PAGE_SIZE
    end = begin + PAGE_SIZE
    posts = Post.objects[begin:end].order_by ("-date")
    pages_total = int (math.ceil (float (Post.objects () .count ()) / PAGE_SIZE))
    return render_template('index.html', posts=posts, pages_total=pages_total, page_index=page_id)
Exemplo n.º 4
0
def comments (request):
    id = request.args['id']
    post = Post.objects (id = id).first ()
    return render_template('comments.html', comments=post.comments)