コード例 #1
0
ファイル: post.py プロジェクト: Ncare/blog_flask
def post(id):

    #cForm = CommentForm(request.form)
    post = PostService.get_one(id)


    tags = [item.name for item in post['tags']]

    try:
        comments = CommentService.get_comments(int(id))
    except Exception:
        print(Exception)

    commentCount = len(comments)

    # get pre or next page
    try:
        next = PostService.get_next_post(id)
        if next is not None:
            nextId = next.id
        else:
            nextId = None
        pre = PostService.get_pre_post(id)
        if pre is not None:
            preId = pre.id
        else:
            preId = None
    except Exception as e:
        print(e)

    # get tag

    #if request.method == "GET":
    return render_template('web/post.html', post=post, cs = comments, count = commentCount, \
            nextPostId = nextId, prePostId = preId, tags = tags)
コード例 #2
0
ファイル: post.py プロジェクト: Ncare/blog_flask
def comment():

    if request.method == 'POST':
        comment = request.json

        name = comment['name']
        email = comment['email']
        comContent = comment['comment']
        post_id = comment['post_id']

        post = PostService.get_one(post_id)

        if not post:
            return json.dumps({'has_error':True, "message":"文章不存在"})

        try:
            CommentService.add_comment(post_id=post_id, name=name, email=email, comments=comContent)
        except:
            return json.dumps({'has_error':True, "message":"存取出错"})

        return jsonify(success=True, message="评论成功", time=datetime.utcnow())
コード例 #3
0
ファイル: post.py プロジェクト: Ncare/blog_flask
def index():

    # 实现分页 1, 2, 3, 4 。。。
    page = request.args.get("page", 1)

    offset = POSTS_PER_PAGE*(int(page)-1)
    postList = PostService.get_posts_page(offset, POSTS_PER_PAGE)
    pager = generate_page(PostService.get_posts_count(), POSTS_PER_PAGE, int(page))

    # 超出页面,
    if int(page)>pager['sumPage'] and pager['sumPage']!=0:
        abort(404)

    comCount = [CommentService.get_comments_count(post['id']) for post in postList]

    postsZip = zip(postList, comCount)

    posts_recent = PostService.get_posts_recent(4, 'desc')

    return render_template('web/index.html', posts=postsZip, pager=pager, postR = posts_recent)
コード例 #4
0
ファイル: app.py プロジェクト: steventt07/Buzz
def start_service():
    service = Service()
    add_post_service = AddPostService(service)
    remove_post_service = RemovePostService(service)
    feed_service = FeedService(service)
    category_service = CategoryService(service)
    vote_service = VoteService(service)
    comment_service = CommentService(service)
    user_service = UserService(service)
    user_liked_post_service = UserLikedPostService(service)
    email_validation_service = EmailValidationService(service)

    app = falcon.API(middleware=[HandleCORS()])
    app.add_route('/add_post_to_category', add_post_service)
    app.add_route('/remove_post_from_category', remove_post_service)
    app.add_route('/feed', feed_service)
    app.add_route('/category', category_service)
    app.add_route('/vote', vote_service)
    app.add_route('/comment', comment_service)
    app.add_route('/user', user_service)
    app.add_route('/user_liked_post', user_liked_post_service)
    app.add_route('/email_validation', email_validation_service)
    return app