Switch to bootstrap cards for catalog page

This commit is contained in:
Edward Betts 2019-10-10 21:00:13 +01:00
parent e2c78d813d
commit 1ef188fa06
2 changed files with 45 additions and 34 deletions

10
app.py
View file

@ -180,6 +180,9 @@ def property_query_page(property_id):
@app.route('/') @app.route('/')
def start(): def start():
return random_painting() return random_painting()
username = wikidata_oauth.get_username()
username = None
return render_template('start.html', username=username)
@app.route('/next') @app.route('/next')
def random_painting(): def random_painting():
@ -613,10 +616,15 @@ def catalog_page():
item['url'] = url_for('item_page', item_id=item['item_id']) item['url'] = url_for('item_page', item_id=item['item_id'])
item['image'] = detail[item['image_filename']] item['image'] = detail[item['image_filename']]
item_labels = get_labels(qid for pid, qid in params)
title = ' / '.join(find_more_props[pid] + ': ' + item_labels[qid]
for pid, qid in params)
return render_template('catalog.html', return render_template('catalog.html',
labels=find_more_props, labels=find_more_props,
items=items, items=items,
other=other) other=other,
title=title)
def get_image_detail_with_cache(items, cache_name, thumbwidth=None): def get_image_detail_with_cache(items, cache_name, thumbwidth=None):
filenames = [cur['image_filename'] for cur in items] filenames = [cur['image_filename'] for cur in items]

View file

@ -1,42 +1,45 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block style %} {% block title %}{{ title }}{% endblock %}
<style>
td { vertical-align: top; }
</style>
{% endblock %}
{% block content %} {% block content %}
<div class="p-2"> <div class="p-2">
<table> <h1>{{ self.title() }}</h1>
{% for item in items %} {% for item in items %}
<tr> <div class="card mb-3">
<td> <div class="row no-gutters">
<img src="{{ item.image.thumburl }}"> <div class="col-md-3">
</td> <img src="{{ item.image.thumburl }}" class="card-img">
<td> </div>
<p>{{ item.label }}</p> <div class="col-md-9">
<div class="card-body">
<h5 class="card-title">{{ item.label }}</h5>
{% for key, prop_label in labels.items() %} <p>
{% set claims = item.entity['claims'][key] %} <a href="https://www.wikidata.org/wiki/{{ item.qid }}" class="btn btn-primary">view on Wikidata</a>
{% if claims %} </p>
<div>
<strong>{{ prop_label }}</strong>: {% for key, prop_label in labels.items() %}
{% for claim in claims %} {% set claims = item.entity['claims'][key] %}
{% if 'datavalue' in claim.mainsnak %} {% if claims %}
{% set claim_qid = claim.mainsnak.datavalue.value.id %} <div>
<a href="https://www.wikidata.org/wiki/{{ claim_qid }}">{{ other[claim_qid] or '[ label missing ]' }}</a> ({{ claim_qid }}) <strong>{{ prop_label }}</strong>:
{% else %} {% for claim in claims %}
<i>no value</i> {% if 'datavalue' in claim.mainsnak %}
{% endif %} {% set claim_qid = claim.mainsnak.datavalue.value.id %}
{% endfor %} <a href="https://www.wikidata.org/wiki/{{ claim_qid }}">{{ other[claim_qid] or '[ label missing ]' }}</a> ({{ claim_qid }})
</div> {% else %}
{% endif %} <i>no value</i>
{% endfor %} {% endif %}
</td> {% endfor %}
</tr> </div>
{% endfor %} {% endif %}
</table> {% endfor %}
</div>
</div>
</div>
</div>
{% endfor %}
</div> </div>
{% endblock %} {% endblock %}