本文整理汇总了Python中applications.zcomx.modules.books.Book.from_updated方法的典型用法代码示例。如果您正苦于以下问题:Python Book.from_updated方法的具体用法?Python Book.from_updated怎么用?Python Book.from_updated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类applications.zcomx.modules.books.Book
的用法示例。
在下文中一共展示了Book.from_updated方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__run
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [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])
示例2: test__get_reader
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def test__get_reader(self):
router = Router(db, self._request, auth)
# No request.vars.reader, no book
self.assertEqual(router.get_reader(), None)
unreadable_statuses = [BOOK_STATUS_DRAFT, BOOK_STATUS_DISABLED]
readers = ['_reader_', 'slider', 'scroller']
router.book = self._book
for status in unreadable_statuses:
router.book = Book.from_updated(router.book, dict(status=status))
for reader in readers:
router.request.vars.reader = reader
self.assertEqual(router.get_reader(), 'draft')
self._book = Book.from_updated(
self._book, dict(status=BOOK_STATUS_ACTIVE))
router.book = None
router.request.vars.reader = '_reader_'
self.assertEqual(router.get_reader(), None)
router.book = self._book
self.assertEqual(router.get_reader(), 'slider')
del router.request.vars.reader
self.assertEqual(router.get_reader(), 'slider')
self._book = Book.from_updated(self._book, dict(reader='scroller'))
router.book = self._book
self.assertEqual(router.get_reader(), 'scroller')
self._book = Book.from_updated(self._book, dict(reader='slider'))
示例3: archive
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def archive(self, base_path=None):
"""Archive the torrent.
Returns:
string, name of archive file.
"""
result = BaseTorrentCreator.archive(self, base_path=base_path)
if self.book:
self.book = Book.from_updated(self.book, dict(torrent=result))
return result
示例4: run
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def run(self, job_options=None):
db = current.app.db
jobs = []
if not self.book.tumblr_post_id:
job = PostOnSocialMediaQueuer(
db.job,
job_options=job_options,
cli_args=[str(self.book.id)],
).queue()
self.needs_requeue = True
# Set the tumblr post id to a dummy value to prevent this step
# from running over and over.
data = dict(
tumblr_post_id=IN_PROGRESS,
twitter_post_id=IN_PROGRESS
)
self.book = Book.from_updated(self.book, data)
self.needs_requeue = True
return [job]
# Everythings good. Release the book.
data = dict(
release_date=datetime.datetime.today(),
complete_in_progress=False,
)
self.book = Book.from_updated(self.book, data)
# Log activity
try:
first_page = get_page(self.book, page_no='first')
except LookupError:
LOG.error('First page not found: %s', self.book.name)
else:
db.tentative_activity_log.insert(
book_id=self.book.id,
book_page_id=first_page.id,
action='completed',
time_stamp=datetime.datetime.now(),
)
db.commit()
return jobs
示例5: test__set_reader_view
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def test__set_reader_view(self):
router = Router(db, self._request, auth)
router.creator = self._creator
router.book = self._book
router.book_page_record = self._book_page
self.assertEqual(len(self._book_views(self._book.id)), 0)
router.set_reader_view()
self.assertEqual(
sorted(router.view_dict.keys()),
self._keys_for_view['reader'],
)
self.assertEqual(
router.view,
'books/slider.html',
)
self.assertEqual(router.redirect, None)
views = self._book_views(self._book.id)
self.assertEqual(len(views), 1)
for obj in views:
self._objects.append(obj)
router.book = Book.from_updated(router.book, dict(reader='scroller'))
for book_view in self._book_views(self._book.id):
book_view.delete()
self.assertEqual(len(self._book_views(self._book.id)), 0)
router.set_reader_view()
self.assertEqual(
sorted(router.view_dict.keys()),
self._keys_for_view['reader'],
)
self.assertEqual(
router.view,
'books/scroller.html',
)
views = self._book_views(self._book.id)
self.assertEqual(len(views), 1)
for obj in views:
self._objects.append(obj)
router.book = Book.from_updated(router.book, dict(reader='slider'))
示例6: main
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def main():
"""Main processing."""
usage = '%prog [options]'
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, unused_args) = parser.parse_args()
if options.man:
man_page()
quit(0)
set_cli_logging(LOG, options.verbose, options.vv)
LOG.info('Started.')
ids = [x.id for x in db(db.book).select(db.book.id)]
for book_id in ids:
book = Book.from_id(book_id)
meta = BookPublicationMetadata.from_book(book)
try:
publication_year = meta.publication_year()
except ValueError:
continue # This is expected if the metadata is not set.
if book.publication_year == publication_year:
continue
LOG.debug('Updating: %s to %s', book.name, publication_year)
book = Book.from_updated(book, dict(publication_year=publication_year))
LOG.info('Done.')
示例7: set_page_added_on
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def set_page_added_on(book_id):
"""Set the book.page_added_on value
Args:
book_id: integer, id of book
"""
book = Book.from_id(book_id)
LOG.debug('Checking book: %s', book.name)
max_created_on = db.book_page.created_on.max()
query = (db.book_page.book_id == book.id)
rows = db(query).select(max_created_on)
if not rows:
return
page_added_on = rows[0][max_created_on]
if page_added_on:
LOG.debug('Updating book: %s %s', book.name, page_added_on)
book = Book.from_updated(book, dict(page_added_on=page_added_on))
示例8: archive
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def archive(book, base_path='applications/zcomx/private/var'):
"""Create a cbz file for an book and archive it.
Args:
book: Book instance
base_path: location of cbz archive
Return:
string, path to cbz file.
"""
creator = Creator.from_id(book.creator_id)
cbz_creator = CBZCreator(book)
cbz_file = cbz_creator.run()
cbz_archive = CBZArchive(base_path=base_path)
subdir = cbz_archive.get_subdir_path(creator_name(creator, use='file'))
dst = os.path.join(subdir, os.path.basename(cbz_file))
archive_file = cbz_archive.add_file(cbz_file, dst)
book = Book.from_updated(book, dict(cbz=archive_file))
return archive_file
示例9: test__applies
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def test__applies(self):
creator = self.add(Creator, dict(email='[email protected]'))
creator_2 = self.add(Creator, dict(email='[email protected]'))
book = self.add(Book, dict(
name='test__applies',
creator_id=creator.id,
book_type_id=1,
release_date=datetime.date(2014, 12, 31),
))
barrier = DupeNameBarrier(book)
self.assertFalse(barrier.applies())
dupe_data = dict(
name=book.name, # same
creator_id=book.creator_id, # same
book_type_id=book.book_type_id + 1, # not same
release_date=datetime.date(1990, 12, 31), # not None
)
book_2 = self.add(Book, dict(dupe_data))
self.assertTrue(barrier.applies())
# Change each field one a time to see test that if changed, the
# record is no longer a dupe.
not_dupe_data = dict(
name=book.name + '_',
creator_id=creator_2.id,
book_type_id=book.book_type_id,
release_date=None
)
for k, v in not_dupe_data.items():
data = dict(dupe_data)
data[k] = v
book_2 = Book.from_updated(book_2, data)
self.assertFalse(barrier.applies())
示例10: main
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
def main():
"""Main processing."""
usage = '%prog [options] book_id'
parser = OptionParser(usage=usage, version=VERSION)
parser.add_option(
'-f', '--force',
action='store_true', dest='force', default=False,
help='Post regardles if book post_ids exist.',
)
parser.add_option(
'--facebook',
action='store_true', dest='facebook', default=False,
help='Post only on facebook.',
)
parser.add_option(
'--man',
action='store_true', dest='man', default=False,
help='Display manual page-like help and exit.',
)
parser.add_option(
'--tumblr',
action='store_true', dest='tumblr', default=False,
help='Post only on tumblr.',
)
parser.add_option(
'--twitter',
action='store_true', dest='twitter', default=False,
help='Post only on twitter.',
)
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)
LOG.debug('Starting')
book_id = args[0]
book = Book.from_id(book_id)
creator = Creator.from_id(book.creator_id)
services = []
if options.facebook:
services.append('facebook')
if options.tumblr:
services.append('tumblr')
if options.twitter:
services.append('twitter')
if not options.facebook and not options.tumblr and not options.twitter:
services = ['facebook', 'tumblr', 'twitter']
for social_media_service in services:
LOG.debug('Posting to: %s', social_media_service)
poster = SocialMediaPoster.class_factory(social_media_service)
try:
post_id = poster.post(book, creator)
except SocialMediaPostError as err:
post_id = None
LOG.error(
'Social media post (%s) failed for book: %s - %s',
social_media_service,
book.id,
book.name
)
if err:
LOG.error(err)
if post_id:
field = '{s}_post_id'.format(s=social_media_service)
data = {field: post_id}
book = Book.from_updated(book, data)
LOG.debug('Done')
示例11: test__route
# 需要导入模块: from applications.zcomx.modules.books import Book [as 别名]
# 或者: from applications.zcomx.modules.books.Book import from_updated [as 别名]
#.........这里部分代码省略.........
suggestion_labels,
['Cartoonist page:', 'Book page:', 'Read:']
)
# Urls will be random creator/book/read. Look for expected patterns.
local_domain = 'http://127.0.0.1:8000'
for count, suggestion_url in enumerate(suggestion_urls):
self.assertTrue(suggestion_url.startswith(local_domain))
relative_url = suggestion_url.replace(local_domain, '').lstrip('/')
parts = relative_url.split('/')
self.assertTrue(len(parts), count + 1)
# Creator as integer (creator_id) should redirect.
self.assertEqual(len(self._book_views(self._book.id)), 0)
request_vars.creator = str(self._creator.id)
expect = Storage({
'redirect': '/FirstLast',
})
do_test(request_vars, expect)
# Creator as name
self.assertEqual(len(self._book_views(self._book.id)), 0)
request_vars.creator = 'FirstLast'
expect = Storage({
'view_dict_keys': self._keys_for_view['creator'],
'view': 'creators/creator.html',
})
do_test(request_vars, expect)
# Book as name
self.assertEqual(len(self._book_views(self._book.id)), 0)
request_vars.creator = 'FirstLast'
request_vars.book = 'MyBook'
expect = Storage({
'view_dict_keys': self._keys_for_view['book'],
'view': 'books/book.html',
})
do_test(request_vars, expect)
# Book page: slider
request_vars.creator = 'FirstLast'
request_vars.book = 'MyBook'
request_vars.page = '001'
expect = Storage({
'view_dict_keys': self._keys_for_view['reader'],
'view': 'books/slider.html',
})
self.assertEqual(len(self._book_views(self._book.id)), 0)
do_test(request_vars, expect)
views = self._book_views(self._book.id)
self.assertEqual(len(views), 1)
for obj in views:
self._objects.append(obj)
# Book page: scroller
self._book = Book.from_updated(self._book, dict(reader='scroller'))
expect = Storage({
'view_dict_keys': self._keys_for_view['reader'],
'view': 'books/scroller.html',
})
do_test(request_vars, expect)
views = self._book_views(self._book.id)
self.assertEqual(len(views), 2)
for obj in views:
self._objects.append(obj)
self._book = Book.from_updated(self._book, dict(reader='slider'))
# Book page image
request_vars.page = '001.jpg'
expect = Storage({
'view_dict_keys': self._keys_for_view['page_image'],
'view': 'books/page_image.html'
})
do_test(request_vars, expect)
# Nonexistent creator
request_vars.creator = str(9999999)
expect_not_found = Storage({
'view_dict_keys': self._keys_for_view['page_not_found'],
'view': 'errors/page_not_found.html',
})
do_test(request_vars, expect_not_found)
request_vars.creator = '_Invalid_Creator_'
do_test(request_vars, expect_not_found)
# Nonexistent book
request_vars.creator = 'FirstLast'
request_vars.book = 'Some_Invalid_Book'
do_test(request_vars, expect_not_found)
# Nonexistent book page
request_vars.creator = 'FirstLast'
request_vars.book = 'MyBook'
request_vars.page = '999.jpg'
do_test(request_vars, expect_not_found)
request_vars.page = '999'
do_test(request_vars, expect_not_found)