Pass in the custom list template via interface_data

This commit is contained in:
Kovid Goyal 2017-07-18 17:30:34 +05:30
parent 3e6d7c93d2
commit e62ade9d20
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 28 additions and 6 deletions

View File

@ -118,6 +118,26 @@ def get_translations():
DEFAULT_NUMBER_OF_BOOKS = 50 DEFAULT_NUMBER_OF_BOOKS = 50
def custom_list_template():
ans = getattr(custom_list_template, 'ans', None)
if ans is None:
ans = {
'thumbnail': True,
'thumbnail_height': 140,
'height': 'auto',
'comments_fields': ['comments'],
'lines': [
_('<b>{title}</b> by {authors}'),
_('{series_index} of <i>{series}</i>') + '|||{rating}',
'{tags}',
_('Date: {timestamp}') + '|||' + _('Published: {pubdate}') + '|||' + _('Publisher: {publisher}'),
'',
]
}
custom_list_template.ans = ans
return ans
def basic_interface_data(ctx, rd): def basic_interface_data(ctx, rd):
ans = { ans = {
'username': rd.username, 'username': rd.username,
@ -126,12 +146,12 @@ def basic_interface_data(ctx, rd):
for x in available_input_formats()}, for x in available_input_formats()},
'gui_pubdate_display_format': tweaks['gui_pubdate_display_format'], 'gui_pubdate_display_format': tweaks['gui_pubdate_display_format'],
'gui_timestamp_display_format': tweaks['gui_timestamp_display_format'], 'gui_timestamp_display_format': tweaks['gui_timestamp_display_format'],
'gui_last_modified_display_format': 'gui_last_modified_display_format': tweaks['gui_last_modified_display_format'],
tweaks['gui_last_modified_display_format'],
'use_roman_numerals_for_series_number': get_use_roman(), 'use_roman_numerals_for_series_number': get_use_roman(),
'translations': get_translations(), 'translations': get_translations(),
'icon_map': icon_map(), 'icon_map': icon_map(),
'icon_path': ctx.url_for('/icon', which=''), 'icon_path': ctx.url_for('/icon', which=''),
'custom_list_template': getattr(ctx, 'custom_list_template', None) or custom_list_template(),
} }
ans['library_map'], ans['default_library_id'] = ctx.library_info(rd) ans['library_map'], ans['default_library_id'] = ctx.library_info(rd)
return ans return ans

View File

@ -6,7 +6,7 @@ from __python__ import bound_methods, hash_literals
from elementmaker import E from elementmaker import E
from gettext import gettext as _ from gettext import gettext as _
from book_list.details_list import THUMBNAIL_MAX_HEIGHT, sandbox_css, BORDER_RADIUS from book_list.details_list import sandbox_css, BORDER_RADIUS
from book_list.library_data import library_data from book_list.library_data import library_data
from date import format_date from date import format_date
from dom import build_rule, clear, set_css, svgicon from dom import build_rule, clear, set_css, svgicon
@ -15,7 +15,7 @@ from utils import fmt_sidx, safe_set_inner_html, sandboxed_html
CUSTOM_LIST_CLASS = 'book-list-custom-list' CUSTOM_LIST_CLASS = 'book-list-custom-list'
ITEM_CLASS = CUSTOM_LIST_CLASS + '-item' ITEM_CLASS = CUSTOM_LIST_CLASS + '-item'
DESCRIPTION = _('A customizable list') DESCRIPTION = _('A customizable list (see Preferences->Sharing over the net->Book list template)')
def custom_list_css(): def custom_list_css():
ans = '' ans = ''
@ -37,10 +37,11 @@ def custom_list_css():
def default_template(): def default_template():
# Should never actually be needed
if not default_template.ans: if not default_template.ans:
default_template.ans = { default_template.ans = {
'thumbnail': True, 'thumbnail': True,
'thumbnail_height': THUMBNAIL_MAX_HEIGHT, 'thumbnail_height': 140,
'height': 'auto', 'height': 'auto',
'comments_fields': v"['comments']", 'comments_fields': v"['comments']",
'lines': [ 'lines': [
@ -263,7 +264,7 @@ def on_img_load(img, load_type):
def create_item(book_id, metadata, create_image, show_book_details): def create_item(book_id, metadata, create_image, show_book_details):
template = default_template() template = get_interface_data().custom_list_template or default_template()
text_data = render_template_text(template, book_id, metadata) text_data = render_template_text(template, book_id, metadata)
text_data.style.flexGrow = '10' text_data.style.flexGrow = '10'
text_data.style.overflow = 'hidden' text_data.style.overflow = 'hidden'

View File

@ -165,6 +165,7 @@ default_interface_data = {
'library_map': None, 'library_map': None,
'icon_map': {}, 'icon_map': {},
'icon_path': '', 'icon_path': '',
'custom_list_template': None,
} }
def get_interface_data(): def get_interface_data():