$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": title, "remove_dialog_html": _('Are you sure you want to remove %(title)s from your list?', title=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)
  • $_('Cover of: %(title)s', title=list.name) $list.name $if remove: [X] $if remove: from $_('You') $else: from $list.owner.displayname
  • $jsdef render_my_lists(lists, property): $for list in lists: $if list[property]:

    $list.name

    $jsdef render_already_lists(lists, user_key): $for list in lists: $if list['active']: $:show_list(list, user_key) $jsdef render_widget_add(lists, work_key, edition_key, users_work_read_status, username, pageurl, readinglogonly, use_work, user_key):
    $if edition_key and not work_key:
    $else:
    $if work_key:
    $if users_work_read_status == 3: $ message = _("Already Read") $elif users_work_read_status == 2: $ message = _("Currently Reading") $else: $ message = _("Want to Read") $if users_work_read_status: $else: $if edition_key:
    $if users_work_read_status:
    $else:
    $else: $if username:

    $_('Add to List')

    $else:

    $('Add to List')

    $jsdef render_widget_display(lists, limit, user_key): $for i, list in enumerate(lists): $if i < limit: $:show_list(list, user_key) $jsdef render_head(seed_type, page_lists, page_url): $if seed_type == "subject":

    Lists

    $_('watch for edits or export all records')
    $else:

    $if len(page_lists) > 0: $ msg = ungettext("%(count)d List", "%(count)d Lists", len(page_lists), count=len(page_lists)) $(msg) $else: $_("Lists")

    $if include_header:
    $:render_head(seed_info['type'], page_lists, page_url)
    $if include_widget: $if ctx.user or not work_key:
    $:render_widget_add(user_lists, work_key, edition_key, users_work_read_status, ctx.user, page.url(), readinglog_only, False,user_key)
    $else:
    $if work:
    $if edition_key:
    $if work: $if include_rating: $:macros.StarRatings(work, edition) $if edition: $if work.has_book_note(username, edition.key.split('/')[-1]): $ link_text = _("Update my book note") $else: $ link_text = _("Add a book note") $:macros.NotesModal(work, edition, link_text, 'cta', 'cta-section patron-metadata') $if include_showcase: $if render_once('lists/widget.remove-dialog'): $if ctx.user and render_once('lists/widget.addList'): $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']