$def with (page, include_rating=True, include_header=True, include_widget=True, include_showcase=True, user_lists_only=False, readinglog_only=False, read_status=None, rating=None, _user_lists=None)
$ edition = page if page.key.startswith("/books/") else None
$ work = (page.works and page.works[0]) if page.key.startswith("/books/") else page if page.key.startswith("/works/") else None
$ work_key = work and work.key
$ edition_key = edition and edition.key
$ username = ctx.user and ctx.user.key.split('/')[-1]
$ users_work_read_status = read_status or work.get_users_read_status(username) if work and username else None
$ users_work_rating = rating or work.get_users_rating(username) if work and username else None
$ uid = str(random.randint(1000, 9999))
$ container_id = 'widget-lists-wrapper-%s' % str(uid)
$if "lists" not in ctx.features:
$return
$code:
_user_lists = _user_lists or (ctx.user and ctx.user.get_lists(sort=True) or [])
def get_seed_info(page):
"""Takes a thing, determines what type it is, and returns a seed summary"""
if page.key.startswith("/subjects/"):
seed = page.key.split("/")[-1]
if seed.split(":")[0] not in ["place", "person", "time"]:
seed = "subject:" + seed
seed = seed.replace(",", "_").replace("__", "_")
seed_type = "subject"
title = page.name
else:
seed = {"key": page.key}
if page.key.startswith("/authors/"):
seed_type = "author"
title = page.get('name', 'name missing')
elif page.key.startswith("/works"):
seed_type = "work"
title = page.get("title", "untitled")
else:
seed_type = "edition"
title = page.get("title", "untitled")
return {
"seed": seed,
"type": seed_type,
"title": websafe(title),
"remove_dialog_html": _('Are you sure you want to remove %(title)s from your list?', title=websafe(title))
}
def get_list_data(list, seed, include_cover_url=True):
d = storage({
"name": list.name or "",
"key": list.key,
"active": list.has_seed(seed),
})
if include_cover_url:
cover = list.get_cover() or list.get_default_cover()
d['cover_url'] = cover and cover.url("S") or "/images/icons/avatar_book-sm.png"
if 'None' in d['cover_url']:
d['cover_url'] = "/images/icons/avatar_book-sm.png"
owner = list.get_owner()
d['owner'] = storage(displayname=owner.displayname or "", key=owner.key)
return d
def get_user_lists(seed_info):
return [get_list_data(list, seed_info['seed'], include_cover_url=True) for list in _user_lists]
def get_page_lists(page, seed_info):
user_key = ctx.user and ctx.user.key
return [get_list_data(list, seed_info['seed']) for list in page.get_lists(sort=False)]
$ seed_info = get_seed_info(page)
$ work_seed_info= edition and work and get_seed_info(work)
$ user_lists = get_user_lists(seed_info)
$if user_lists_only:
$ page_lists = [list for list in user_lists if list.active]
$else:
$ page_lists = get_page_lists(page, seed_info)
$ user_key = ctx.user and ctx.user.key
$ page_url = page.url()
$var page_lists = page_lists
$jsdef show_list(list, user_key):
$ remove = (list.owner.key == user_key)
$if render_once('lists-api-js'):
$code:
def build_contains_dict(user_list, seeds):
result = {}
for list in user_list:
result[list.key] = {}
for seed in seeds:
if seed and list.has_seed(seed):
seed_key = seed['key'] if isinstance(seed_info['seed'], dict) else seed
result[list.key][seed_key] = True;
return result
$ default_seed_key = seed_info['seed']['key'] if isinstance(seed_info['seed'], dict) else seed_info['seed']