本文整理汇总了Python中book.Book.updateBook方法的典型用法代码示例。如果您正苦于以下问题:Python Book.updateBook方法的具体用法?Python Book.updateBook怎么用?Python Book.updateBook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类book.Book
的用法示例。
在下文中一共展示了Book.updateBook方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DetailProcessor
# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import updateBook [as 别名]
class DetailProcessor():
def __init__(self):
self.series = Series()
self.author = Author()
self.book = Book()
self.whenRead = WhenRead()
#establish list of fields the book method is purely responsible for
# updating
self.bookOnlyFields = ['book_id', 'title', 'notes', 'published',
'owner_status_id', 'read_status_id', 'type_id',
'series_num']
def processForm(self, formDict):
message = 'Record Updated'
book_id = formDict['book_id']
#if the record is new first call the add new book method, reciecve a new
# book_id, append it to the dictionary
# the send the dictionary to the update methods
if formDict['activity'] == 'submit_new':
book_id = self.book.addBook()
formDict['book_id'] = book_id
message = 'Record Added'
bookDict = {}
#create a special dictionary of fields the book method is responsible for
# updating itself.
for field in self.bookOnlyFields:
bookDict[field] = formDict[field]
#run the seriesUpdate method which will add a series to the DB if
# necessary. append the new series id to the bookDict
seriesUpdate = self.series.updateSeries(formDict)
bookDict['series_id'] = seriesUpdate
bookUpdate = self.book.updateBook(bookDict)
authorUpdate = self.author.updateAuthor(formDict)
if formDict['when_read'] != '':
dateUpdate = self.whenRead.updateWhenRead(formDict)
#message = self.buildMessasge() # insert all update return values
return message, book_id
def buildMessage(self, updated, added= None):
'''accepts dict of fields updated and their new values
returns properly formatted string for message display'''
updates = ''
adds = ''
if updated:
updates = 'Updated: <br> '
for item in updated:
if item in self.columns:
d_name = self.columns[item][0]['display']
updates += '%s changed to: %s <br>'\
%(d_name, updated[item])
else:
updates += '%s was %s <br>' %(item, updated[item])
if added:
adds = 'Added: <br> '
for item in added:
adds += '%s: %s ' %(item, added[item])
message = 'For this record the following fields were <br> %s %s'\
%(updates, adds)
if not added and not updated:
message = 'Message: No fields changed, no updates made'
return message