def add(): """新增文章至資料庫""" # 檢查有無登入 if g.user == None: # 沒登入就回到登入頁面 return redirect(url_for("index")) newForm = NewArticleForm() if newForm.validate_on_submit(): newArticle = DbArticle(g.user.index, newForm.content.data, newForm.title.data, newForm.authority.data) newArticle.store_to_db() flash(u"新增文章成功") else: flash(u"新增文章失敗") return redirect(url_for("user.article"))
def add(): '''新增文章至資料庫''' #檢查有無登入 if g.user == None: #沒登入就回到登入頁面 return redirect(url_for('index')) newForm = NewArticleForm() if newForm.validate_on_submit(): newArticle = DbArticle(g.user.index, newForm.content.data, newForm.title.data, newForm.authority.data) newArticle.store_to_db() flash(u"新增文章成功") else: flash(u"新增文章失敗") return redirect(url_for('user.article'))
def edit_over(serial): '''編輯完成''' #檢查有無登入 if g.user == None: #沒登入就回到登入頁面 return redirect(url_for('index')) article = DbArticle.query.filter_by(index=serial).first() if article is None: flash(u"沒有這篇文章") return redirect(url_for('user.article')) newForm = NewArticleForm() if newForm.validate_on_submit(): article.content = newForm.content.data article.title = newForm.title.data article.type = newForm.authority.data article.modify() flash(u"修改文章成功") else: flash(u"修改文章失敗") return redirect(url_for('user.article'))
def edit_over(serial): """編輯完成""" # 檢查有無登入 if g.user == None: # 沒登入就回到登入頁面 return redirect(url_for("index")) article = DbArticle.query.filter_by(index=serial).first() if article is None: flash(u"沒有這篇文章") return redirect(url_for("user.article")) newForm = NewArticleForm() if newForm.validate_on_submit(): article.content = newForm.content.data article.title = newForm.title.data article.type = newForm.authority.data article.modify() flash(u"修改文章成功") else: flash(u"修改文章失敗") return redirect(url_for("user.article"))
def edit(serial): '''編輯文章''' #檢查有無登入 if g.user == None: #沒登入就回到登入頁面 flash(u"您還沒登入歐~") return redirect(url_for('index')) article = DbArticle.query.filter_by(index=serial).first() if article is None: flash(u"沒有這篇文章") return redirect(url_for('user.article')) aform = NewArticleForm() aform.title.data = article.title aform.content.data = article.content qform = QuestionForm() questions = DbQuestion.query.filter_by(article_id=serial) print serial return render_template('article/edit.html', article=article, questions=questions, form=aform, qform=qform)
def new(): '''新增文章頁面''' form_ = NewArticleForm() # for i in xrange(20): # form_.questions.append_entry() return render_template('article/new.html', form=form_)