chiark / gitweb /
Added listing by age at birth of child to web
[familyTree.git] / familyTree / askQuestion.py
index 6e9642635213f84bc4ac330d7f71103bdaadd63f..179888c62ab38b357a019de984fdad3bc27066db 100755 (executable)
@@ -63,10 +63,22 @@ def name_html(row,html):
                if html==1:
                        script = "person.py?ID=" + str(row[1])
                        name = row[0]
-                       return link_Template.substitute(script = script, text = name)
+                       return link_Template.substitute(script = script\
+                               , text = name)
                else:
                        return row[0] + "," +str(row[1])
 
+def print_age_count(row,newLine):
+       if newLine == '<br>':
+               script = "age.py?age="+str(row[0])
+               link = link_Template.substitute(script = \
+                       script, text = row[0])
+               return str(row[1]) + ' people had children at age '\
+                        + link + newLine
+       else:
+               return print_row(row,newLine)
+       
+
 def print_tagged_name(relationship,row,newLine):
        if row[0]==None:
                        out = relationship + " not yet entered: " + row[1]
@@ -134,6 +146,7 @@ def list_territories(newLine):
                out =out + terr_html(row[0],newLine) +newLine
        return out
 
+
 def list_people(newLine):
        s = "SELECT name,id,bornyear"\
        +" FROM people"\
@@ -268,7 +281,10 @@ def count_age_at_child(newLine):
                +" WHERE p1.bornYear <> 0 and p2.bornYear<>0"\
                +" GROUP BY age;"
 
-       out = print_query(s,(),newLine)
+       out = ''
+       for row in run_query(s,()):
+               out = out + print_age_count(row,newLine)
+
        return out
 
 def people_had_child_at_age(age,newLine):
@@ -279,7 +295,7 @@ def people_had_child_at_age(age,newLine):
                 +" ON parents.ID = p1.ID"\
                 +" INNER JOIN people p2"\
                 +" ON parents.parentID = p2.ID"\
-               +" WHERE age = ?"
+               +" WHERE age = ? AND p1.bornYear<>0 AND p2.bornYear<>0"
 
        t = (int(age),)