From c81efa8c63d4b76d182a205ea63a3349370df411 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 15 Nov 2020 11:14:34 +0100 Subject: [PATCH] one url fixed browsethearchive and collection + related works on artwork page --- daapinterface.py | 62 ++++++++++++-------- templates/artwork.html | 101 ++++++++++++++++++++++++-------- templates/browsethearchive.html | 9 +-- 3 files changed, 122 insertions(+), 50 deletions(-) diff --git a/daapinterface.py b/daapinterface.py index d2b4096..b2b64a3 100644 --- a/daapinterface.py +++ b/daapinterface.py @@ -195,34 +195,50 @@ def zinesindex(): def artwork(): artwork_id = request.args.get('id') +# copies in collection sparql.setQuery(''' - SELECT ?work ?workLabel ?workDescription ?propLabel ?b ?bLabel ?creators ?creatorsLabel ?creatorRoles ?creatorRolesLabel ?image ?depicts ?depictsLabel ?license ?licenseLabel + SELECT ?copiesCollections ?copiesCollectionsLabel ?collection ?collectionLabel ?image WHERE { - VALUES ?work {wd:'''+artwork_id+'''} - ?work ?a ?b. - - OPTIONAL { ?work wdt:P9 ?creators. } - OPTIONAL { ?work p:P9 ?statement1. - ?statement1 ps:P9 ?creators; - pq:P49 ?creatorRoles. } - OPTIONAL { ?work wdt:P30 ?image. } - OPTIONAL { ?work p:P30 ?statement2. - ?statement2 ps:P30 ?image; - pq:P54 ?depicts; - pq:P56 ?license.} - - SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } - ?prop wikibase:directClaim ?a . -} ''') + VALUES ?work {wd:'''+artwork_id+'''} + ?work wdt:P43 ?copiesCollections. + ?copiesCollections wdt:P47 ?collection. + OPTIONAL { ?collection wdt:P30 ?image. } + SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } + } ''') sparql.setReturnFormat(JSON) - artwork = sparql.query().convert() - print(artwork) + copiesincollection = sparql.query().convert() + print(copiesincollection) + +# related works + sparql.setQuery(''' + SELECT ?relatedWorks ?relatedWorksLabel ?image ?daterelatedWorks + WHERE { + { + SELECT ?relatedWorks ?relatedWorksLabel (SAMPLE(?daterelatedWorks) AS ?daterelatedWorks) + WHERE + { VALUES ?work {wd:'''+artwork_id+'''} + ?work wdt:P44 ?relatedWorks. + OPTIONAL {?relatedWorks wdt:P13 ?daterelatedWorks.} + SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } + } + GROUP BY ?relatedWorks ?relatedWorksLabel + ORDER BY ?relatedWorksLabel + } + OPTIONAL {?relatedWorks wdt:P30 ?image.} + } ''') + sparql.setReturnFormat(JSON) + relatedworks = sparql.query().convert() + print(relatedworks) + + + # artwork_url = "https://daap.bannerrepeater.org/wiki/Item:Q92" + # artwork_title = "the human printer" + # artwork_description = "short description" + return render_template('artwork.html', copiesincollection=copiesincollection, relatedworks=relatedworks) + + - artwork_url = "https://daap.bannerrepeater.org/wiki/Item:Q92" - artwork_title = "the human printer" - artwork_description = "short description" - return render_template('artwork.html', artwork_title=artwork_title, artwork_description=artwork_description, artwork=artwork, artwork_id=artwork_id) ######################### PERSON @app.route("/person", methods=['GET']) diff --git a/templates/artwork.html b/templates/artwork.html index 4a3f6e2..1e31b6f 100644 --- a/templates/artwork.html +++ b/templates/artwork.html @@ -1,35 +1,90 @@ {% extends "layout.html" %} {% block content %} - +
+ + +
+ +
+ + +
+ + +
+ +
-
- + + +
+
Copies in collections
+ + {% for x in copiesincollection['results']['bindings'] %} +
+ +
+ {% if "image" in x %} + + + +
+ {% else %} + + + +
+ {% endif %} +
+ +
+ {{ x["collectionLabel"]["value"]}} +
+ +
+ {% endfor %}
-
- --> -
+ +
+
Related works
+ + {% for x in relatedworks['results']['bindings'] %} +
+ +
+ {% if "image" in x %} + + + +
+ {% else %} + + + +
+ {% endif %} +
+ +
+ {{ x["relatedWorksLabel"]["value"]}} +
+ +
+ {% if "daterelatedWorks" in x %} + {{ x["daterelatedWorks"]["value"] | replace("T00:00:00Z", "") }} + {% endif %} +
+
+ {% endfor %} +
- -
-Go to backend to see live data -
-
- - {% endblock content %} \ No newline at end of file diff --git a/templates/browsethearchive.html b/templates/browsethearchive.html index bfb7d50..2e61750 100644 --- a/templates/browsethearchive.html +++ b/templates/browsethearchive.html @@ -10,26 +10,27 @@
{% if "image" in x %} - +
{% else %} - +
{% endif %}
- + {{ x["workLabel"]["value"]}}
{% if "date" in x %} {{ x["date"]["value"] | replace("T00:00:00Z", "") }} + {% endif %} - {% endif %} +