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

{{page_title}}

{% if books.loan|length %}
{% else %}
{% endif %}
{{ book_form.id }} {{ book_form.csrf_token }} {% if b.parent %}
{% endif %} {% for key in keys %}
{% if key == "bals" %} {% else %} {% endif %} {% if key == "genre" %}
{% for genre in genre_list %}
{% endfor %}
{% elif key == "bals" %} {% set cnt = namespace(idx=1) %} {% for a in books[key] %} {% if cnt.idx > 1 %} {% endif %} {% set cnt.idx = cnt.idx+1 %} {% endfor %} {# if idx is still 1, then no authors - new book, just put one there - book HAS to have an author #} {% if cnt.idx == 1 %} {% else %} {% set rows=4 %} {% if key == "notes" %} {% set rows=2 %} {% endif %} {% if b.parent 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 input-group-append" )}} {% else %} {{book_form[key](class="form-control input-group-append", 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) != 'Currently Owned' %} {{ book_form.delete( class="btn btn-outline-danger col-2" )}} {% else %} {{ book_form.delete( class="btn btn-outline-danger col-2 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 books.loan|length %}
{% else %}
{% endif %} {% if b.parent %}
{{ 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 %} {% if books.loan|length %}
{% endif %}
{% endblock main_content %} {% if books.child_ref|length %} {% endif %} {% block script_content %} {% endblock script_content %}