{% extends "base.html" %} {% block main_content %} {# use tmpl-series-div as a template & keep it hidden always #} {% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}

{{page_title}}

{{ book_form.id }} {{ book_form.csrf_token }} {% if b.parent|length %}
{% endif %} {% for key in keys %}
{% if key == "genre" %}
{% for genre in genre_list %}
{% endfor %}
{% elif key == "author" %}
{% set cnt = namespace(idx=0) %} {% for objects in books[key] %}
{% if cnt.idx > 0 %}
{% endif %}
{% set cnt.idx = cnt.idx+1 %} {% endfor %} {% if cnt.idx == 0 %}
{% endif %}
{% else %}
{% set rows=4 %} {% if key == "notes" %} {% set rows=2 %} {% endif %} {% if b.parent|length and (key == 'publisher' or key == 'owned' or key == 'covertype' or key == 'condition' or key == 'blurb' ) %} {{book_form[key](class="form-control", rows=rows, disabled="disabled" )}} {# disabled fields do not come through in form post, so add hidden to make it work #} {% elif key == 'publisher' or key == 'owned' or key == 'covertype' or key == 'condition' or key == 'rating' %} {{book_form[key](class="form-select" )}} {% else %} {{book_form[key](class="form-control", rows=rows )}} {% endif %}
{% endif %}
{% endfor %}
{# putting hidden inputs in between input-groups breaks formatting, so use this var to collect them and add just before form ends #} {% set hiddens=namespace(txt='') %} {% if books.series|length %} {# empty-series-dev - filler -- we use 0 AND use that number to keep track of how many series divs for add/remove #} {% for s in books.series %} {% set hiddens.txt=hiddens.txt+"".format(loop.index, books.id) %} {% set hiddens.txt=hiddens.txt+"".format(loop.index,s.id) %}
{% if SeriesBookNum( s.id, books.id ) %} {% set hiddens.txt=hiddens.txt+"".format(loop.index, SeriesBookNum( s.id, books.id )) %} {% if books.series|length > loop.index %} {% set disabled=" disabled" %} {% else %} {% set disabled="" %} {% endif %}
Book {{ SeriesBookNum( s.id, books.id ) }} of {{s.num_books}} in  {{s.title}}
{% else %} {% set hiddens.txt=hiddens.txt+"".format(loop.index) %}
Contains books in  {{s.title}}
{% endif %} {% if books.series|length == loop.index %}
{% endif %}
{% endfor %} {% set show_div_0 = 0 %} {% else %} {# empty-series-dev - filler -- we use 0 AND use that number to keep track of how many series divs for add/remove #}
{% endif %}
{% if books.child_ref|length %}
{% endif %}

{{ book_form.submit( class="btn btn-primary offset-2 col-2" )}} {% if 'Edit' in page_title %} {% if GetOwnedById(b.owned) == 'Sold' %} {{ book_form.delete( class="btn btn-outline-danger col-2" )}} {% else %} {{ book_form.delete( class="btn btn-outline-danger col disabled", disabled="true", style="pointer-events: none;" )}} {% endif %} {% endif %}
{{ hiddens.txt|safe }}
{% if books.loan|length %}
Loaned to
{{books.loan[0].firstnames}} {{books.loan[0].surname}}

When: {{books.loan[0].date_lent}}
Contact: {{books.loan[0].contact_details}}

{% endif %}
{% if 'Edit' in page_title %}
{% if b.parent|length == 0 %}
{{ book_form.add_sub( class="btn btn-outline-success offset-2 col-2" )}}
{% else %}
{{ book_form.rem_sub( class="btn btn-outline-danger offset-2 col-3" )}}
{% endif %}
{% endif %} {% endblock main_content %} {% if books.child_ref|length %} {% block script_content %} {% endblock script_content %} {% endif %}