Show existing depicts on browse page

This commit is contained in:
Edward Betts 2019-11-25 15:46:05 +00:00
parent a2aa063dd5
commit 2cbc88a947
3 changed files with 31 additions and 4 deletions

View file

@ -83,6 +83,7 @@ def build_browse_item_map(bindings):
item = {
'image_filename': image_filename,
'date': d,
'depicts': row['depictsList']['value'].split('|'),
}
if artist_name:
item['artist_name'] = artist_name
@ -103,6 +104,7 @@ def build_browse_item_map(bindings):
artist_names = []
labels = set()
when = None
depicts = []
for item in items:
if 'title' in item:
lang, title = item['title']
@ -115,6 +117,9 @@ def build_browse_item_map(bindings):
labels.add(item['label'])
if when is None and item.get('date'):
when = item['date']
for d in item['depicts']:
if d not in depicts:
depicts.append(d)
item = {
'qid': f'Q{item_id}',
@ -122,6 +127,7 @@ def build_browse_item_map(bindings):
'image_filename': list(filenames),
'artist_name': ', '.join(artist_names),
'date': when,
'depicts': depicts,
}
if artist_names:
item['artist_name'] = ', '.join(artist_names)

View file

@ -56,6 +56,11 @@
<h5 class="card-title">{{ item.label }}</h5>
<p class="card-text">by {{ item.artist_name }}
{% if item.date %}({{ item.date }}){% endif %}
<div>
{% for depicts_label in item.depicts %}
<span class="badge badge-primary">{{ depicts_label }}</span>
{% endfor %}
</div>
</p>
</div>
</div>

View file

@ -1,6 +1,16 @@
select ?item ?itemLabel ?image ?artist ?artistLabel ?title ?titleLang ?time ?timeprecision {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
VALUES ?isa { {% for isa in isa_list %} wd:{{ isa }} {% endfor %} }
select ?item
?itemLabel
?image
?artist
?artistLabel
?title
?titleLang
?time
?timeprecision
(group_concat(distinct ?depictsLabel; SEPARATOR="|") as ?depictsList)
where {
service wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
values ?isa { {% for isa in isa_list %} wd:{{ isa }} {% endfor %} }
?item wdt:P31 ?isa .
{% for pid, qid in params %}
@ -17,4 +27,10 @@ select ?item ?itemLabel ?image ?artist ?artistLabel ?title ?titleLang ?time ?tim
BIND(LANG(?title) as ?titleLang)
}
OPTIONAL { ?item wdt:P170 ?artist }
}
OPTIONAL {
?item wdt:P180 ?depicts .
?depicts rdfs:label ?depictsLabel .
FILTER(LANG(?depictsLabel) = "en").
}
} group by ?item ?itemLabel ?image ?artist ?artistLabel
?title ?titleLang ?time ?timeprecision