本文整理汇总了Python中applications.zcomx.modules.creators.Creator类的典型用法代码示例。如果您正苦于以下问题:Python Creator类的具体用法?Python Creator怎么用?Python Creator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Creator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_contributions_remaining
def update_contributions_remaining(book):
"""Update the contributions_remaining for the creator of the book.
Args
book: Book instance
"""
if not book:
return
data = dict(
contributions_remaining=calc_contributions_remaining(book)
)
updated_book = Book.from_updated(book, data)
if not updated_book.creator_id:
return
creator = Creator.from_id(updated_book.creator_id)
if not creator:
return
total = contributions_remaining_by_creator(creator)
if creator.contributions_remaining != total:
data = dict(contributions_remaining=total)
creator = Creator.from_updated(creator, data)
示例2: modal
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,
)
示例3: creator_torrent
def creator_torrent(creator_id):
"""Create a torrent for a creator."""
creator = Creator.from_id(creator_id)
result = CreatorTorrentCreator(creator).archive()
LOG.debug('Created: %s', result)
if creator.rebuild_torrent:
creator = Creator.from_updated(creator, dict(rebuild_torrent=False))
示例4: book_torrent
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))
示例5: test__preset_links
def test__preset_links(self):
router = Router(db, self._request, auth)
data = dict(
shop=None,
tumblr=None,
)
self._creator = Creator.from_updated(self._creator, data)
# Creator not set.
self.assertEqual(router.preset_links(), [])
# Set creator but still no presets
router.request.vars.creator = 'FirstLast'
self.assertEqual(router.preset_links(), [])
def test_presets(links, expect):
soups = [BeautifulSoup(str(x)) for x in links]
anchors = [x.find('a') for x in soups]
self.assertEqual(
[x.string for x in anchors],
expect
)
for anchor in anchors:
if anchor.string == 'shop':
self.assertEqual(anchor['href'], 'http://www.shop.com')
elif anchor.string == 'tumblr':
self.assertEqual(anchor['href'], 'http://user.tumblr.com')
self.assertEqual(anchor['target'], '_blank')
# Set creator.shop
data = dict(
shop='http://www.shop.com',
tumblr=None
)
self._creator = Creator.from_updated(self._creator, data)
router.creator = None
test_presets(router.preset_links(), ['shop'])
# Set creator.tumblr
data = dict(
shop=None,
tumblr='http://user.tumblr.com',
)
self._creator = Creator.from_updated(self._creator, data)
router.creator = None
test_presets(router.preset_links(), ['tumblr'])
# Set both creator.shop and creator.tumblr
data = dict(
shop='http://www.shop.com',
tumblr='http://user.tumblr.com',
)
self._creator = Creator.from_updated(self._creator, data)
router.creator = None
test_presets(router.preset_links(), ['shop', 'tumblr'])
示例6: tearDownClass
def tearDownClass(cls):
for job in db(db.job).select():
job.delete_record()
db.commit()
if cls._max_optimize_img_log_id:
query = (db.optimize_img_log.id > cls._max_optimize_img_log_id)
db(query).delete()
db.commit()
Creator.from_updated(cls._creator, cls._creator_as_dict)
示例7: widget
def widget():
"""Contribute widget component controller.
request.vars.book_id: id of book, optional
request.vars.creator_id: id of creator, optional
request.vars.link_type: 'button' or 'link', 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.
Notes:
This function doesnt' check if the creator is eligible for
contributions. Do this before calling.
If any errors occur, nothing is displayed.
"""
Zco().paypal_in_progress = None
book = None
creator = None
if request.vars.book_id:
book = Book.from_id(request.vars.book_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)
if book:
creator = Creator.from_id(book.creator_id)
amount = default_contribute_amount(book) if book else 1.00
paypal_vars = {}
if book:
paypal_vars['book_id'] = book.id
elif creator:
paypal_vars['creator_id'] = creator.id
link_types = ['link', 'button']
link_type = request.vars.link_type if request.vars.link in link_types \
else link_types[0]
return dict(
amount='{a:0.2f}'.format(a=amount),
paypal_vars=paypal_vars,
link_type=link_type,
)
示例8: test__url
def test__url(self):
creator = Creator(dict(email='[email protected]'))
tests = [
# (name_for_url, expect)
(None, None),
('Prince', '/Prince'),
('FirstLast', '/FirstLast'),
('firstlast', '/firstlast'),
("HélèDEñça", '/H%C3%A9l%C3%A8DE%C3%B1%C3%A7a'),
]
for t in tests:
creator.name_for_url = t[0]
self.assertEqual(url(creator), t[1])
示例9: setUpClass
def setUpClass(cls):
# C0103: *Invalid name "%%s" (should match %%s)*
# pylint: disable=C0103
# Get the data the tests will use.
cls._creator = Creator.by_email(web.username)
cls._book = Book.from_key(dict(creator_id=cls._creator.id))
cls._server_ip = web.server_ip()
示例10: cc_licence_data
def cc_licence_data(book):
"""Return data required for the cc licence for the book.
Args:
book: Book instance
Returns:
dict
"""
creator = Creator.from_id(book.creator_id)
year_list = book_pages_years(book)
if not year_list:
year_list = [datetime.date.today().year]
if len(year_list) == 1:
years = str(year_list[0])
else:
years = '{f}-{l}'.format(f=year_list[0], l=year_list[-1])
return dict(
owner=creator.name,
owner_url=creator_short_url(creator),
title=book.name,
title_url=short_url(book),
year=years,
place=book.cc_licence_place,
)
示例11: short_url
def short_url(book):
"""Return a short url for the book webpage.
Args:
book: Book instance
Returns:
string, url, eg http://101.zco.mx/My_Book_(2014)
"""
if not book:
return
name = book_name(book, use='url')
if not name:
return
try:
creator = Creator.from_id(book.creator_id)
except LookupError:
return
url_for_creator = creator_short_url(creator)
if not url_for_creator:
return
return urlparse.urljoin(url_for_creator, name)
示例12: creator_data
def creator_data(creator_id_str):
"""Return paypal data for the creator."""
try:
creator_id = int(creator_id_str)
except (TypeError, ValueError):
creator_id = None
if not creator_id:
raise LookupError('Invalid creator id: {i}'.format(
i=creator_id_str))
creator = Creator.from_id(creator_id)
if not creator.paypal_email:
raise LookupError('Creator has no paypal email, id: {i}'.format(
i=creator_id))
book = book_for_contributions(creator)
if not book:
raise LookupError(
'Creator has no book for contributions, id: {i}'.format(
i=creator_id
)
)
data = Storage({})
data.business = creator.paypal_email
data.item_name = '{c}'.format(c=creator.name)
data.item_number = book.id
return data
示例13: setUpClass
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:
msg = 'No user with email: {e}'.format(e=email)
print msg
raise SyntaxError(msg)
query = db.creator.auth_user_id == cls._user.id
cls._creator = Creator.from_query(query)
if not cls._creator:
msg = 'No creator with email: {e}'.format(e=email)
print msg
raise SyntaxError(msg)
cls._creator_as_dict = cls._creator.as_dict()
query = (db.book.creator_id == cls._creator.id) & \
(db.book.name_for_url == 'TestDoNotDelete-001')
cls._book = Book.from_query(query)
cls._book_page = get_page(cls._book, page_no='first')
id_max = db.optimize_img_log.id.max()
cls._max_optimize_img_log_id = \
db(db.optimize_img_log).select(id_max)[0][id_max]
cls._test_data_dir = os.path.join(request.folder, 'private/test/data/')
示例14: url
def url(book, **url_kwargs):
"""Return a url suitable for the book webpage.
Args:
book: Bow instance
url_kwargs: dict of kwargs for URL(). Eg {'extension': False}
Returns:
string, url, eg http://zco.mx/creators/index/First_Last/My_Book_(2014)
(routes_out should convert it to
http://zco.mx/First_Last/My_Book_(2014))
"""
if not book or not book.name:
return
creator = Creator.from_id(book.creator_id)
name_of_creator = creator_name(creator, use='url')
if not name_of_creator:
return
name = book_name(book, use='url')
if not name:
return
kwargs = {}
kwargs.update(url_kwargs)
return URL(c='creators', f='index', args=[name_of_creator, name], **kwargs)
示例15: do_test_random
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)