當前位置: 首頁>>代碼示例>>Python>>正文


Python Book.addBook方法代碼示例

本文整理匯總了Python中book.Book.addBook方法的典型用法代碼示例。如果您正苦於以下問題:Python Book.addBook方法的具體用法?Python Book.addBook怎麽用?Python Book.addBook使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在book.Book的用法示例。


在下文中一共展示了Book.addBook方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DetailProcessor

# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import addBook [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
開發者ID:jzlink,項目名稱:library,代碼行數:78,代碼來源:detailProcessor.py


注:本文中的book.Book.addBook方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。