From: naath Date: Sun, 30 Mar 2014 12:25:15 +0000 (+0100) Subject: improved handling of ordinary numbers and description of relations X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~naath/git?a=commitdiff_plain;h=0b221a9b9a65e8d52f530bafa5696e99332ec9c8;p=familyTree.git improved handling of ordinary numbers and description of relations --- diff --git a/cgiFiles/person.py b/cgiFiles/person.py index 84645e6..32d3807 100755 --- a/cgiFiles/person.py +++ b/cgiFiles/person.py @@ -27,7 +27,7 @@ else: if len(printMe)<10: printMe = 'sorry, no data
' else: - url = "Ancestors" + url = "Ancestors" printMe = printMe + '
' + url everyPage.good(printMe) diff --git a/familyTree/askQuestion.py b/familyTree/askQuestion.py index b9c459f..5f9b6fb 100755 --- a/familyTree/askQuestion.py +++ b/familyTree/askQuestion.py @@ -40,8 +40,9 @@ def print_tagged_query(relationship,s,t,newLine): def relationship_html(ID,ID2,newLine): if newLine=='
': relationship = common_ancestors(ID,ID2,newLine)[2] - script = "ancestors.py?ID="+ID+"&ID2="+str(ID2) - return link_Template.substitute(script = script,text = "Common ancestors") + script = "ancestors.py?ID="+str(ID)+"&ID2="+str(ID2) + url = link_Template.substitute(script = script,text = "Common ancestors") + return relationship + ' '+url + newLine else: return '' @@ -78,6 +79,19 @@ def print_tagged_name(relationship,row,newLine): out = relationship + ": " + name_html(row,html) return out + newLine + +def ordinal_numbers(number): + out = str(number) + if number==1: + out = out +'st' + elif number==2: + out = out +'nd' + elif number==3: + out = out +'rd' + else: + out = out +'th' + return out + def list_territories(newLine): s = "SELECT DISTINCT territory"\ +" FROM territories"\ @@ -102,16 +116,9 @@ def list_people(newLine): if row[2]/100!=year/100: century = row[2]/100 + 1 - out = out +newLine+ 'born in ' + str(century) + out = out +newLine+ 'born in ' - if century==21: - out = out + 'st' - elif century==2: - out = out + 'nd' - else: - out = out + 'th' - - out = out + ' century:' + newLine + out = out +ordinal_numbers(century) + ' century:' + newLine out = out + name_html(row,newLine) +newLine year = row[2] @@ -152,7 +159,7 @@ def all_ancestors(personID,newLine): while len(ancestors)>0: level = level+1 newA =[] - out = out+newLine + parent_level(level) +':' + newLine + out = out+newLine + parent_level(level,'parent') +':' + newLine for ancestor in ancestors: id = (ancestor,) for row in run_query(s,id): @@ -249,7 +256,7 @@ def common_ancestors(IDA, IDB,newLine): if a!=indexA[-1]: out = out + 'and' + newLine - out = out + parent_level(aLevels[indexA[0]]) + out = out + parent_level(aLevels[indexA[0]],'parent') if len(indexA) >1: out = out + 's' @@ -262,7 +269,7 @@ def common_ancestors(IDA, IDB,newLine): if b!=indexB[-1]: out = out + 'and' + newLine - out = out + parent_level(bLevels[indexB[0]]) + out = out + parent_level(bLevels[indexB[0]],'parent') if len(indexB)>1: out = out + 's' out = out + ' of ' + name_html([names[1],IDB],newLine)+newLine @@ -281,18 +288,12 @@ def relationship(level1, level2,names): if level1==0 and level2==0: return names[0] + ' is ' +names[1] if level1==0: - return names[0] + ' is ' + names[1] + '\'s '+ parent_level(level2) + return names[0] + ' is ' + names[1] + '\'s '+ parent_level(level2,'parent') if level2==0: - return names[1] + ' is ' + names[0] + '\'s '+ parent_level(level1) + return names[1] + ' is ' + names[0] + '\'s '+ parent_level(level1,'parent') - if level1==level2: - remove = 0 - if level1==1: - return names[0] +' and '+names[1] +' are '+' siblings' - else: - cousinNum = level1-1 - if level1>level2: + if level1>=level2: remove = level1-level2 cousinNum = level2-1 else: @@ -300,21 +301,14 @@ def relationship(level1, level2,names): cousinNum = level1-1 if cousinNum==0: - if level1< level2: - return names[0] + ' is ' + names[1] + '\'s uncle or aunt' + uaLevel = parent_level(remove,'uncle or aunt') + if level1<= level2: + return names[0] + ' is ' + names[1] + '\'s ' + uaLevel if level2