本文整理汇总了Python中models.Record.weight方法的典型用法代码示例。如果您正苦于以下问题:Python Record.weight方法的具体用法?Python Record.weight怎么用?Python Record.weight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Record
的用法示例。
在下文中一共展示了Record.weight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: acquisition
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import weight [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
#.........这里部分代码省略.........