示例#1
0
def edit_entry(view, id): 
	entry = db_session.query(Book).filter(Book.id==id).first()
	form = BookForm(request.form,obj=entry)
	if request.method == 'POST' and form.validate():
		if view=='books':
			entry.authors = []
			for author in form.authors.data :
				entry.authors.append(get_or_create(Author,name=author))
			entry.name = form.name.data
			entry.description = form.description.data
		db_session.commit()		
		flash('%s successfuly have edited' % entry.name)
		return redirect(url_for('admin_show_entries',pagin = app.config['PAGIN'], page=1, view=view))
	flash('edited  entry to %s database' % view)
	return render_template('add_entry.html', form=form, view=view,entry=entry, mode="edit")
示例#2
0
def add_entry(view): 
	if view=='books':
		form = BookForm(request.form)
	else:
		form = AuthorForm(request.form)
	if request.method == 'POST' and form.validate():
		if view=='books':
			entry = Book(name=form.name.data,description=form.description.data)
			for author in  form.authors.data:
				entry.authors.append(get_or_create(Author,name=author))
		else:
			entry = Author(str(form.name.data))
		db_session.add(entry)
		db_session.commit()		
		flash('%s successfuly added' % entry.name)
		return redirect(url_for('admin_show_entries',pagin = app.config['PAGIN'], page=1, view=view))
	flash('Add new entry to %s database' % view)
	return render_template('add_entry.html', form=form, view=view,mode='add')