def reply_edit(reply_id, page): reply = Reply.query.get(reply_id) if session.get('user_id') == reply.author.id or session.get( 'user_id') == 1: if request.method == 'POST': if not session.get('user_id'): abort(401) if '@' in request.form['reply[content]']: reply_content = mentionfilter(request.form['reply[content]']) else: reply_content = request.form['reply[content]'] reply_content = textformat(reply_content) reply_content = markdown(reply_content) reply = Reply.query.get(reply_id) reply.text = reply_content reply.text_origin = request.form['reply[content]'] db.session.commit() return redirect( url_for('topic.topic_view', topic_id=reply.topic.id, page=page) + '#replys') return render_template('reply_edit.html', reply=reply, topic=reply.topic, page=page) else: abort(401)
def topic_edit(topic_id): topic = Topic.query.get(topic_id) if session.get('user_id') == topic.author.id or session.get('user_id') == 1: if request.method == 'POST': if not session.get('user_id'): abort(401) if request.form['title'] == '': g.error = u'请输入主题标题!' render_template('topic_edit.html', topic=topic) elif request.form['text'] == '': g.error = u'请输入主题内容!' render_template('topic_edit.html', topic=topic) else: topic = Topic.query.get(topic_id) if '@' in request.form['text']: text = mentionfilter(request.form['text']) else: text = request.form['text'] text = textformat(text) text = markdown(text) topic.title = request.form['title'] topic.text = text topic.text_origin = request.form['text'] topic.date = int(time.time()) db.session.commit() flash(u'修改成功!') return redirect(url_for('topic.topic_view',topic_id=topic_id)) return render_template('topic_edit.html', topic=topic) else: abort(401)
def node_add(): if session['user_id'] != 1: abort(401) if request.method == 'POST': if session['user_id'] != 1: abort(401) nodeclass = Nodeclass.query.filter_by(name=request.form['nodeclass']).first() if not nodeclass: nodeclass = Nodeclass(request.form['nodeclass']) db.session.add(nodeclass) db.session.commit() nodeclass = Nodeclass.query.filter_by(name=request.form['nodeclass']).first() if request.form['nodename'] == '' or request.form['nodesite'] == '' or request.form['nodeclass'] == '': error = u'请填写完整信息!' return render_template('node_add.html', error=error) elif Node.query.filter_by(name=request.form['nodename']).first() is not None: error = u'节点名称已存在!' return render_template('node_add.html', error=error) elif Node.query.filter_by(site=request.form['nodesite']).first() is not None: error = u'节点地址已存在!' return render_template('node_add.html', error=error) else: description = textformat(request.form['description']) description = markdown(description) node = Node(name=request.form['nodename'], site=request.form['nodesite'], description=description, description_origin=request.form['description'], nodeclass=nodeclass) db.session.add(node) db.session.commit() flash(u'添加成功!') return redirect(url_for('topic.tab_view')) return render_template('node_add.html')
def add_reply(topic_id): if not session.get('user_id'): abort(401) if g.user.time < 5: g.error = u'抱歉,您的时间不足5分钟!' return redirect(url_for('topic.topic_view', topic_id=topic_id) + "#replyend") if request.form['reply[content]'] == '': g.error = u'抱歉,您的时间不足5分钟!' return redirect(url_for('topic.topic_view', topic_id=topic_id) + "#replyend") topic = Topic.query.get(topic_id) if topic.replys is not None: numbered = len(topic.replys.all()) else: numbered = 0 page_obj = topic.replys.paginate(1, per_page=config.RE_PER_PAGE) if page_obj.pages == 0: page = 1 elif len(topic.replys.all()) % config.RE_PER_PAGE == 0: page = page_obj.pages + 1 else: page = page_obj.pages if '@' in request.form['reply[content]']: reply_content = mentionfilter(request.form['reply[content]']) else: reply_content = request.form['reply[content]'] reply_content = textformat(reply_content) reply_content = markdown(reply_content) reply = Reply(topic=topic, author=g.user, text=reply_content, text_origin=request.form['reply[content]'], number=numbered + 1) g.user.time -= 5 topic.author.time += 5 topic.last_reply_date = int(time.time()) topic.reply_count += 1 for reader in topic.readers: topic.readers.remove(reader) db.session.add(reply) db.session.commit() t = int(time.time()) if session['user_id'] != topic.author.id: bill = Bill(author=g.user,time=5,type=3,date=t,reply=reply,user_id=topic.author.id,balance=g.user.time) bill2 = Bill(author=topic.author,time=5,type=5,date=t,reply=reply,user_id=g.user.id,balance=topic.author.time) db.session.add(bill) db.session.add(bill2) db.session.commit() notify = Notify(author=topic.author, topic=topic, reply=reply, type=1) db.session.add(notify) db.session.commit() if '@' in request.form['reply[content]']: content = request.form['reply[content]'].replace('\n','') usernames = list(set(mentions(content))) for username in usernames: author = User.query.filter_by(name=username).first() if author.id != topic.author.id and author.id != g.user.id: notify = Notify(author, topic, reply=reply, type=2) db.session.add(notify) db.session.commit() return redirect(url_for('topic.topic_view', topic_id=topic_id, page=page) + "#replyend")
def topic_add(nodesite): if not session.get('user_id'): return redirect(url_for('account.login')) node = Node.query.filter_by(site=nodesite).first() if request.method == 'POST': if g.user.time < 20: flash(u'时间不足20分钟!') return redirect(url_for('topic.index')) node = Node.query.filter_by(site=nodesite).first() if request.form['title'] == '': g.error = u'请输入主题标题!' render_template('topic_add.html', node=node) elif request.form['text'] == '': g.error = u'请输入主题内容!' render_template('topic_add.html', node=node) else: if '@' in request.form['text']: text = mentionfilter(request.form['text']) else: text = request.form['text'] text = textformat(text) text = markdown(text) topic = Topic(author=g.user, title=request.form['title'], text=text, text_origin=request.form['text'], node=node, reply_count=0) bank = Bank.query.get(1) g.user.time -= 20 bank.time +=20 db.session.add(topic) db.session.commit() bill = Bill(author=g.user,time=20,type=2,date=int(time.time()),topic=topic,balance=g.user.time) db.session.add(bill) db.session.commit() flash(u'发布成功!') if '@' in request.form['title']: title = request.form['title'].replace('\n','') usernames = list(set(mentions(title))) for username in usernames: author = User.query.filter_by(name=username).first() if author.id != g.user.id: notify = Notify(author, topic, reply=None, type=3) db.session.add(notify) db.session.commit() if '@' in request.form['text']: text = request.form['text'].replace('\n','') usernames = list(set(mentions(text))) for username in usernames: author = User.query.filter_by(name=username).first() if author.id != g.user.id: notify = Notify(author, topic, reply=None, type=3) db.session.add(notify) db.session.commit() return redirect(url_for('topic.topic_view', topic_id=topic.id)) return render_template('topic_add.html', node=node)
def node_edit(nodesite): if session['user_id'] != 1: abort(401) node = Node.query.filter_by(site=nodesite).first() if request.method == 'POST': if request.form['nodename'] == '' or request.form['nodesite'] == '' or request.form['nodeclass'] == '': error = u'请填写完整信息!' return render_template('node_edit.html', node=node, error=error) elif request.form['nodename'] != node.name and Node.query.filter_by(name=request.form['nodename']).first() is not None: error = u'节点名称已存在!' return render_template('node_edit.html', node=node, error=error) elif request.form['nodesite'] != node.site and Node.query.filter_by(site=request.form['nodesite']).first() is not None: error = u'节点地址已存在!' return render_template('node_edit.html', node=node, error=error) else: nodeclass = Nodeclass.query.filter_by(name=request.form['nodeclass']).first() if not nodeclass: nodeclass = Nodeclass(request.form['nodeclass']) db.session.add(nodeclass) db.session.commit() nodeclass = Nodeclass.query.filter_by(name=request.form['nodeclass']).first() description = textformat(request.form['description']) description = markdown(description) header = markdown(request.form['header']) node.name = request.form['nodename'] node.site = request.form['nodesite'] node.description = description node.header = header node.description_origin = request.form['description'] node.header_origin = request.form['header'] node.style = request.form['style'] node.nodeclass = nodeclass db.session.commit() flash(u'节点修改成功!') return redirect(url_for('node.index', nodesite=nodesite)) return render_template('node_edit.html',node=node)
def reply_edit(reply_id, page): reply = Reply.query.get(reply_id) if session.get('user_id') == reply.author.id or session.get('user_id') == 1: if request.method == 'POST': if not session.get('user_id'): abort(401) if '@' in request.form['reply[content]']: reply_content = mentionfilter(request.form['reply[content]']) else: reply_content = request.form['reply[content]'] reply_content = textformat(reply_content) reply_content = markdown(reply_content) reply = Reply.query.get(reply_id) reply.text = reply_content reply.text_origin = request.form['reply[content]'] db.session.commit() return redirect(url_for('topic.topic_view', topic_id=reply.topic.id, page=page) + '#replys') return render_template('reply_edit.html', reply=reply, topic=reply.topic, page=page) else: abort(401)
def add_reply(topic_id): if not session.get('user_id'): abort(401) if g.user.time < 5: g.error = u'抱歉,您的时间不足5分钟!' return redirect( url_for('topic.topic_view', topic_id=topic_id) + "#replyend") if request.form['reply[content]'] == '': g.error = u'抱歉,您的时间不足5分钟!' return redirect( url_for('topic.topic_view', topic_id=topic_id) + "#replyend") topic = Topic.query.get(topic_id) if topic.replys is not None: numbered = len(topic.replys.all()) else: numbered = 0 page_obj = topic.replys.paginate(1, per_page=config.RE_PER_PAGE) if page_obj.pages == 0: page = 1 elif len(topic.replys.all()) % config.RE_PER_PAGE == 0: page = page_obj.pages + 1 else: page = page_obj.pages if '@' in request.form['reply[content]']: reply_content = mentionfilter(request.form['reply[content]']) else: reply_content = request.form['reply[content]'] reply_content = textformat(reply_content) reply_content = markdown(reply_content) reply = Reply(topic=topic, author=g.user, text=reply_content, text_origin=request.form['reply[content]'], number=numbered + 1) g.user.time -= 5 topic.author.time += 5 topic.last_reply_date = int(time.time()) topic.reply_count += 1 for reader in topic.readers: topic.readers.remove(reader) db.session.add(reply) db.session.commit() t = int(time.time()) if session['user_id'] != topic.author.id: bill = Bill(author=g.user, time=5, type=3, date=t, reply=reply, user_id=topic.author.id, balance=g.user.time) bill2 = Bill(author=topic.author, time=5, type=5, date=t, reply=reply, user_id=g.user.id, balance=topic.author.time) db.session.add(bill) db.session.add(bill2) db.session.commit() notify = Notify(author=topic.author, topic=topic, reply=reply, type=1) db.session.add(notify) db.session.commit() if '@' in request.form['reply[content]']: content = request.form['reply[content]'].replace('\n', '') usernames = list(set(mentions(content))) for username in usernames: author = User.query.filter_by(name=username).first() if author.id != topic.author.id and author.id != g.user.id: notify = Notify(author, topic, reply=reply, type=2) db.session.add(notify) db.session.commit() return redirect( url_for('topic.topic_view', topic_id=topic_id, page=page) + "#replyend")