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


Python Book.language方法代码示例

本文整理汇总了Python中catalogue.models.Book.language方法的典型用法代码示例。如果您正苦于以下问题:Python Book.language方法的具体用法?Python Book.language怎么用?Python Book.language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在catalogue.models.Book的用法示例。


在下文中一共展示了Book.language方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_book

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import language [as 别名]
def update_book(book_info):
    book_id = book_info.book_id

    books = Book.objects.filter(uid=book_id[1], uid_scheme=book_id[0])

    mode = 'read'

    if books:
        if books[0].file_stamp < book_info.stamp:
            mode = 'update'
            book = books[0]
        else:
            mode = 'skip'

    if mode in ('read', 'update'):
        LOG.info('update_book:', mode)

        book_info.validate()

        if book_info.valid:
            LOG.info('update_book: found a book: %s, %s', book_info.path,
                                                          book_info.stamp)
            if 1:
                print_info(book_info)

            if mode == 'read':
                fmt, _ = BookFormat.objects.get_or_create(name=book_info.format_name())
                book = Book(
                    uid=book_id[1],
                    uid_scheme=book_id[0],
                    title=book_info.title,
                    language=book_info.language,
                    file=book_info.path,
                    file_stamp=book_info.stamp,
                    mimetype=book_info.mimetype,
                    format=fmt,
                    annotation=book_info.annotation
                )
            else:
                # it is assumed that book format does not change
                book.uid = book_id[1]
                book.uid_scheme = book_id[0]
                book.title = book_info.title
                book.language = book_info.language
                book.file = book_info.path
                book.file_stamp = book_info.stamp
                book.mimetype = book_info.mimetype
                book.annotation = book_info.annotation

                book.authors.clear()
                book.series.clear()
                book.tags.clear()

            book.save()

            for position, author in enumerate(book_info.authors, 1):
                db_author, _ = Author.objects.get_or_create(name=author)

                bookauthor = BookAuthor(book=book, author=db_author,
                                        position=position)
                bookauthor.save()

            for series, number in book_info.series:
                db_series, _ = Series.objects.get_or_create(name=series)

                bookseries = BookSeries(book=book, series=db_series,
                                        number=number)
                bookseries.save()

            for tag in book_info.tags:
                if '/' in tag:
                    db_tag = None

                    for name in [x.strip() for x in tag.split('/')]:
                        db_tag, _ = Tag.objects.get_or_create(name=name,
                                                              parent=db_tag)
                else:
                    db_tag, _ = Tag.objects.get_or_create(name=tag)

                booktag = BookTag(book=book, tag=db_tag)
                booktag.save()
        else:
            LOG.error('update_book: not a valid book at', book_info.path)
    elif mode == 'skip':
        LOG.warn('update_book: %s already registered and is up to date',
                 book_info.path)
开发者ID:sa2ajj,项目名称:myLibrary,代码行数:88,代码来源:tools.py


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