changes to annotations again

This commit is contained in:
ange 2018-06-13 14:34:15 +02:00
parent f75bd69d37
commit 389de3ecad
4 changed files with 52 additions and 46 deletions

View File

@ -57,19 +57,20 @@ def get_annot_results(annot,name):
return res return res
def get_annot_book(annot,name): def get_annot_book(annot,name):
bannot=[] res=[]
annot=get_annotations()
for item in annot['rows']: for item in annot['rows']:
if 'selector' in item['target'][0]: if 'selector' in item['target'][0]:
if len(item['target'][0]['selector'])>2: if len(item['target'][0]['selector'])>2:
if name==item['uri']: string=item['uri']
if name==string.replace('http://localhost:8080/uploads/',''):
data={'text': item['text'],'extract':item['target'][0]['selector'][2]['exact'],'title':item['document']['title'], 'url':item['uri']} data={'text': item['text'],'extract':item['target'][0]['selector'][2]['exact'],'title':item['document']['title'], 'url':item['uri']}
bannot.append(data) res.append(data)
else: else:
if name in item['uri']: string=item['uri']
if name==string.replace('http://localhost:8080/uploads/',''):
data={'text': item['text'],'extract':item['target'][0]['selector'][1]['exact'],'title':item['document']['title'], 'url':item['uri']} data={'text': item['text'],'extract':item['target'][0]['selector'][1]['exact'],'title':item['document']['title'], 'url':item['uri']}
bannot.append(data) res.append(data)
return bannot return res

View File

@ -18,7 +18,6 @@
{% for row in res %} {% for row in res %}
{%for book in books%} {%for book in books%}
{%if book.file == row.url|replace('http://localhost:8080/uploads/','')%} {%if book.file == row.url|replace('http://localhost:8080/uploads/','')%}
<p align="right" style="font-family:archivo narrow;font-size:10px;">Book</p> <p align="right" style="font-family:archivo narrow;font-size:10px;">Book</p>

View File

@ -66,6 +66,34 @@
</tbody> </tbody>
</table> </table>
<div align="right">
<p>Annotations for <i>{{book.title}}</i>:</p>
{% for row in res%}
<p style="font-family:archivo narrow;font-size:8px;">Extract</p>
<div style="font-family:archivo narrow;font-family:archivo narrow;font-size:16px;">
<i>"{{ row.extract }}"</i></div><br>
<p style="font-family:archivo narrow;font-size:8px;color:#ff3300;">Annotation</p>
{%if 'https://www.youtube.com'in row.text %}
<a style="font-family:archivo narrow;font-size:16px;color:#ff3300;" href="{{row.text}}">{{row.text}}</a><br>
<hr>
{%elif '.jpg' in row.text%}
<img src="{{row.text}}" alt="" width="400">
<hr>
{%else%}
<div style="font-family:archivo narrow;font-size:16px;color:#ff3300;">{{row.text}}</div><br>
<hr>
{% endif %}
{% endfor %}
</div>
<br> <br>
<br> <br>
<p>Instances:</p> <p>Instances:</p>
@ -88,6 +116,11 @@
<br> <br>
{% if book.file %} {% if book.file %}
<button id="myBtn" style= "width: 180px; font-size: 10pt;"><a> Download this {{ book.fileformat }}</a></button> <button id="myBtn" style= "width: 180px; font-size: 10pt;"><a> Download this {{ book.fileformat }}</a></button>
<div id="myModal" class="modal"> <div id="myModal" class="modal">
@ -114,30 +147,7 @@
{% for row in bannot %}
{%for book in books%}
{%if book.file == row.uri%}
<a href="books/{{book.id}}"><p align="right" style="font-family:archivo narrow;font-size:12px;">{{book.title}}</p></a><br>
{% endif %}
{% endfor %}
<p align="right" style="font-family:archivo narrow;font-size:14px;">{{row.title}}</p><br>
<p style="font-family:archivo narrow;font-size:8px;">Extracts:</p>
<div style="font-family:archivo narrow;font-family:archivo narrow;font-size:18px;">
<i>"{{ row.extract }}"</i></div><br>
<p style="font-family:archivo narrow;font-size:8px;color:#ff3300;">Annotations:</p>
{%if 'https://www.youtube.com'in row.text %}
<a style="font-family:archivo narrow;font-size:18px;color:#ff3300;" href="{{row.text}}">{{row.text}}</a><br>
<hr>
{%elif '.jpg' in row.text%}
<img src="{{row.text}}" alt="" width="400">
<hr>
{%else%}
<div style="font-family:archivo narrow;font-size:18px;color:#ff3300;">{{row.text}}</div><br>
<hr>
{% endif %}
{%endfor%}
{% endblock %} {% endblock %}

View File

@ -154,6 +154,12 @@ def show_book_by_id(id):
if id == edge: if id == edge:
nextbook = None nextbook = None
name= book.file
annot = get_annotations()
res = get_annot_book(annot,name)
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
@ -165,17 +171,10 @@ 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, previousbook = previousbook, nextbook = nextbook, all_instances=all_instances) return render_template('show_book_detail.html', book=book, previousbook = previousbook, nextbook = nextbook, all_instances=all_instances, name=name, annot=annot, res=res)
@app.route('/books/<int:id>/annotations', methods=['POST', 'GET'])
def book_annot():
books = db.session.query(Book).all()
name=book.file
annot = get_annotations()
res = get_annot_book(annot,name)
return redirect(url_for('show_book_detail'), name=name, annot=annot, res=res, books=books)
@app.route('/books/<int:id>/delete', methods=['POST', 'GET']) @app.route('/books/<int:id>/delete', methods=['POST', 'GET'])
@ -593,13 +592,10 @@ def search_results(searchtype, query, viewby):
@app.route('/search_annot', methods=['POST', 'GET']) @app.route('/search_annot', methods=['POST', 'GET'])
def search_annot(): def search_annot():
books = db.session.query(Book).all() books = db.session.query(Book).all()
if request.method=='POST': name=str(request.args.get('query'))
return redirect (url_for('annotations')) annot = get_annotations()
else: res = get_annot_results(annot,name)
name=str(request.args.get('query')) return render_template('results_annot.html', name=name, annot=annot, res=res, books=books)
annot = get_annotations()
res = get_annot_results(annot,name)
return render_template('results_annot.html', name=name, annot=annot, res=res, books=books)
@app.route('/add_to_stack/<int:id>', methods=['GET', 'POST']) @app.route('/add_to_stack/<int:id>', methods=['GET', 'POST'])