def sys_info(): if account() < 0: uname = platform.uname() info = flask.__version__ return render_template('admin/sys_info.html', uname=uname, info=info) else: return redirect(url_for('login'))
def modify_art(): if account() < 0: if request.method == 'POST': id = request.form.get('id') cate_id = request.form.get('cate_id') art_name = request.form.get('art_name') describe = request.form.get('describe') content = request.form.get('content') art = Article.query.filter(Article.id == id).first() art.cate_id = cate_id art.art_name = art_name art.describe = describe art.content = content art.author = session.get('user_id') db.session.commit() return 'ok' else: id = request.args.get('id') art = Article.query.filter(Article.id == id).first() cate = [] categories = all_cate() for c in categories: if c.parent_id == 0: c.cate_name = '|--' + c.cate_name else: c.cate_name = '|------' + c.cate_name cate.append(c) return render_template('admin/modify_art.html', cate=cate, art=art) else: return redirect(url_for('login'))
def add_art(): if account() < 0: if request.method == 'POST': cate_id = request.form.get('cate_id') art_name = request.form.get('art_name') describe = request.form.get('describe') content = request.form.get('content') article = Article(cate_id=cate_id, art_name=art_name, describe=describe, content=content, author=session.get('user_id')) db.session.add(article) db.session.commit() return 'ok' else: cate = [] categories = Category.query.all() for c in categories: if c.parent_id == 0: c.cate_name = '|--' + c.cate_name cate.append(c) for s in categories: if s.parent_id == c.id: s.cate_name = '|------' + s.cate_name cate.append(s) return render_template('admin/add_art.html', cate=cate) else: return redirect(url_for('login'))
def add_cate(): if account() < 0: name = request.form.get('name') pid = request.form.get('pid') leave = request.form.get('leave') category = Category(cate_name=name, parent_id=pid, leave=leave) db.session.add(category) db.session.commit() return 'ok' else: return redirect(url_for('login'))
def del_user(): if account() < 0: id = request.form.get('id') user = User.query.filter(User.id == id).first() if user: db.session.delete(user) db.session.commit() return 'ok' else: return 'no' else: return redirect(url_for('login'))
def mar_comment(): if account() < 0: id = request.args.get('id') art_name = Article.query.filter(Article.id == id).first().art_name comments = Comment.query.filter(Comment.art_id == id).all() users = all_user() return render_template('admin/comment.html', comments=comments, art_name=art_name, users=users) else: return redirect(url_for('login'))
def del_art(): if account() < 0: id = request.form.get('id') article = Article.query.filter(Article.id == id).first() if category: db.session.delete(article) db.session.commit() return 'ok' else: return 'no' else: return redirect(url_for('login'))
def del_cate(): if account() < 0: id = request.form.get('id') category = Category.query.filter(Category.id == id).first() if category: db.session.delete(category) db.session.commit() return 'ok' else: return 'no' else: return redirect(url_for('login'))
def article(): if account() < 0: categories = all_cate() articles = all_art() users = all_user() for art in articles: for cate in categories: if art.cate_id == cate.id: art.cate_name = cate.cate_name return render_template('admin/article.html', articles=articles, users=users) else: return redirect(url_for('login'))
def ch_cate(): if account() < 0: id = request.form.get('id') name = request.form.get('name') leave = request.form.get('leave') category = Category.query.filter(Category.id == id).first() if category: category.cate_name = name category.leave = leave db.session.commit() return 'ok' else: return 'no' else: return redirect(url_for('login'))
def del_comment(): if account() < 0: if request.method == 'POST': id = request.form.get('id') comment = Comment.query.filter(Comment.id == id).first() if comment: db.session.delete(comment) db.session.commit() return 'ok' else: return 'no' else: logout() return redirect(url_for('login')) else: return redirect(url_for('login'))
def comment(): if request.method == 'GET': id = request.args.get('id') users = all_user() comments = Comment.query.filter(Comment.art_id == id).all() return render_template('comment.html', comments=comments, users=users) else: if account() < 0: id = request.form.get('id') content = request.form.get('content') comment = Comment(art_id=id, content=content, user=session.get('user_id')) db.session.add(comment) db.session.commit() return 'ok' else: return 'error'
def category(): if account() < 0: data = [] par = [] ch = [] res = all_cate() for r in res: if r.parent_id == 0: par.append(r) for x in res: if x.parent_id == r.id: ch.append(x) par.append(ch) ch = [] if par: data.append(par) par = [] return render_template('admin/category.html', data=data) else: return redirect(url_for('login'))
def mar_user(): if account() < 0: users = all_user() return render_template('admin/user.html', users=users) else: return redirect(url_for('login'))
def admin(): if account() < 0: return render_template('admin.html') else: # return render_template('admin.html') return redirect(url_for('login'))