Browse Source

reverse query results and some new links on show_book_detail

ansible-setup-and-deploy
nberting 6 years ago
parent
commit
b8a6c86a13
  1. 5
      app/templates/results.html
  2. 5
      app/templates/results_grid.html
  3. 7
      app/templates/show_book_detail.html
  4. 24
      app/views.py

5
app/templates/results.html

@ -31,7 +31,7 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<table class="library_table" id="table" style="width:100%"> <table class="library_table" id="table" style="width:100%; padding-bottom:60px;">
<tr id="header"> <tr id="header">
<th width="70px;">Cover</th> <th width="70px;">Cover</th>
<th>Title</th> <th>Title</th>
@ -68,9 +68,10 @@
</table> </table>
</div> </div>
<br>
<div class="container" style= "border-top: dashed; border-width: 1px;" > <div class="container" style= "border-top: dashed; border-width: 1px;" >
<h2> Other books </h2> <h2> More books </h2>
<table class="library_table" id="table" style="width:100%"> <table class="library_table" id="table" style="width:100%">
<tr id="header"> <tr id="header">

5
app/templates/results_grid.html

@ -30,7 +30,7 @@
</div> </div>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<div class="grid" > <div class="grid" style="padding-bottom:60px;">
{% for book in books|sort(attribute='title', reverse = False) %} {% for book in books|sort(attribute='title', reverse = False) %}
@ -52,9 +52,8 @@
{% endfor %} {% endfor %}
</div> </div>
<div class="container" style= "border-top: dashed; border-width: 1px;"> <div class="container" style= "border-top: dashed; border-width: 1px;">
<h2> Other books </h2> <h2> More books </h2>
<div class="grid"> <div class="grid">

7
app/templates/show_book_detail.html

@ -35,7 +35,12 @@
<button style= "font-size: 10pt;"> <a href="{{ url_for('edit_book_by_id', id=book.id )}}">edit</a></button> <button style= "font-size: 10pt;"> <a href="{{ url_for('edit_book_by_id', id=book.id )}}">edit</a></button>
<button style= "font-size: 10pt;"> <a href="{{ url_for('remove_book_by_id', id=book.id)}}">delete</a></button> <button style= "font-size: 10pt;"> <a href="{{ url_for('remove_book_by_id', id=book.id)}}">delete</a></button>
<br><br>
<hr>
{% if previousbook %}
<a href="{{ url_for('show_book_by_id', id=previousbook.id )}}" style="font-size: 9pt;"> < see the previous book added to XPPL: &nbsp;<i>{{ previousbook.title |truncate(40,True,'...') }} </i></a> {% endif %}
{% if nextbook %}
<a href="{{ url_for('show_book_by_id', id=nextbook.id )}}" style="float:right; font-size: 9pt;"> see the next book added to XPPL: &nbsp;<i>{{ nextbook.title|truncate(40,True,'...')}} </i>> </a>{% endif %}
</div> </div>
{% endblock %} {% endblock %}

24
app/views.py

@ -9,6 +9,7 @@ from app import app, db, socketio, DOMAIN
from flask import Flask, Response, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort from flask import Flask, Response, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort
import json import json
from sqlalchemy.sql.expression import func, select from sqlalchemy.sql.expression import func, select
from sqlalchemy.sql import except_
from app.forms import UploadForm, EditForm, SearchForm, ChatForm, StackForm, AddtoStackForm, EditStackForm from app.forms import UploadForm, EditForm, SearchForm, ChatForm, StackForm, AddtoStackForm, EditStackForm
from app.models import Book, BookSchema, Author, AuthorSchema, Stack, StackSchema, UserIns, Chat, ChatSchema, Potential from app.models import Book, BookSchema, Author, AuthorSchema, Stack, StackSchema, UserIns, Chat, ChatSchema, Potential
from app.cover import get_cover from app.cover import get_cover
@ -105,6 +106,15 @@ def show_books_grid():
@app.route('/books/<int:id>') @app.route('/books/<int:id>')
def show_book_by_id(id): def show_book_by_id(id):
book = Book.query.get(id) book = Book.query.get(id)
previousbook = Book.query.filter_by(id=id - 1).first()
nextbook = Book.query.filter_by(id=id + 1).first()
allbooks = db.session.query(Book).all()
edge = len(allbooks)
if id == 1:
previousbook = None
if id == edge:
nextbook = None
userin = UserIns.query.filter_by(title="lastViewed").first() userin = UserIns.query.filter_by(title="lastViewed").first()
if userin != None: if userin != None:
userin.info = book.title userin.info = book.title
@ -116,7 +126,7 @@ def show_book_by_id(id):
if not book: if not book:
return render_template('red_link.html', id=id) return render_template('red_link.html', id=id)
else: else:
return render_template('show_book_detail.html', book=book) return render_template('show_book_detail.html', book=book, previousbook = previousbook, nextbook = nextbook)
@app.route('/books/<int:id>/delete', methods=['POST', 'GET']) @app.route('/books/<int:id>/delete', methods=['POST', 'GET'])
@ -399,8 +409,8 @@ def show_books():
@app.route('/search/<searchtype>/<viewby>/<query>', methods=['POST', 'GET']) @app.route('/search/<searchtype>/<viewby>/<query>', methods=['POST', 'GET'])
def search_results(searchtype, query, viewby): def search_results(searchtype, query, viewby):
search = SearchForm(request.form, search=query) search = SearchForm(request.form, search=query)
random_order=Book.query.all()
results=Book.query.filter(Book.title.contains(query)).order_by(Book.title) results=Book.query.filter(Book.title.contains(query)).order_by(Book.title)
allbooks = set(Book.query.all())
viewby = view[-1] viewby = view[-1]
if searchtype == 'Title': if searchtype == 'Title':
@ -432,14 +442,16 @@ def search_results(searchtype, query, viewby):
count = results.count() count = results.count()
whole = Book.query.count() whole = Book.query.count()
percentage = float(count / whole * 100) percentage = float(count / whole * 100)
fbooks = set(results)
books_all = allbooks - fbooks
if search.listview.data: if search.listview.data:
view.append('1') view.append('1')
return render_template('results.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage) return render_template('results.html', books=results, form=search, query=query, books_all=books_all, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
if search.grid.data: if search.grid.data:
view.append('2') view.append('2')
return render_template('results_grid.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage) return render_template('results_grid.html', books=results, form=search, query=query, books_all=books_all, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
if request.method == 'POST': if request.method == 'POST':
newmsg = 'searched for: ' + search.search.data newmsg = 'searched for: ' + search.search.data
@ -464,10 +476,10 @@ def search_results(searchtype, query, viewby):
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby))) return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby)))
if viewby == '2': if viewby == '2':
return render_template('results_grid.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage) return render_template('results_grid.html', form=search, books=results, books_all=books_all, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage)
else: else:
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage) return render_template('results.html', form=search, books=results, books_all=books_all, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage)
# ## Search - autocomplete # ## Search - autocomplete

Loading…
Cancel
Save