Show more detail on catalog page.

This commit is contained in:
Edward Betts 2019-10-10 20:52:11 +01:00
parent 66cbf3b670
commit e2c78d813d
2 changed files with 31 additions and 3 deletions

15
app.py
View file

@ -422,7 +422,7 @@ def get_labels(keys, name=None):
return {entity['id']: wikibase.get_entity_label(entity) for entity in labels} return {entity['id']: wikibase.get_entity_label(entity) for entity in labels}
def get_other(entity): def build_other_set(entity):
other_items = set() other_items = set()
for key in find_more_props.keys(): for key in find_more_props.keys():
if key not in entity['claims']: if key not in entity['claims']:
@ -430,7 +430,10 @@ def get_other(entity):
for claim in entity['claims'][key]: for claim in entity['claims'][key]:
if 'datavalue' in claim['mainsnak']: if 'datavalue' in claim['mainsnak']:
other_items.add(claim['mainsnak']['datavalue']['value']['id']) other_items.add(claim['mainsnak']['datavalue']['value']['id'])
return other_items
def get_other(entity):
other_items = build_other_set(entity)
return get_labels(other_items) return get_labels(other_items)
@app.route("/admin/edits") @app.route("/admin/edits")
@ -587,15 +590,20 @@ def catalog_page():
entities = mediawiki.get_entities_with_cache(qids) entities = mediawiki.get_entities_with_cache(qids)
items = [] items = []
other_items = set()
for entity in entities: for entity in entities:
other_items.update(build_other_set(entity))
item = { item = {
'label': wikibase.get_entity_label(entity), 'label': wikibase.get_entity_label(entity),
'qid': entity['id'], 'qid': entity['id'],
'item_id': int(entity['id'][1:]), 'item_id': int(entity['id'][1:]),
'image_filename': wikibase.first_datavalue(entity, 'P18'), 'image_filename': wikibase.first_datavalue(entity, 'P18'),
'entity': entity,
} }
items.append(item) items.append(item)
other = get_labels(other_items)
flat = '_'.join(f'{pid}={qid}' for pid, qid in params) flat = '_'.join(f'{pid}={qid}' for pid, qid in params)
thumbwidth = 400 thumbwidth = 400
cache_name = f'{flat}_{page}_{page_size}_{thumbwidth}' cache_name = f'{flat}_{page}_{page_size}_{thumbwidth}'
@ -605,7 +613,10 @@ 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']]
return render_template('catalog.html', items=items) return render_template('catalog.html',
labels=find_more_props,
items=items,
other=other)
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

@ -16,10 +16,27 @@ td { vertical-align: top; }
</td> </td>
<td> <td>
<p>{{ item.label }}</p> <p>{{ item.label }}</p>
{# <pre>{{ item | pprint }}</pre> #}
{% for key, prop_label in labels.items() %}
{% set claims = item.entity['claims'][key] %}
{% if claims %}
<div>
<strong>{{ prop_label }}</strong>:
{% for claim in claims %}
{% if 'datavalue' in claim.mainsnak %}
{% set claim_qid = claim.mainsnak.datavalue.value.id %}
<a href="https://www.wikidata.org/wiki/{{ claim_qid }}">{{ other[claim_qid] or '[ label missing ]' }}</a> ({{ claim_qid }})
{% else %}
<i>no value</i>
{% endif %}
{% endfor %}
</div>
{% endif %}
{% endfor %}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</table>
</div> </div>
{% endblock %} {% endblock %}