make item_detail a macro

This commit is contained in:
Edward Betts 2019-10-11 15:26:27 +01:00
parent 545311112b
commit a5207834e1

View file

@ -1,5 +1,24 @@
{% extends "base.html" %}
{% macro item_detail(entity) %}
{% for key, prop_label in labels.items() %}
{% set claims = 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 %}
{% endmacro %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
@ -19,22 +38,7 @@
<a href="https://www.wikidata.org/wiki/{{ item.qid }}" class="btn btn-primary">view on Wikidata</a>
</p>
{% 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 %}
{{ item_detail(item.entity) }}
</div>
</div>
</div>