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 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 archives(): topic = Topics() topicList = topic.query.order_by('createTime').all() return render_template('index/archives.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'))