diff --git a/registries.xml b/registries.xml
index c104701..8dd79b3 100644
--- a/registries.xml
+++ b/registries.xml
@@ -18,6 +18,16 @@ second):
List of redundants (subtags redundant with other subtags)
+As HTML:
+
+
As XML :
- According to this schema
diff --git a/search.py b/search.py
index f626d8c..31e4d24 100755
--- a/search.py
+++ b/search.py
@@ -13,11 +13,16 @@ import psycopg2
from yattag import Doc
PORT = 4000
+#REDIRECTION_URL = "file:///home/stephane/src/Language-tags/GaBuZoMeu/registry-html" # Firefox does not accept a redirect to a file
+REDIRECTION_URL = "https://www.langtag.net/registries/registry-html"
-def pack(start_response, status, data):
+def pack(start_response, status, data, headers = []):
datae = data.encode() # Always encode to UTF-8
- response_headers = [("Content-type", "text/plain; charset=UTF-8"),
+ response_headers = [("Content-type", "text/plain; charset=UTF-8"), # TODO allows the type HTML
("Content-Length", str(len(datae)))]
+ if headers != []:
+ for header in headers:
+ response_headers.append(header)
start_response(status, response_headers)
return [datae]
@@ -33,6 +38,7 @@ def application(environ, start_response):
body = environ["wsgi.input"].read(body_size)
query = urllib.parse.parse_qsl(body.decode())
form = {}
+ headers = []
for q in query:
form[q[0]] = q[1]
for mandatory in ["string", "what"]:
@@ -53,8 +59,11 @@ def application(environ, start_response):
cursor.execute(sql, (term, ))
mytuple = cursor.fetchone()
status = "200 OK"
- if mytuple is not None:
- output = "TODO %s\r\n" % str(mytuple) # TODO display comments, preferredscript, addition date etc Or a redirect to mulhtml's result?
+ if mytuple is not None:
+ status = "308 Redirect"
+ url = "%s/%s/%s.html" % (REDIRECTION_URL, form["what"], mytuple[1])
+ headers.append(("Location", url))
+ output = "Redirect to %s\r\n" % (url)
else:
if form["what"] == "language":
sql = "SELECT * FROM Languages,Descriptions_Languages,Descriptions WHERE Descriptions_Languages.description = Descriptions.id AND Descriptions_Languages.lang = Languages.code AND position(%s in lower(Descriptions.description)) > 0;"
@@ -64,13 +73,11 @@ def application(environ, start_response):
found = False
output = ""
for tuple in cursor.fetchall():
- output += "TODO %s\r\n" % str(tuple)
+ output += "TODO %s\r\n" % str(tuple) # TODO make it a HTML list
found = True
if not found:
output = "\"%s\" not found\r\n" % term
- # TODO HTML with a templating engine? Yattag, probably
- # TODO link to mulhtml results?
- return pack(start_response, status, output)
+ return pack(start_response, status, output, headers)
if __name__ == "__main__":
conn = psycopg2.connect("dbname=lsr")