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,9 +1,28 @@
{% extends "base.html" %} {% 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 title %}{{ title }}{% endblock %}
{% block content %} {% block content %}
<div class="p-2"> <div class="p-2">
<h1>{{ self.title() }}</h1> <h1>{{ self.title() }}</h1>
{% for item in items %} {% for item in items %}
<div class="card mb-3"> <div class="card mb-3">
@ -19,27 +38,12 @@
<a href="https://www.wikidata.org/wiki/{{ item.qid }}" class="btn btn-primary">view on Wikidata</a> <a href="https://www.wikidata.org/wiki/{{ item.qid }}" class="btn btn-primary">view on Wikidata</a>
</p> </p>
{% for key, prop_label in labels.items() %} {{ item_detail(item.entity) }}
{% 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 %}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% endblock %} {% endblock %}