本文整理汇总了Python中applications.zcomx.modules.creators.Creator.from_key方法的典型用法代码示例。如果您正苦于以下问题:Python Creator.from_key方法的具体用法?Python Creator.from_key怎么用?Python Creator.from_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类applications.zcomx.modules.creators.Creator
的用法示例。
在下文中一共展示了Creator.from_key方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_test_random
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_key [as 别名]
def do_test_random(request_vars):
"""Run test."""
self._request.vars = request_vars
router = Router(db, self._request, auth)
router.page_not_found()
self.assertTrue('urls' in router.view_dict)
self.assertTrue('suggestions' in router.view_dict['urls'])
labels = [
x['label'] for x in router.view_dict['urls']['suggestions']]
self.assertEqual(
labels,
['Cartoonist page:', 'Book page:', 'Read:']
)
self.assertEqual(
router.view_dict['urls']['invalid'],
'http://www.domain.com/path/to/page'
)
self.assertEqual(router.view, 'errors/page_not_found.html')
book_url = router.view_dict['urls']['suggestions'][1]['url']
# http://127.0.0.1:8000/FirstLast/MyBook
unused_scheme, _, unused_url, creator_for_url, book_for_url = \
book_url.split('/')
got = Creator.from_key(dict(
name_for_url=urllib.unquote(creator_for_url)))
self.assertTrue(got)
got = Book.from_key(dict(
name_for_url=urllib.unquote(book_for_url)))
self.assertTrue(got)
self.assertTrue(got.release_date is not None)
示例2: test__validate
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_key [as 别名]
def test__validate(self):
email = '[email protected]'
email_2 = '[email protected]'
error_msg = 'is_not_in_db_scrubbed error'
def rm_underscore_two(text):
"""Remove '_2' from given string."""
return text.replace('_2', '')
def rm_b(text):
"""Remove 'b' from given string."""
return text.replace('b', '')
db.creator.insert(email=email)
db.commit()
creator = Creator.from_key(dict(email=email))
self.assertTrue(creator)
self.assertEqual(creator.email, email)
self._objects.append(creator)
tests = [
#(email, scrub_callback, expect)
(email, None, error_msg), # In db, so not ok
(email_2, None, None), # Not in db, so ok
(email.upper(), None, error_msg), # lowercase in db, not ok
(email_2.upper(), None, None), # Not in db, so ok
(email, 'a_str', error_msg), # Not callable, like None
(email_2, 'a_str', None), # Not callable, like None
(email, rm_underscore_two, error_msg), # Doesn't change, in db, not ok
(email_2, rm_underscore_two, error_msg), # becomes email, in db, not ok
(email_2.upper(), rm_underscore_two, error_msg), # becomes email, in db, not ok
(email, rm_b, None), # becomes unique, so ok
(email_2, rm_b, None), # becomes unique, so ok
]
for t in tests:
if t[2] is None:
expect = t[1](t[0]) \
if t[1] is not None and callable(t[1]) else t[0]
self.assertEqual(
IS_NOT_IN_DB_SCRUBBED(
db,
db.creator.email,
error_message=error_msg,
scrub_callback=t[1],
).validate(t[0]),
expect
)
else:
self.assertRaises(
ValidationError,
IS_NOT_IN_DB_SCRUBBED(
db,
db.creator.email,
error_message=error_msg,
scrub_callback=t[1],
).validate,
t[0]
)
示例3: wrapper
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_key [as 别名]
def wrapper(*a, **b):
"""Wrapped function."""
auth = current.app.auth
if not auth.is_impersonating():
redirect_url = URL(c='login', f='agree_to_terms')
try:
creator = Creator.from_key(dict(auth_user_id=auth.user_id))
except LookupError:
return redirect(redirect_url)
else:
if not creator.agreed_to_terms:
return redirect(redirect_url)
return action(*a, **b)
示例4: setUpClass
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_key [as 别名]
def setUpClass(cls):
# C0103: *Invalid name "%%s" (should match %%s)*
# pylint: disable=C0103
# Get the data the tests will use.
email = web.username
query = (db.auth_user.email == email)
cls._user = db(query).select(limitby=(0, 1)).first()
if not cls._user:
raise SyntaxError('No user with email: {e}'.format(e=email))
cls._creator = Creator.from_key(dict(auth_user_id=cls._user.id))
if not cls._creator:
raise SyntaxError('No creator with email: {e}'.format(e=email))
query = db.book.creator_id == cls._creator.id
cls._book = Book.from_query(query)
if not cls._book:
raise SyntaxError('No book for creator with email: {e}'.format(
e=email))
cls._server_ip = web.server_ip()
示例5: route
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_key [as 别名]
#.........这里部分代码省略.........
except LookupError:
pass
else:
urls.suggestions.append({
'label': 'Book torrent:',
'url': book_torrent_url(book, host=True),
})
response.view = 'errors/page_not_found.html'
message = 'The requested torrent was not found on this server.'
return dict(urls=urls, message=message)
if not request.vars:
return page_not_found()
if not request.vars.torrent:
return page_not_found()
torrent_type = None
torrent_name = None
if request.vars.creator:
creator = None
# Test for request.vars.creator as creator.id
try:
int(request.vars.creator)
except (TypeError, ValueError):
pass
else:
try:
creator = Creator.from_id(request.vars.creator)
except LookupError:
creator = None
# Test for request.vars.creator as creator.name_for_url
if not creator:
name = request.vars.creator.replace('_', ' ')
try:
creator = Creator.from_key({'name_for_url': name})
except LookupError:
creator = None
if not creator:
return page_not_found()
if '{i:03d}'.format(i=creator.id) == request.vars.creator:
# Redirect to name version
c_url = creator_url(creator)
redirect_url = '/'.join([c_url, request.vars.torrent])
if request.vars.no_queue:
redirect_url += '?no_queue=' + str(request.vars.no_queue)
redirect(redirect_url)
torrent_type = 'book'
torrent_name = request.vars.torrent
else:
if request.vars.torrent == 'zco.mx.torrent':
torrent_type = 'all'
else:
torrent_type = 'creator'
torrent_name = request.vars.torrent
download_vars = {'no_queue': request.vars.no_queue} \
if request.vars.no_queue else {}
if torrent_type == 'all':
redirect(
URL(c='torrents', f='download', args='all', vars=download_vars))
if torrent_type == 'creator':
query = (db.creator.torrent.like('%/{t}'.format(
t=torrent_name)))
creator = db(query).select(limitby=(0, 1)).first()
if not creator:
return page_not_found()
redirect(URL(
c='torrents',
f='download',
args=['creator', creator.id],
vars=download_vars
))
if torrent_type == 'book':
extension = '.torrent'
if torrent_name.endswith(extension):
book_name = torrent_name[:(-1 * len(extension))]
query = (db.book.creator_id == creator.id) & \
(db.book.name_for_url == book_name)
book = db(query).select(limitby=(0, 1)).first()
if not book or not book.torrent:
return page_not_found()
redirect(URL(
c='torrents',
f='download',
args=['book', book.id],
vars=download_vars
))
return page_not_found()
示例6: route
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_key [as 别名]
#.........这里部分代码省略.........
})
book_row = db(db.book).select(
orderby='<random>', limitby=(0, 1)).first()
try:
book = Book.from_id(book_row.id)
except LookupError:
pass
else:
urls.suggestions.append({
'label': 'Book rss:',
'url': book_rss_url(book, host=True),
})
response.view = 'errors/page_not_found.html'
message = 'The requested rss feed was not found on this server.'
return dict(urls=urls, message=message)
if not request.vars:
return page_not_found()
if not request.vars.rss:
return page_not_found()
rss_type = None
rss_name = None
if request.vars.creator:
creator = None
# Test for request.vars.creator as creator.id
try:
int(request.vars.creator)
except (TypeError, ValueError):
pass
else:
try:
creator = Creator.from_id(request.vars.creator)
except LookupError:
creator = None
# Test for request.vars.creator as creator.name_for_url
if not creator:
name = request.vars.creator.replace('_', ' ')
try:
creator = Creator.from_key({'name_for_url': name})
except LookupError:
creator = None
if not creator:
return page_not_found()
if '{i:03d}'.format(i=creator.id) == request.vars.creator:
# Redirect to name version
c_url = creator_url(creator)
redirect_url = '/'.join([c_url, request.vars.rss])
redirect(redirect_url)
rss_type = 'book'
rss_name = request.vars.rss
else:
if request.vars.rss == 'zco.mx.rss':
rss_type = 'all'
else:
rss_type = 'creator'
rss_name = request.vars.rss
if rss_type == 'all':
rss_channel = channel_from_type('all')
response.view = 'rss/feed.rss'
return rss_channel.feed()
extension = '.rss'
if rss_type == 'creator':
creator_name = rss_name
if rss_name.endswith(extension):
creator_name = rss_name[:(-1 * len(extension))]
query = (db.creator.name_for_url == creator_name)
creator = db(query).select(limitby=(0, 1)).first()
if not creator:
return page_not_found()
rss_channel = channel_from_type('creator', record_id=creator.id)
response.view = 'rss/feed.rss'
return rss_channel.feed()
if rss_type == 'book':
if rss_name.endswith(extension):
book_name = rss_name[:(-1 * len(extension))]
query = (db.book.creator_id == creator.id) & \
(db.book.name_for_url == book_name)
book = db(query).select(limitby=(0, 1)).first()
if not book:
return page_not_found()
rss_channel = channel_from_type('book', record_id=book.id)
response.view = 'rss/feed.rss'
return rss_channel.feed()
return page_not_found()
示例7: route
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_key [as 别名]
def route():
"""Parse and route cbz urls.
request.vars.creator: integer (creator id) or string (creator name)
request.vars.cbz: string name of cbz file
Examples:
?creator=123&cbz=My_Book_01_(of 01).cbz
?creator=First_Last&cbz=My_Book_01_(of 01).cbz
If request.vars.creator is an integer (creator id) the page is
redirected to the string (creator name) page.
request.vars.no_queue: boolean, if set, don't queue a logs_download job
"""
def page_not_found():
"""Handle page not found.
Ensures that during the page_not_found formatting if any
exceptions happen they are logged, and a 404 is returned.
(Then search bots, for example, see they have an invalid page)
"""
try:
return formatted_page_not_found()
except Exception:
for line in traceback.format_exc().split("\n"):
LOG.error(line)
raise HTTP(404, "Page not found")
def formatted_page_not_found():
"""Page not found formatter."""
urls = Storage({})
urls.invalid = '{scheme}://{host}{uri}'.format(
scheme=request.env.wsgi_url_scheme or 'https',
host=request.env.http_host,
uri=request.env.web2py_original_uri or request.env.request_uri
)
urls.suggestions = []
query = (db.book.cbz != None)
book_row = db(query).select(
db.book.id, orderby='<random>', limitby=(0, 1)).first()
book = Book.from_id(book_row.id)
if book:
urls.suggestions.append({
'label': 'CBZ file:',
'url': cbz_url(book, host=True),
})
response.view = 'errors/page_not_found.html'
message = 'The requested CBZ file was not found on this server.'
return dict(urls=urls, message=message)
if not request.vars:
return page_not_found()
if not request.vars.creator:
return page_not_found()
if not request.vars.cbz:
return page_not_found()
cbz_name = request.vars.cbz
creator = None
# Test for request.vars.creator as creator.id
try:
int(request.vars.creator)
except (TypeError, ValueError):
pass
else:
try:
creator = Creator.from_id(request.vars.creator)
except LookupError:
creator = None
# Test for request.vars.creator as creator.name_for_url
if not creator:
name = request.vars.creator.replace('_', ' ')
try:
creator = Creator.from_key({'name_for_url': name})
except LookupError:
creator = None
if not creator:
return page_not_found()
if '{i:03d}'.format(i=creator.id) == request.vars.creator:
# Redirect to name version
c_url = creator_url(creator)
redirect_url = '/'.join([c_url, request.vars.cbz])
if request.vars.no_queue:
redirect_url += '?no_queue=' + str(request.vars.no_queue)
redirect(redirect_url)
download_vars = {'no_queue': request.vars.no_queue} \
if request.vars.no_queue else {}
#.........这里部分代码省略.........