def addPost(): if request.method == 'POST': title = request.form['title'] description = request.form['description'] PostService.add('', title, description) return redirect(url_for("admin"))
def delete(): if request.method == 'POST': data = request.json print(data) try: PostService.delete_post(data['post_id']) CommentService.delete_comments(data['post_id']) except Exception as e: print(e) return json.dumps({'has_error':True, 'message':"删除错误"}) return jsonify(success=True, message="删除成功" )
def admin(): if request.method == 'POST': title = request.form['title'] description = request.form['description'] ids = request.form['id'] PostService.update('', ids, title, description) return redirect(url_for("admin")) else: posts = PostService.getAll('') title = 'Admin' return render_template('admin.html', title=title, posts=posts)
def show_posts(page = 1): #posts = PostService.get_posts() #posts, nav = PostService.get_posts_paginate(page, POSTS_PER_PAGE, False) #return render_template('admin/posts.html', posts = posts, nav=nav, username=session['admin_uid']) # 实现分页 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_BACK) pager = generate_page(PostService.get_posts_count(), POSTS_PER_PAGE_BACK, int(page)) # 超出页面, if int(page)>pager['sumPage'] and pager['sumPage']!=0: abort(404) #comCount = [CommentService.get_comments_count(post['id']) for post in postList] return render_template('admin/posts.html', posts=postList, pager=pager)
def update_post(id): post = PostService.get_one(id) print(post) form = PostForm(title=post.get('title'), content=post.get('content')) if request.method == 'GET': return render_template('admin/update.html', form=form, post = post) title = request.form['title'] content = request.form['content'] dic = {'title':title, 'content':content} try: post= PostService.update_post(id, dic) print("success") flash('update success') except: flash('update failed') return redirect(url_for('admin.show_posts'))
def add_post(): if request.method == 'GET': return render_template('admin/add_post.html') title = request.form['title'] content = request.form['content'] tags = request.form['tags'] tagsList = [item.strip() for item in tags.split(',')] try: post = PostService.add_post(title, content, tagsList) flash('add success') print('success') except: flash('add failed') return render_template('admin/index.html')
def post(id): post = PostService.get_one(id) comment = CommentService.get_comments(id) return render_template('admin/posts.html', post=post, comment=comment)
def info(): title = "Blog" posts = PostService.getAll('') return render_template('news.html', title=title, posts=posts)
def removePost(): if request.method == 'POST': PostService.remove('', request.form['id']) return redirect(url_for("admin"))