本文整理汇总了Python中models.Book.language方法的典型用法代码示例。如果您正苦于以下问题:Python Book.language方法的具体用法?Python Book.language怎么用?Python Book.language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.language方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_data
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import language [as 别名]
def insert_data(self, data):
"""
Will handle inserting data into the database
"""
try:
# Check if book is in database, if so update else create
try:
book = db_session.query(Book).filter(Book.book_id == data.get('book_id')).one()
except NoResultFound:
book = Book()
book.title = data.get('title')
book.subtitle = data.get('subtitle')
book.author = data.get('author')
book.year = data.get('year')
book.pages = data.get('pages')
book.language = data.get('language')
book.publisher = data.get('publisher')
book.isbn = data.get('isbn')
book.format = data.get('format')
book.description = data.get('description')
book.file_source = data.get('file_source')
book.file_cover_source = data.get('file_cover_source')
book.file_location = data.get('file_location')
book.file_cover_location = data.get('file_cover_location')
book.book_id = data.get('book_id')
book.time_collected = data.get('time_collected')
db_session.add(book)
db_session.commit()
# self.track_stat('rows_added_to_db', rows_affected)
except Exception:
db_session.rollback()
logger.exception("Error adding to db {data}".format(data=data))
示例2: upload_file
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import language [as 别名]
def upload_file(self, filename):
gcs_file = gcs.open(filename)
datareader = csv.reader(gcs_file)
count = 0
entities = []
for row in datareader:
count += 1
#TODO: Pass the enums
if len(row[1]) > 0:
booktitle = row[1].lower()
booksbId = row[0]
#convert 1/4/3101 to 3101-04--01
if booksbId.find('/')>-1:
list = booksbId.split('/')
if len(list)>1:
booksbId = list[2] + '-0'+list[1] +'--0'+list[0]
b_key = ndb.Key(Book, booksbId.upper())
newBook = Book(
key = b_key,
sbId = booksbId,
title = booktitle,
volume = row[2],
author = row[3],
isbn = row[4],
price = row[5],
#language = row[6],
notes = row[8],
#suggestedGrade = row[9],
category = row[10],
publisher = row[15],
editionYear = row[18],
donor = row[20],
comments = row[25]
)
if row[6]:
lang = row[6]
if lang == 'English':
newBook.language = Language.ENGLISH
elif lang == 'Tamil':
newBook.language = Language.TAMIL
elif lang == 'Gujarathi':
newBook.language = Language.GUJARATHI
elif string.find(lang, 'Hindi')>-1:
newBook.language = Language.HINDI
if row[9]:
grade = row[9]
if grade == 'KG':
newBook.suggestedGrade.append(Grade.K)
elif self._isNumber(grade):
newBook.suggestedGrade.append(self._getGrade(int(grade)))
elif grade == 'Adult':
newBook.suggestedGrade.append(Grade.ADULT)
else:
minGrade = 0
if string.find(grade, '-Jan')>-1:
maxGrade = grade[0]
minGrade = 1
elif string.find(grade, '-Feb')>-1:
minGrade = 2
maxGrade = grade[0]
elif string.find(grade, '-Mar')>-1:
minGrade = 3
maxGrade = grade[0]
if minGrade > 0:
for i in range(minGrade, int(maxGrade)+1):
newBook.suggestedGrade.append(self._getGrade(i))
if row[16]:
if row[16] == 'Book':
newBook.mediaType = Media.BOOK
elif row[16] == 'Dictionary':
newBook.mediaType = Media.DICTIONARY
elif string.find(row[16], 'CD')>-1:
newBook.mediaType = Media.CD
entities.append(newBook)
if count%50==0 and entities:
ndb.put_multi(entities)
entities=[]
if entities:
ndb.put_multi(entities)
self.response.set_status(204)