def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('edit')) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template('edit.html', form=form)
def publish(): form = EditForm() if form.validate_on_submit(): entry = Entry(title = form.title.data, content = form.content.data, pub_date = datetime.now()) try: db.session.add(entry) db.session.commit() except: flash('Database error!') return redirect('/edit') flash('Publich success!') return redirect('/entry/%d'%(entry.id)) return render_template('publish.html',form = form)
def edit(id): entry = Entry.query.filter_by(id = id).first() if entry == None: flash('entry error') return redirect(url_for('index')) form = EditForm(obj = entry) if form.validate_on_submit(): entry.title = form.title.data entry.content = form.content.data entry.pub_date = datetime.now() try: db.session.add(entry) db.session.commit() except: flash('Database error!') return redirect('/edit/%d'%entry.id) flash('Edit success!') return redirect('/entry/%d'%(entry.id)) return render_template('publish.html', form = form)