当前位置: 首页>>代码示例>>Python>>正文


Python Record.weight方法代码示例

本文整理汇总了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

#.........这里部分代码省略.........
开发者ID:ratna1234,项目名称:nerp,代码行数:103,代码来源:views.py


注:本文中的models.Record.weight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。