From ee8659b357dd38501124854d990476f2dd321803 Mon Sep 17 00:00:00 2001
From: moogdo49 <moogdo49@mi.fu-berlin.de>
Date: Tue, 11 Jul 2017 10:54:59 +0200
Subject: [PATCH] =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20=20=20=20=20=20=20=20?=
 =?UTF-8?q?=20=20=20=20=20api.py=20=09ge=C3=A4ndert:=20=20=20=20=20=20=20?=
 =?UTF-8?q?=20=20=20=20=20=20=20=20templates/index.html=20=09templates/fil?=
 =?UTF-8?q?ter.html?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 api.py               | 49 ++++++++++++++++++++++++++++++++++++++++++++
 templates/index.html |  2 +-
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/api.py b/api.py
index 77dfe89..e3b74b9 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 8720509..55bd919 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>
 
-- 
GitLab