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


Python Book.from_id方法代码示例

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


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

示例1: test__run

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
    def test__run(self):
        data = dict(
            release_date=datetime.date.today(),
            complete_in_progress=True,
        )
        self._book = Book.from_updated(self._book, data)
        releaser = UnreleaseBook(self._book, self._creator)
        jobs = releaser.run(job_options=self._job_options)
        self.assertEqual(jobs, [])
        self.assertEqual(releaser.needs_requeue, False)

        book = Book.from_id(self._book.id)      # reload
        self.assertEqual(book.release_date, None)
        self.assertEqual(book.complete_in_progress, False)

        tests = [
            # (post_id, expect)
            ('', None),
            ('_fake_post_id_', '_fake_post_id_'),
            (IN_PROGRESS, None),
        ]
        for t in tests:
            data = dict(
                tumblr_post_id=t[0],
                twitter_post_id=t[0],
            )
            self._book = Book.from_updated(self._book, data)
            releaser = UnreleaseBook(self._book, self._creator)
            jobs = releaser.run(job_options=self._job_options)
            self.assertEqual(jobs, [])
            book = Book.from_id(self._book.id)      # reload
            self.assertEqual(book.tumblr_post_id, t[1])
            self.assertEqual(book.twitter_post_id, t[1])
开发者ID:zcomx,项目名称:zcomix.com,代码行数:35,代码来源:test_releasers.py

示例2: test__book_post_upload_session

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
    def test__book_post_upload_session(self):
        # No book_id, return fail message
        self.assertWebTest(
            '/login/book_post_upload_session',
            match_page_key='',
            match_strings=[
                '"status": "error"',
                '"msg": "Reorder service unavailable"',
            ],
        )

        # Invalid book_id, return fail message
        self.assertWebTest(
            '/login/book_post_upload_session/{bid}'.format(bid=999999),
            match_page_key='',
            match_strings=[
                '"status": "error"',
                '"msg": "Reorder service unavailable"',
            ],
        )

        # Valid book_id, no book pages returns success

        # Protect existing book_page records so they don't get deleted.
        def set_book_page_book_ids(from_book_id, to_book_id):
            from_book = Book.from_id(from_book_id)
            for page in from_book.pages():
                BookPage.from_updated(page, dict(book_id=to_book_id))

        temp_book = self.add(Book, dict(name='Temp Book'))

        set_book_page_book_ids(self._book.id, temp_book.id)

        self._book.update_record(status=BOOK_STATUS_DRAFT)
        db.commit()
        self.assertWebTest(
            '/login/book_post_upload_session/{bid}'.format(bid=self._book.id),
            match_page_key='/login/book_post_upload_session',
        )

        # book has no pages, so it should status should be set accordingly
        book = Book.from_id(self._book.id)
        self.assertEqual(book.status, BOOK_STATUS_DRAFT)

        # Valid
        set_book_page_book_ids(temp_book.id, self._book.id)
        book_page_ids = [x.id for x in self._book.pages()]
        bp_ids = ['book_page_ids[]={pid}'.format(pid=x) for x in book_page_ids]
        self.assertWebTest(
            '/login/book_post_upload_session/{bid}?{bpid}'.format(
                bid=self._book.id,
                bpid='&'.join(bp_ids),
            ),
            match_page_key='/login/book_post_upload_session',
        )

        # book has pages, so it should status should be set accordingly
        book = Book.from_id(self._book.id)
        self.assertEqual(book.status, BOOK_STATUS_ACTIVE)
开发者ID:zcomx,项目名称:zcomix.com,代码行数:61,代码来源:test_login.py

示例3: modal

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def modal():
    """Contributions input controller for modal view.

    request.vars.book_id: id of book, optional
    request.vars.creator_id: id of creator, optional

    if request.vars.book_id is provided, a contribution to a book is presumed.
    if request.vars.creator_id is provided, a contribution to a creator is
        presumed.
    if neither request.vars.book_id nor request.vars.creator_id are provided
        a contribution to zco.mx is presumed.
    request.vars.book_id takes precendence over request.vars.creator_id.
    """
    book = None
    creator = None

    if request.vars.book_id:
        book = Book.from_id(request.vars.book_id)
        creator = Creator.from_id(book.creator_id)
    elif request.vars.creator_id:
        creator = Creator.from_id(request.vars.creator_id)
        if not creator:
            raise LookupError(
                'Creator not found, id %s', request.vars.creator_id)

    return dict(
        book=book,
        creator=creator,
    )
开发者ID:zcomx,项目名称:zcomix.com,代码行数:31,代码来源:contributions.py

示例4: log_completed

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def log_completed():
    """Create activity_log records for books set as completed. """
    query = (db.book.release_date != None)
    ids = [x.id for x in db(query).select(db.book.id)]
    for book_id in ids:
        book = Book.from_id(book_id)
        # Check if log exists
        query = (db.activity_log.action == 'completed') & \
                (db.activity_log.book_id == book.id)
        count = db(query).count()
        if not count:
            LOG.debug('Logging completed: %s', book.name)
            try:
                first_page = get_page(book, page_no='first')
            except LookupError:
                LOG.error('First page not found: %s', book.name)
                continue

            db.activity_log.insert(
                book_id=book.id,
                book_page_ids=[first_page.id],
                action='completed',
                time_stamp=datetime.datetime.combine(
                    book.release_date, datetime.datetime.max.time())
            )
            db.commit()
开发者ID:zcomx,项目名称:zcomix.com,代码行数:28,代码来源:populate_activity_log_12889.py

示例5: create_book_page

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def create_book_page(db, book_id, image_filename):
    """Add the file to the book pages.

    Args:
        book_id: integer, id of book record the files belong to
        image_filename: /path/to/name of image file
    """
    try:
        stored_filename = store(db.book_page.image, image_filename)
    except IOError as err:
        LOG.error('IOError: %s', str(err))
        return

    book = Book.from_id(book_id)
    try:
        last_page = get_page(book, page_no='last')
    except LookupError:
        last_page = None
    page_no = last_page.page_no + 1 if last_page else 1

    data = dict(
        book_id=book_id,
        page_no=page_no,
        image=stored_filename,
    )
    book_page = BookPage.from_add(data)
    return book_page.id
开发者ID:zcomx,项目名称:zcomix.com,代码行数:29,代码来源:book_upload.py

示例6: download

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
    def download(
            self, request, db, chunk_size=DEFAULT_CHUNK_SIZE, attachment=True,
            download_filename=None):
        """
        Adapted from Response.download.
        request.args(0): integer, id of book record.
        """
        current.session.forget(current.response)

        if not request.args:
            raise HTTP(404)

        try:
            book = Book.from_id(request.args(0))
        except LookupError:
            raise HTTP(404)
        filename = book.cbz

        if not filename or not os.path.exists(filename):
            raise HTTP(404)

        stream = os.path.abspath(filename)

        headers = self.headers
        headers['Content-Type'] = contenttype(filename)
        if download_filename is None:
            download_filename = os.path.basename(filename)
        if attachment:
            fmt = 'attachment; filename="%s"'
            headers['Content-Disposition'] = \
                fmt % download_filename.replace('"', '\"')
        return self.stream(stream, chunk_size=chunk_size, request=request)
开发者ID:zcomx,项目名称:zcomix.com,代码行数:34,代码来源:downloaders.py

示例7: book_name_rep

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
 def book_name_rep(value, row):
     """db.book.name.represent."""
     # unused-argument (W0613): *Unused argument %%r*
     # pylint: disable=W0613
     book = Book.from_id(row.book.id)
     return A(
         formatted_name(book, include_publication_year=False),
         _href=book_url(book, extension=False)
     )
开发者ID:zcomx,项目名称:zcomix.com,代码行数:11,代码来源:search.py

示例8: book_torrent

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def book_torrent(book_id):
    """Create a torrent for a book."""
    book = Book.from_id(book_id)
    result = BookTorrentCreator(book).archive()
    LOG.debug('Created: %s', result)

    creator = Creator.from_id(book.creator_id)
    if not creator.rebuild_torrent:
        creator = Creator.from_updated(creator, dict(rebuild_torrent=True))
开发者ID:zcomx,项目名称:zcomix.com,代码行数:11,代码来源:create_torrent.py

示例9: __init__

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
    def __init__(self, db, value, row):
        """Constructor

        Args:
            db: gluon.dal.Dal instance
            value: string, value to display in footer right side.
            row: gluon.dal.Row representing row of grid
        """
        Tile.__init__(self, db, value, row)
        self.book = Book.from_id(self.row.book.id)
开发者ID:zcomx,项目名称:zcomix.com,代码行数:12,代码来源:search.py

示例10: book_link

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
 def book_link(book_id, text_only=False):
     """Return a book link."""
     label = 'book'
     url = None
     if not text_only:
         try:
             book = Book.from_id(book_id)
         except LookupError:
             url = None
         else:
             url = book_url(book, extension=False)
     return li_link(label, url)
开发者ID:zcomx,项目名称:zcomix.com,代码行数:14,代码来源:z.py

示例11: read_link

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def read_link(row):
    """Return an 'Read' link suitable for grid row."""
    if not row:
        return ''
    book_id = link_book_id(row)
    if not book_id:
        return ''
    book = Book.from_id(book_id)
    return book_read_link(
        book,
        **dict(_class='btn btn-default zco_book_reader')
    )
开发者ID:zcomx,项目名称:zcomix.com,代码行数:14,代码来源:search.py

示例12: optimize_book_images

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def optimize_book_images(book_id, debug=False, force=False):
    """Optimize all images associated with a book."""
    book = Book.from_id(book_id)
    LOG.debug('Optimizing images for book: %s', book.name)
    if not debug:
        images = book_images(book)
        if force:
            for image in images:
                query = (db.optimize_img_log.image == image)
                db(query).delete()
                db.commit()
        AllSizesImages.from_names(images).optimize()
开发者ID:zcomx,项目名称:zcomix.com,代码行数:14,代码来源:optimize_images.py

示例13: book_generator

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def book_generator(query):
    """Generate book records.

    Args:
        query: gluon.dal.Expr query.

    Yields:
        Book instance
    """
    ids = [x.id for x in db(query).select(db.book.id)]
    for book_id in ids:
        book = Book.from_id(book_id)
        yield book
开发者ID:zcomx,项目名称:zcomix.com,代码行数:15,代码来源:set_book_status.py

示例14: main

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def main():
    """Main processing."""

    usage = '%prog [options] book_id [book_id book_id ...]'
    parser = OptionParser(usage=usage, version=VERSION)

    parser.add_option(
        '--man',
        action='store_true', dest='man', default=False,
        help='Display manual page-like help and exit.',
    )
    parser.add_option(
        '-v', '--verbose',
        action='store_true', dest='verbose', default=False,
        help='Print messages to stdout.',
    )
    parser.add_option(
        '--vv',
        action='store_true', dest='vv', default=False,
        help='More verbose.',
    )

    (options, args) = parser.parse_args()

    if options.man:
        man_page()
        quit(0)

    set_cli_logging(LOG, options.verbose, options.vv)

    if len(args) < 1:
        parser.print_help()
        exit(1)

    exit_status = 0
    for book_id in args:
        try:
            book = Book.from_id(book_id)
        except LookupError:
            LOG.error('Book not found, id: %s', book_id)
            exit_status = 1
            continue

        LOG.debug('Creating cbz for: %s', book.name)
        try:
            archive(book)
        except (CBZCreateError, LookupError) as err:
            LOG.error('%s, %s', err, book.name)
            exit_status = 1
    if exit_status:
        exit(exit_status)
开发者ID:zcomx,项目名称:zcomix.com,代码行数:53,代码来源:create_cbz.py

示例15: log

# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_id [as 别名]
def log(download_click_id, book_id):
    """Log a download click

    Args:
        download_click_id: integer, id of download_click record
        book_id: integer, id of book record
    """
    click = DownloadClick.from_id(download_click_id)
    if not click:
        raise LookupError('download_click not found, id: {i}'.format(
            i=download_click_id))

    book = Book.from_id(book_id)
    return DownloadEvent(book, click.auth_user_id).log(value=click)
开发者ID:zcomx,项目名称:zcomix.com,代码行数:16,代码来源:log_downloads.py


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