当前位置: 首页>>代码示例>>Python>>正文


Python Author.placeofbirth方法代码示例

本文整理汇总了Python中models.Author.placeofbirth方法的典型用法代码示例。如果您正苦于以下问题:Python Author.placeofbirth方法的具体用法?Python Author.placeofbirth怎么用?Python Author.placeofbirth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Author的用法示例。


在下文中一共展示了Author.placeofbirth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit_author

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import placeofbirth [as 别名]
def edit_author(number):
	if number == 'new':
		author = Author()
		title = 'Ajouter un auteur dans la bibliotheque'
	else:
		author = Author.query.get(number)
		title = author
		if os.path.exists('app/static/photos/' + str(author.id)):
			author.img = True
	#global author
	#a = author
	form = AuthorForm()
	form.booktoadd.choices = Book.query.filter(Book!=author.books)
	update = False
	#if form.validate_on_submit():
	if request.form=='POST' and form.validate():
		#print form.errors
		author.firstname = unicode(form.firstname.data)
		author.familyname = unicode(form.familyname.data)
		if form.nationality.data != author.nationality:
			author.nationality= unicode(form.nationality.data)
			update = True
		#a.dateofbirth= form.dateofbirth.data
		if form.placeofbirth.data != author.placeofbirth:
			author.placeofbirth = unicode(form.placeofbirth.data)
			update = True
		if form.website.data != author.website:
			author.website = unicode(form.website.data)
			update = True
		if form.biography.data != author.biography:
			author.biography = unicode(form.biography.data)
			update = True

		# gestion des livres
		if request.form.getlist('booktodelete'):
			for item in request.form.getlist('booktodelete'):
				a = Book.query.get(item)
				author.remove_book(a)
				update = True
		
		if request.form.getlist('booktoadd'):
			for item in request.form.getlist('booktoadd'):
				# even if noting is select, the field return something, a unicode string '__None'
				# this "if" not to block the whole thing. Same on books !
				if item != '__None':
					a = Book.query.get(item)
					author.add_book(a)
					update = True
		
		if update:
			db.session.add(author)
			db.session.commit()
			db.session.refresh(author)
		
		# the photo will overwrite the previous if existing.
		# thus, only one per author and nothing else to check
		if request.method == 'POST' and request.files['portrait']:
			fileurl = 'app/static/photos/' + str(author.id)
			image = request.files['portrait'].save(fileurl)
		
		return redirect('/admin')
	return render_template('edit_author.html', form = form, author = author, title = title)
开发者ID:22decembre,项目名称:biblib,代码行数:64,代码来源:views.py


注:本文中的models.Author.placeofbirth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。