本文整理汇总了Python中models.Record.publisher方法的典型用法代码示例。如果您正苦于以下问题:Python Record.publisher方法的具体用法?Python Record.publisher怎么用?Python Record.publisher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Record
的用法示例。
在下文中一共展示了Record.publisher方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: acquisition
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import publisher [as 别名]
#.........这里部分代码省略.........
elif data['data'].has_key('authors'):
for author in data['data']['authors']:
author_key = author['url'].replace('http://openlibrary.org/authors/', '')
try:
book_author = Author.objects.get(identifier=author_key)
except Author.DoesNotExist:
book_author = Author(identifier=author_key)
book_author.name = author['name']
book_author.save()
record.authors.add(book_author)
if data['data'].has_key('ebooks'):
if data['data']['ebooks'][0].has_key('formats'):
formats = data['data']['ebooks'][0]['formats']
for book_format in formats:
ebooks = record.ebooks(book_format)
for ebook in ebooks:
ebook.delete()
if formats[book_format].has_key('url'):
url = formats[book_format].get('url')
result = urllib.urlretrieve(url)
book_file = BookFile(record=record)
book_file.file.save(
os.path.basename(url),
File(open(result[0]))
)
book_file.save()
subjects = None
if data['details']['details'].has_key('subjects'):
subjects = data['details']['details']['subjects']
elif data['data'].has_key('subjects'):
subjects = data['data']['subjects']
if subjects:
record.book.subjects.clear()
for subject in subjects:
if type(subject) == dict:
subject = title_case(subject['name'])
try:
book_subject = Subject.objects.get(name=subject)
except Subject.DoesNotExist:
book_subject = Subject(name=subject)
book_subject.save()
record.book.subjects.add(book_subject)
# record.publishers.clear()
# for publisher in data['details']['details']['publishers']:
# try:
# book_publisher = Publisher.objects.get(name=publisher['name'])
# except Publisher.DoesNotExist:
# book_publisher = Publisher(name=publisher['name'])
# book_publisher.save()
# record.publishers.add(book_publisher)
try:
book_publisher = Publisher.objects.get(name=data['details']['details']['publishers'][0])
except Publisher.DoesNotExist:
book_publisher = Publisher(name=data['details']['details']['publishers'][0])
book_publisher.save()
record.publisher = book_publisher
if data['data'].has_key('cover'):
if data['data']['cover'].has_key('large'):
cover_url = data['data']['cover']['large']
result = urllib.urlretrieve(cover_url)
record.large_cover.save(
os.path.basename(cover_url),
File(open(result[0]))
)
if data['data']['cover'].has_key('medium'):
cover_url = data['data']['cover']['medium']
result = urllib.urlretrieve(cover_url)
record.medium_cover.save(
os.path.basename(cover_url),
File(open(result[0]))
)
if data['data']['cover'].has_key('small'):
cover_url = data['data']['cover']['small']
result = urllib.urlretrieve(cover_url)
record.small_cover.save(
os.path.basename(cover_url),
File(open(result[0]))
)
# thumbnail_url = data['details']['thumbnail_url']
# result = urllib.urlretrieve(thumbnail_url)
# record.thumbnail.save(
# os.path.basename(thumbnail_url),
# File(open(result[0]))
# )
# import pdb
#
# pdb.set_trace()
record_data = RecordSerializer(record).data
record_form = RecordForm(instance=record)
return render(request, 'acquisition.html', {'data': record_data, 'form': record_form})
示例2: save_acquisition
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import publisher [as 别名]
#.........这里部分代码省略.........
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))
else:
new_author = Author(name=author)
new_author.save()
record.authors.add(new_author)
record.languages.clear()
for language in request.POST.getlist('languages'):
record.languages.add(Language.objects.get(id=language))
publisher = request.POST.get('publisher')
if publisher:
if publisher.isnumeric():
record.publisher_id = publisher
else:
new_publisher = Publisher(name=publisher)
new_publisher.save()
record.publisher = new_publisher
record.save()
return redirect(reverse_lazy('view_record', kwargs={'pk': record.id}))