本文整理汇总了Python中models.Author.nationality方法的典型用法代码示例。如果您正苦于以下问题:Python Author.nationality方法的具体用法?Python Author.nationality怎么用?Python Author.nationality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Author
的用法示例。
在下文中一共展示了Author.nationality方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import nationality [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)