Record page title and endpoint with query

This commit is contained in:
Edward Betts 2019-11-27 10:00:00 +00:00
parent ff11922c35
commit b894188f1a
4 changed files with 19 additions and 12 deletions

12
app.py
View file

@ -160,6 +160,7 @@ def save(item_id):
@app.route("/property/P<int:property_id>")
def property_query_page(property_id):
pid = f'P{property_id}'
g.title = find_more_props[pid]
sort = request.args.get('sort')
sort_by_name = sort and sort.lower().strip() == 'name'
@ -189,10 +190,9 @@ def property_query_page(property_id):
has_label = sorted((row for row in rows if 'objectLabel' in row),
key=lambda row: locale.strxfrm(row['objectLabel']['value']))
rows = has_label + no_label
label = find_more_props[pid]
return render_template('property.html',
label=label,
label=g.title,
order=('name' if sort_by_name else 'count'),
pid=pid,
rows=rows)
@ -674,6 +674,9 @@ def browse_page():
item_labels = get_labels(qid for pid, qid in params)
g.title = ' / '.join(find_more_props[pid] + ': ' + item_labels[qid]
for pid, qid in params)
bindings = filter_artwork(params)
facets = get_facets(params)
@ -706,15 +709,12 @@ def browse_page():
cache_refreshed = True
item['image'] = detail[image_filename]
title = ' / '.join(find_more_props[pid] + ': ' + item_labels[qid]
for pid, qid in params)
catalog_url = url_for('catalog_page', **dict(params))
return render_template('find_more.html',
facets=facets,
prop_labels=find_more_props,
label=title,
label=g.title,
pager=pager,
params=params,
item_map=item_map,

View file

@ -111,6 +111,8 @@ class WikidataQuery(Base):
error_text = Column(String)
query_template = Column(String)
row_count = Column(Integer)
page_title = Column(String)
endpoint = Column(String)
@property
def duration(self):

View file

@ -4,7 +4,7 @@ import urllib.parse
import os
import dateutil.parser
import hashlib
from flask import request, render_template
from flask import request, render_template, g
from collections import defaultdict
from datetime import datetime
from .model import WikidataQuery
@ -47,7 +47,9 @@ def record_query(query, query_template=None):
start_time=start,
sparql_query=query,
path=request.full_path.rstrip('?'),
query_template=query_template)
query_template=query_template,
page_title=getattr(g, 'title', None),
endpoint=request.endpoint)
database.session.add(db_query)
database.session.commit()

View file

@ -15,7 +15,7 @@
</div>
<div class="row">
<div class="col-1"></div>
<div class="col-2">endpoint</div>
<div class="col-2">template</div>
<div class="col-2">when</div>
<div class="col-1">rows</div>
@ -25,7 +25,7 @@
{% for obj in q %}
<div class="border {% if obj.bad %}border-danger{% endif %} my-1 py-1">
<div class="row">
<div class="col-1"></div>
<div class="col-2">{{ obj.endpoint or '' }}</div>
<div class="col-2">
{{ obj.template or '' }}
</div>
@ -61,8 +61,11 @@
</div>
<div class="row">
<div class="col-1"></div>
<div class="col-11"><a href="{{ obj.path }}">{{ obj.path }}</a></div>
<div class="col"><a href="{{ obj.path }}">{{ obj.path }}</a></div>
</div>
<div class="row">
<div class="col">{{ obj.page_title or '' }}</div>
</div>
<div id="query_{{ obj.id }}" class="row sparql">