Browse Source

extended info on add-book page

ansible-setup-and-deploy
nberting 6 years ago
parent
commit
93bf8a6b93
  1. 3
      app/static/css/style.css
  2. 48
      app/templates/add_book.html
  3. 39
      app/templates/show_book_detail.html
  4. 13
      app/views.py

3
app/static/css/style.css

@ -83,6 +83,9 @@ border-spacing:0; /* Removes the cell spacing via CSS */
font-size: 20px;
cursor: pointer;
}
.library_table td{
padding: 5px;
}
th.headerSortUp{
background-color: #E8E8E8!important;

48
app/templates/add_book.html

@ -1,7 +1,9 @@
{% extends 'base.html' %}
{% block main %}
<div class="container">
<div class="container" style="float: left; width:50%;">
<div style="width: 98%; border-right: dashed; border-width: 1px;">
<h1 class="page-header">Add Book</h1>
{% with messages = get_flashed_messages() %}
{% if messages %}
@ -33,25 +35,59 @@
{% endfor %}
</table>
</div>
</div>
<br>
<div style="padding-left:10px;">
Category: {{ form.category(size=27, class="form-control") }}
<br>
<br>
Year published: {{ form.year_published(size=8, class="form-control") }}
<br>
<br>
<div style="width: 50%">
Add a message for future readers: {{ form.message(size=150, class="form-control") }}
<div style="width: 40%;">
Add a message for future readers: {{ form.message(size=90, class="form-control") }}
<br></div>
<br>
{{ form.file }}
{{ form.upload }}
{{ form.wish }}
</div>
</form>
</div>
<div>
<table class="library_table" id="table" style="width:30% padding:10px;" >
<thead>
<tr id="header" style="height:15px;">
<th style="width: 10%;"> <h5> Currently in the library </h5></th>
<th style="width: 20%;"></th>
</tr>
</thead>
<tbody>
<tr>
<td> Titles: </td>
<td> {{ books_all }}</td>
</tr>
<tr>
<td> Authors: </td>
<td> {{ authors_all }} </td>
</tr>
<tr>
<td> Categories: </td>
<td> {{ categories|replace('[', '')|replace(']', '') }}</td>
</tr>
<tr>
<td> Stacks: </td>
<td> {{ stacks_all|replace('[', '')|replace(']', '') }}</td>
</tr>
<tr>
<td> From the years: </td>
<td> {{earliest}} –– {{latest}}</td>
</tr>
<tr>
<td> Gaps in the collection: </td>
<td> At least {{ books_potential }} potential books missing</td>
</tr>
</tbody>
</table>
</div>
</div>
{% endblock %}

39
app/templates/show_book_detail.html

@ -5,21 +5,40 @@
<h1 class="header">{{ book.title }}</h1>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="180" onerror="if (this.src != '../uploads/cover/{{ book.cover }}') this.src = '../static/img/default_cover.gif';">
<p>Year published: {{ book.year_published }}</p>
<p>Author(s): <ul>{% for author in book.authors %}
<li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li>
<table class="library_table" id="table" style="width:50%; padding-bottom: 20px;">
<thead>
<tr id="header">
<th style="width: 150px;"></th>
<th style="width: 500px;"></th>
</tr>
</thead>
<tbody>
<tr>
<td>Year published: </td>
<td>{{ book.year_published or '––'}}</td>
</tr>
<tr>
<td> Author(s): </td>
<td>{% for author in book.authors %}
{% endfor %}</ul></p>
<a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a><br>
<p>Category: {{ book.category }}</p>
<p>Included in stack(s): <ul>{% for stack in book.stacks %}
{% endfor %}</td>
</tr>
<tr>
<td>Category: </td>
<td>{{ book.category }}</td>
</tr>
<tr>
<td>Included in stack(s): </td>
<td>{% for stack in book.stacks %}
<li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a>
<p style="font-size: 10px;"><a href="{{url_for('remove_from_stack', stackid=stack.id, bookid=book.id)}}"> Remove from stack</a></p>
<p style="font-size: 10px;"><a href="{{url_for('remove_from_stack', stackid=stack.id, bookid=book.id)}}"> Remove from stack</a>{% endfor %}</td>
</tr>
{% endfor %}</ul></p>
</tbody>
</table>
{% if book.file %}
<button id="myBtn" style= "width: 180px; font-size: 10pt;"><a> Download this {{ book.fileformat }}</a></button>

13
app/views.py

@ -200,6 +200,17 @@ def edit_book_by_id(id):
@app.route('/add-book', methods=['POST', 'GET'])
def add_book():
upload_form = UploadForm()
allbooks = db.session.query(Book).all()
books_all = len(allbooks)
allauthors = db.session.query(Author).all()
authors_all = len(allauthors)
stacks_all = [s.stack_name for s in db.session.query(Stack.stack_name)]
categories = [r.category for r in db.session.query(Book.category).distinct()]
allpotential = db.session.query(Book).filter(Book.file.contains('potential.pdf')).all()
books_potential = len(allpotential)
earliest = db.session.query(func.min(Book.year_published)).scalar()
latest = db.session.query(func.max(Book.year_published)).scalar()
if request.method == 'POST':
if upload_form.validate_on_submit():
@ -268,7 +279,7 @@ def add_book():
return redirect(url_for('show_books'))
flash_errors(upload_form)
return render_template('add_book.html', form=upload_form)
return render_template('add_book.html', form=upload_form, books_all=books_all, authors_all=authors_all, categories=categories, stacks_all=stacks_all, books_potential=books_potential, earliest=earliest, latest=latest)
# Flash errors from the form if validation fails

Loading…
Cancel
Save