diff --git a/api.py b/api.py index 77dfe89bbf3be2ffa71264c2257cb3cfc640f8a8..e3b74b9826a105ae395fd82c17aa0f11c9167f23 100644 --- a/api.py +++ b/api.py @@ -108,6 +108,55 @@ def search(): return render_template('index.html', objects = merke, searchBool = True, text = text) +@app.route('/filter', methods=['GET']) +def filter(): + merke = [] + merkeLetter = [] + actorQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in distinct-values(/root/object/descriptiveMetadata/actor/text()) order by $x return $x") + for a,actor in actorQuery.iter(): + anfang = actor[0] + if (len(merkeLetter) == 0): + merkeLetter.append({"name" : anfang}) + elif anfang != merkeLetter[len(merkeLetter)-1]["name"]: + merkeLetter.append({"name" : anfang}) + merke.append({"anfang" : anfang, "name" : actor}) + + return render_template('filter.html', letters = merkeLetter, objects = merke, filter = True, text = '') + +@app.route('/filter/actor/<path:kunstler>', methods=['GET']) +def filterActor(kunstler): + text = kunstler + merke = [] + urlQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/actor[contains(text(),'" + kunstler + "')]]/bildLink/text()) return $x") + actorQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/actor[contains(text(),'" + kunstler + "')]]/descriptiveMetadata/actor/text()) return $x") + titleQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/actor[contains(text(),'" + kunstler + "')]]/descriptiveMetadata/objectIdentificationWrap/title/text()) return $x") + + urlList = [] + actorList = [] + titleList = [] + + for a,url in urlQuery.iter(): + urlList.append(url) + + for b,actor in actorQuery.iter(): + actorList.append(actor) + + for c,title in titleQuery.iter(): + titleList.append(title) + + + for i in range(0, len(urlList)): + url = urlList[i] + actor = actorList[i] + title = titleList[i] + eintrag = {"url" : url, "actor" : actor, "title" : title} + merke.append(eintrag) + + urlQuery.close() + actorQuery.close() + titleQuery.close() + + return render_template('index.html', objects = merke, searchBool = True, text = text) if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 8720509885e5d70a83812f99fec5ec511e299a40..55bd91988b111a19e9c08cbff66d0914d44be8b6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -20,7 +20,7 @@ <div class="menue"> <ul id="navibereich"> <li><a href="https://www.wikidata.org/wiki/Wikidata:Main_Page">WikiData</a></li> - <li><a href="">Filter</a></li> + <li><a href="{{ url_for('filter') }}">Filter</a></li> </ul> </div>