本文整理汇总了Python中models.Book.subtitle方法的典型用法代码示例。如果您正苦于以下问题:Python Book.subtitle方法的具体用法?Python Book.subtitle怎么用?Python Book.subtitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.subtitle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_data
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import subtitle [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: acquisition
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import subtitle [as 别名]
def acquisition(request):
record_data = {}
record = None
if request.GET.get('isbn'):
isbn = request.GET.get('isbn')
if isbnpy.isValid(isbn):
url = 'http://openlibrary.org/api/volumes/brief/json/isbn:' + isbn
response = urllib2.urlopen(url)
# response = urllib2.urlopen('http://127.0.0.1/json/3.json')
data = json.load(response)
if isbnpy.isI10(isbn):
isbn = isbnpy.convert(isbn)
if data == {}:
record_data['isbn13'] = isbn
record_form = RecordForm(instance=record)
return render(request, 'acquisition.html', {'data': record_data, 'form': record_form})
data = data.itervalues().next()['records'].itervalues().next()
try:
record = Record.objects.get(isbn13=isbn)
new_record = False
except Record.DoesNotExist:
record = Record(isbn13=isbn)
new_record = True
# pp(data)
if record.book_id:
book = record.book
else:
book = Book()
book.title = data['data']['title']
if data['details']['details'].has_key('subtitle'):
book.subtitle = data['details']['details']['subtitle']
book.save()
if data['details']['details'].has_key('pagination'):
record.pagination = data['data']['pagination']
elif data['details']['details'].has_key('number_of_pages'):
record.pagination = str(data['data']['number_of_pages']) + ' p.'
if data['details']['details'].has_key('physical_format'):
record.format = data['details']['details']['physical_format']
if record.format.startswith('electronic'):
record.format = 'eBook'
# record.openlibrary_url = data['data']['url']
if data['details']['details'].has_key('weight'):
record.weight = data['details']['details'].get('weight')
if data['details']['details'].has_key('physical_dimensions'):
record.dimensions = data['details']['details'].get('physical_dimensions')
if data['data'].has_key('classifications'):
if data['data']['classifications'].has_key('dewey_decimal_class'):
record.ddc = data['data']['classifications'].get('dewey_decimal_class')[0]
if data['data']['classifications'].has_key('lc_classifications'):
record.lcc = data['data']['classifications'].get('lc_classifications')[0]
try:
record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%B %d, %Y').date()
record.publication_has_month = True
record.publication_has_day = True
except ValueError:
try:
record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%Y').date()
record.publication_has_month = False
record.publication_has_day = False
except ValueError:
try:
record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%B %Y').date()
record.publication_has_day = False
record.publication_has_month = True
except ValueError:
record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%m/%d/%Y').date()
record.publication_has_day = True
record.publication_has_month = True
if data['data'].has_key('identifiers'):
if data['data']['identifiers'].has_key('openlibrary'):
record.openlibrary_id = data['data']['identifiers']['openlibrary'][0]
if data['data']['identifiers'].has_key('goodreads'):
record.goodreads_id = data['data']['identifiers']['goodreads'][0]
if data['data']['identifiers'].has_key('librarything'):
record.librarything_id = data['data']['identifiers']['librarything'][0]
if data['data']['identifiers'].has_key('oclc'):
record.oclc_id = data['data']['identifiers']['oclc'][0]
if data['data']['identifiers'].has_key('lccn'):
record.lccn_id = data['data']['identifiers']['lccn'][0]
if data['data'].has_key('by_statement'):
record.by_statement = data['data'].get('by_statement')
if data['data'].has_key('notes'):
record.notes = data['data'].get('notes')
if data['data'].has_key('excerpts'):
record.excerpt = data['data'].get('excerpts')[0].get('text')
record.book = book
#.........这里部分代码省略.........
示例3: save_acquisition
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import subtitle [as 别名]
def save_acquisition(request):
if request.POST.get('book').isnumeric():
book = Book.objects.get(id=request.POST.get('book'))
new_book = False
else:
book = Book(title=request.POST.get('book'))
new_book = True
book.subtitle = request.POST.get('subtitle')
book.save()
if request.POST.get('isbn'):
isbn = request.POST.get('isbn')
if isbnpy.isValid(isbn):
if isbnpy.isI10(isbn):
isbn = isbnpy.convert(isbn)
try:
record = Record.objects.get(isbn13=isbn)
new_record = False
except Record.DoesNotExist:
record = Record(isbn13=isbn)
new_record = True
else:
if not new_book:
try:
record = Record.objects.get(book=book, edition=request.POST.get('book'))
new_record = False
except Record.DoesNotExist:
record = Record(book=book)
new_record = True
else:
record = Record(book=book)
new_record = True
record.book = book
record.format = request.POST.get('format')
if record.format != 'ebook':
if new_record:
record.quantity = request.POST.get('quantity')
else:
record.quantity += int(request.POST.get('quantity'))
record.excerpt = request.POST.get('excerpt')
record.edition = request.POST.get('edition')
record.notes = request.POST.get('notes')
record.ddc = request.POST.get('ddc')
record.lcc = request.POST.get('lcc')
record.pagination = request.POST.get('pagination')
record.format = request.POST.get('format')
record.type = request.POST.get('type')
if record.format != 'eBook':
record.quantity = request.POST.get('quantity')
record.publication_has_month = False
record.publication_has_day = False
if request.POST.get('year'):
dt = datetime(int(request.POST.get('year')), 1, 1)
if request.POST.get('month'):
record.publication_has_month = True
dt = dt.replace(month=int(request.POST.get('month')))
if request.POST.get('day'):
record.publication_has_day = True
dt = dt.replace(day=int(request.POST.get('day')))
record.date_of_publication = dt
else:
record.date_of_publication = None
if request.FILES.get('small_cover'):
record.small_cover = request.FILES.get('small_cover')
if request.FILES.get('medium_cover'):
record.medium_cover = request.FILES.get('medium_cover')
if request.FILES.get('large_cover'):
record.large_cover = request.FILES.get('large_cover')
if not record.date_added:
record.date_added = datetime.today()
record.save()
if request.FILES.get('ebook'):
ebooks = request.FILES.getlist('ebook')
for ebook in ebooks:
ebook_file = BookFile(record=record, file=ebook)
existing_files = record.ebooks(ebook_file.format)
for existing_file in existing_files:
existing_file.delete()
ebook_file.save()
book.subjects.clear()
for subject in request.POST.getlist('subjects'):
if subject.isnumeric():
book.subjects.add(Subject.objects.get(id=subject))
else:
new_subject = Subject(name=subject)
new_subject.save()
book.subjects.add(new_subject)
record.authors.clear()
for author in request.POST.getlist('authors'):
if author.isnumeric():
record.authors.add(Author.objects.get(id=author))
#.........这里部分代码省略.........