def index(): u = current_user() if u is not None: board_id = int(request.args.get('board_id', -1)) if board_id == -1: ms = Topics.all() else: ms = Topics.all(board_id=board_id) token = new_csrf_token() bs = Board.all() u = current_user() return render_template('topic/index.html', ms=ms, token=token, bs=bs, bid=board_id, user=u) else: return render_template('login.html')
def generate_fake_date(): form = dict( username='******', password='******', ) u = User.register(form) form = dict( username='******', password='******', ) u = User.register(form) # form = dict( # username='******', # password='******', # ) # u = User.register(form) form = dict(title='all') b = Board.new(form) with open('markdown_demo.md', encoding='utf8') as f: content = f.read() topic_form = dict(title='markdown demo', board_id=b.id, content=content) for i in range(10): print('begin topic <{}>'.format(i)) t = Topics.new(topic_form, u.id) reply_form = dict( content='reply test', topic_id=t.id, ) for j in range(5): Replys.new(reply_form, u.id)
def replied_topic(user_id): # O(k)+O(m*n) rs = Replys.all(user_id=user_id) ts = [] for r in rs: t = Topics.one(id=r.topic_id) ts.append(t) return ts
def rewrite(topicId): t = Topics() topic = t.query.filter_by(id=topicId).first() mf = dynamicMyBlogEdit() form = mf() form.title.data = topic.title form.content.data = topic.content_md form.tags.data = topic.tag_id return render_template('admin/edit.html', form=form)
def index(): topic = Topics() topicList = topic.query.order_by('createTime').limit(4) path = os.path.join(basedir, 'static/img/randomPic') picLs = os.listdir(path) ranPicLs = random.sample(picLs, 4) for i, p in zip(topicList, ranPicLs): i.pic_url = p return render_template('index/index.html', topicList=topicList)
def detail(topicId): topic = Topics() topicObj = topic.query.filter_by(id=topicId).first() if topicObj: tags = topicObj.tag reconTopic = tags.topic.limit(4) return render_template('index/detail.html', topicObj=topicObj, reconTopic=reconTopic) else: return abort(404)
def wrapper(*args, **kwargs): u = current_user() topic_id = request.args.get('id') t = Topics.one(id=topic_id) log('删除作者认证,文章作者id {}, 操作人id {}'.format(topic_id, u.id)) if t.user_id == u.id: log('作者', u) return f(*args, **kwargs) else: log('非作者本人') abort(401)
def add(): MyBlog = dynamicMyBlogEdit() form = MyBlog() if form.validate_on_submit(): topic = Topics() topic.title = form.title.data topic.content = request.form.get('editormd-html-code') topic.content_md = form.content.data topic.tag_id = form.tags.data db.session.add(topic) db.session.commit() return redirect(url_for('admin.index')) else: return render_template('admin/edit.html', form=form)
def addNewTopic(): topicInput = request.form["topic"] # Get user and check if topick in DB currentUser = Users.query.get(session["user_id"]) topicId = Topics.query.filter_by(topic=topicInput).first() if topicId: # If topic already in DB just append to current user topic_id currentUser.topics.append(Topics.query.get(topicId.id)) db.session.add(currentUser) db.session.commit() flash('You were successfully add topick') return redirect("/topics") else: # If not create new topic newTopic = Topics(topic=topicInput) db.session.add(newTopic) currentUser.topics.append(newTopic) db.session.add(currentUser) db.session.commit() flash('You were successfully add new topick') return redirect("/topics")
def add(): form = request.form.to_dict() u = current_user() Topics.new(form, user_id=u.id) return redirect(url_for('.index'))
def delete(): id = int(request.args.get('id')) u = current_user() print('删除 topic 用户是', u, id) Topics.delete(id) return redirect(url_for('.index'))
def detail(id): m = Topics.get(id) b = Board.one(id=m.board_id) # 传递 topic 的所有 reply 到 页面中 return render_template("topic/detail.html", topic=m, b=b)
def archives(): topic = Topics() topicList = topic.query.order_by('createTime').all() return render_template('index/archives.html', topicList=topicList)
def index(): topicList = Topics.get_topic_sum(basedir) return render_template('index/index.html', topicList=topicList)
def delete(topicId): t = Topics() topic = t.query.filter_by(id=topicId).first() db.session.delete(topic) db.session.commit() return redirect(url_for('admin.topicList'))
def created_topic(user_id): # O(n) ts = Topics.all(user_id=user_id) return ts