chiark / gitweb /
changed URL formating to use Templates
authornaath <naath@chiark.greenend.org.uk>
Sun, 30 Mar 2014 11:32:37 +0000 (12:32 +0100)
committernaath <naath@chiark.greenend.org.uk>
Sun, 30 Mar 2014 11:32:37 +0000 (12:32 +0100)
familyTree/askQuestion.py

index 82684ac751cac6f2b1764e58c17be06e2e1833ff..b9c459f18f1a1604a5f9129e69c911095431c7d7 100755 (executable)
@@ -2,6 +2,10 @@
 
 import sqlite3
 import findYear
+from string import Template
+
+global link_Template 
+link_Template= Template("<a href = http://www.chiark.greenend.org.uk/ucgi/~naath/$script>$text</a>")
 
 def run_query(s,t):
        c = make_cursor()
@@ -32,23 +36,18 @@ def print_tagged_query(relationship,s,t,newLine):
                mine = mine + print_tagged_name(relationship,row,newLine)
        return mine
 
-def base_url():
-       return "http://www.chiark.greenend.org.uk/ucgi/~naath/"
 
 def relationship_html(ID,ID2,newLine):
        if newLine=='<br>':
                relationship = common_ancestors(ID,ID2,newLine)[2]
-               url=base_url()+"ancestors.py?ID="+ID+"&ID2="\
-               +str(ID2)
-               return relationship + ':<a href='+url+'> Common Ancestors</a>'+newLine
+               script = "ancestors.py?ID="+ID+"&ID2="+str(ID2)
+               return link_Template.substitute(script = script,text = "Common ancestors")
        else:
                return ''
 
 def terr_html(terr,newLine):
        if newLine=='<br>':
-               url =  base_url()+"territory.py?terr="
-                return '<a href ='+url + terr+'>'+terr+'</a>'          
-
+               return link_Template.substitute(script = "territory.py?terr="+terr, text=terr)
        else:
                return terr
 def name_html(row,html):
@@ -57,9 +56,9 @@ def name_html(row,html):
        elif html=='\n':
                html=0
        if html == 1:
-               url =  base_url()+"person.py?ID=" + str(row[1])
+               script = "person.py?ID=" + str(row[1])
                name = row[0]
-               return "<a href = "+url+">"+str(name)+"</a>"
+               return link_Template.substitute(script = script, text = name)
        if row[0] == None:
                return row[1]
        else: