Ejemplo n.º 1
0
def show_blog(id):
    blog = Blog.objects.with_id(ObjectId(id))
    if not blog:
        return jsonify(success=False, error='不存在该日志')
    if (blog.visible in [Blog.VISIBLE_LOGIN, Blog.VISIBLE_OWNER] and current_user.is_authenticated is False) \
        or (blog.visible == Blog.VISIBLE_OWNER and current_user.id != blog.author):
        return abort(403)

    # 增加观看量
    Blog.objects(id=ObjectId(id)).update(inc__view_count=1)
    # 设置上个观察者的ip
    Blog.objects(id=ObjectId(id)).update(set__last_view_ip=request.remote_addr)
    # 设置上个观看者的用户id
    Blog.objects(id=ObjectId(id)).update(set__last_view_user=current_user.id if current_user.is_active and current_user.is_anounymous is False else None)
    # 设置上次观看的时间
    Blog.objects(id=ObjectId(id)).update(set__last_view_time=now_lambda())

    prev, next = Blog.get_prev_next(unicode(blog.id), current_user)
    monthes = get_all_month()
    return render_template('home/blog_detail.html', blog=blog.as_dict(), prev=prev, next=next, monthes=monthes, tags=get_tags_cloud())
Ejemplo n.º 2
0
def test_prev_next():
    print Blog.get_prev_next('56c462de59acd1470c262e04')