{% macro list_to_html_multiline(possible_list) %} {% autoescape false %} {%- if possible_list is string -%} {{ possible_list }} {%- else -%} {%- for el in possible_list -%} {%- if el is string -%} {{el}}
{% else %} {{el[1]}}
{%- endif -%} {%- endfor -%} {%- endif -%} {% endautoescape %} {% endmacro %} {# render_book_search_table - Format Gutenberg Book Search results into a table for display results - whoosh search results (format differ from typical sqlite results) offset - the index into the total result sets of the first result on this page. fn_author_to_query - function that accepts an author string an returns a query value that searches for the author class - css class for the table #} {% macro render_book_search_table(results, offset, fn_author_to_query, class='', files_exist=None) %} {% for result in results %} {% endfor %}
# {% trans %}Title{% endtrans %} {% trans %}Author{% endtrans %} {% trans %}Language{% endtrans %}
{{ loop.index + offset }} {{ list_to_html_multiline(result['title']) }} {% if files_exist != None and not files_exist(result['textId']) -%} ({% trans %}Not Available{% endtrans %}) {% endif -%} {%- for k,v in result['creator'] -%} {{ v }}
{%- endfor -%} {%- for k,v in result['contributor'] -%} {{ v }}
{%- endfor -%}
{{ list_to_html_multiline(result['language']) }}
{% endmacro %} {% macro render_book_table(books, offset, fn_author_to_query, class='') %} {% for book in books %} {% endfor %}
# {% trans %}Title{% endtrans %} {% trans %}Author{% endtrans %} {% trans %}Language{% endtrans %}
{{ loop.index + offset }} {{ book.title }} {% for c in book.gutenberg_creators -%} {{ c.creator }}
{%- endfor %} {% for c in book.gutenberg_contributors -%} {{ c.contributor }}
{%- endfor %}
{% for c in book.gutenberg_languages -%} {{ c.language }} {%- endfor %}
{% endmacro %} {% macro render_author_table(authors, offset, class='') %} {% for author in authors -%} {%- endfor %}
# {% trans %}Author{% endtrans %}
{{ loop.index + offset }} {{ author.creator }}
{% endmacro %} {# record - record for book field - list of tuples of (Table Header, record_key, aux_key) class - css class name #} {% macro render_book_details(record, fields, class='') %} {% for label, key, aux_key in fields -%} {% if record[key] is string -%} {% else -%} {% for val in record[key] -%} {%- endfor -%} {%- endif -%} {%- endfor %}
{{ label }}{{ record[key] }}
{{ label }} {{ val[aux_key] }}
{% endmacro %} {# record - record for book field - list of tuples of (Table Header, record_key, aux_key) class - css class name #} {% macro render_book_files(record, fields, class='') %} {% if record['gutenberg_files']|length > 0 %} {% endif %} {% set index = 0 %} {% for f in record['gutenberg_files'] %} {% set index = index + 1 %} {%- endfor %}
{% trans %}Name{% endtrans %} {% trans %}Format{% endtrans %}
{{ f['file'] }} {{ f['format'] }}
{% endmacro %} {% macro render_book_htmlz_or_epub(htmlz_url, epub_url) %} {% if htmlz_url != None %}
{% trans %}Read{% endtrans %}
{% endif %} {% if epub_url != None %}
{% trans %}Download (EPub){% endtrans %}
{% endif %} {% endmacro %} {% macro render_pagination(pagination, endpoint_desc, query='') %} {% if pagination.pages > 1 %} {% endif %} {% endmacro %} {% macro render_flash_message() %} {% block flash_message %} {% with messages = get_flashed_messages(with_categories=True) %} {% if messages %}
{% for category, msg in messages %}
{{ msg }}
{% endfor %}
{% endif %} {% endwith %} {% endblock %} {% endmacro %}