本文整理汇总了Python中applications.zcomx.modules.creators.Creator.from_id方法的典型用法代码示例。如果您正苦于以下问题:Python Creator.from_id方法的具体用法?Python Creator.from_id怎么用?Python Creator.from_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类applications.zcomx.modules.creators.Creator
的用法示例。
在下文中一共展示了Creator.from_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modal
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator 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,
)
示例2: widget
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
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,
)
示例3: update_contributions_remaining
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
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)
示例4: short_url
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
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)
示例5: url
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
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)
示例6: cbz_url
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
def cbz_url(book, **url_kwargs):
"""Return the url to the cbz file for the book.
Args:
book: Book instance
url_kwargs: dict of kwargs for URL(). Eg {'extension': False}
Returns:
string, url, eg
http://zco.mx/FirstLast/MyBook-001.cbz
"""
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=name_of_creator,
f='{name}.cbz'.format(name=name),
**kwargs
)
示例7: cc_licence_data
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
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,
)
示例8: creator_data
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
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
示例9: download
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator 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): one of 'all', 'book', 'creator'
request.args(1): integer, id of record if request.args(0) is 'book' or
'creator'
"""
current.session.forget(current.response)
if not request.args:
raise HTTP(404)
tor_type = request.args(0)
if tor_type not in ['all', 'book', 'creator']:
raise HTTP(404)
if tor_type in ['book', 'creator'] and not request.args(1):
raise HTTP(404)
filename = None
if tor_type == 'all':
tor_archive = TorrentArchive()
name = '.'.join([tor_archive.name, 'torrent'])
filename = os.path.join(
tor_archive.base_path,
tor_archive.category,
tor_archive.name,
name
)
elif tor_type == 'creator':
try:
creator = Creator.from_id(request.args(1))
except LookupError:
raise HTTP(404)
filename = creator.torrent
else:
try:
book = Book.from_id(request.args(1))
except LookupError:
raise HTTP(404)
filename = book.torrent
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)
示例10: widget
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
def widget():
"""Controller for rss widget (reader notifications)
request.args(0): integer, optional, id of creator.
"""
creator = None
if request.args(0):
creator = Creator.from_id(request.args(0))
books = None
if creator:
book_list = OngoingBookList(creator)
books = book_list.books()
query = (db.book.id != None) # Creators must have at least one book.
creators = db(query).select(
db.creator.id,
db.auth_user.name,
left=[
db.auth_user.on(db.auth_user.id == db.creator.auth_user_id),
db.book.on(db.book.creator_id == db.creator.id),
],
groupby=db.creator.id,
orderby=db.auth_user.name,
)
names = [x.creator.id for x in creators]
labels = [x.auth_user.name for x in creators]
fields = [
Field(
'creator_id',
type='integer',
default=creator.id if creator else 0,
requires=IS_EMPTY_OR(
IS_IN_SET(
names,
labels=labels,
zero='- - -',
)
)
),
]
form = SQLFORM.factory(
*fields,
submit_button='Submit'
)
form.custom.widget.creator_id['_class'] += ' form-control'
if form.process(keepvalues=True, message_onsuccess='').accepted:
redirect(URL(r=request, args=form.vars.creator_id))
return dict(
books=books,
creator=creator,
form=form
)
示例11: creator_torrent
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
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))
示例12: link_for_creator_torrent
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
def link_for_creator_torrent(row):
"""Return a creator torrent link suitable for grid row."""
if not row:
return ''
if 'creator' not in row or not row.creator.id or not row.creator.torrent:
return ''
creator = Creator.from_id(row.creator.id)
return creator_torrent_link(creator)
示例13: book_torrent
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator 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))
示例14: __init__
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
def __init__(self, record=None):
"""Initializer
Args:
record: Book instance
"""
super(BookRSSChannel, self).__init__(record=record)
self.book = record
self.creator = Creator.from_id(self.book.creator_id)
示例15: page_url
# 需要导入模块: from applications.zcomx.modules.creators import Creator [as 别名]
# 或者: from applications.zcomx.modules.creators.Creator import from_id [as 别名]
def page_url(
book_page,
reader=None,
embed=False,
zbr_origin=None,
**url_kwargs):
"""Return a url suitable for the reader webpage of a book page.
Args:
book_page: BookPage instance
reader: str, one of 'slider', 'scroller'
If not None, appends ?reader=<reader> to the url.
embed: if True add embed to url
zbr_origin: zco book reader origin url, used by book reader
postMessage() calles.
url_kwargs: dict of kwargs for URL(). Eg {'extension': False}
Returns:
string, url,
eg http://zco.mx/creators/index/First_Last/My_Book_(2014)/002
(routes_out should convert it to
http://zco.mx/First_Last/My_Book_(2014))/002
"""
book = Book.from_id(book_page.book_id)
creator = Creator.from_id(book.creator_id)
name_of_creator = creator_name(creator, use='url')
if not name_of_creator:
return
books_name = book_name(book, use='url')
if not books_name:
return
page_name = '{p:03d}'.format(p=book_page.page_no)
kwargs = {}
kwargs.update(url_kwargs)
url_vars = {}
if reader:
url_vars['reader'] = reader
if zbr_origin:
url_vars['zbr_origin'] = zbr_origin
url_args = []
if embed:
url_args.append('embed')
url_args.extend([name_of_creator, books_name, page_name])
return URL(
c='creators',
f='index',
args=url_args,
vars=url_vars,
**kwargs
)