@@ -89,11 +89,8 @@ def serveImage(self, filename):
8989
9090 def index (self ):
9191 self .loadTemplates ()
92- return template (self .template ,
93- default_query_value = "" ,
94- in_search_checked = "" ,
95- imagetemplate = "" ,
96- textresponse = "" )
92+
93+ return self .submit_search_query ()
9794
9895 def submit_search_query (self ):
9996 self .loadTemplates ()
@@ -102,7 +99,8 @@ def getReturnTemplate(textResponse):
10299 return template (self .searchTemplate ,
103100 default_query_value1 = userInput1 or "" ,
104101 default_query_value2 = userInput2 or "" ,
105- in_search_checked = "checked" ,
102+ in_search_checked = "checked" * bool (inSearch ),
103+ case_sensitive_checked = "checked" * bool (caseSensitive ),
106104 textresponse = textResponse ).replace ("<" ,"<" ).replace (">" ,">" ).replace ('"' ,'"' ).replace ("'" ,'"' )
107105
108106 userInput1 = request .GET .get ("query_search_input1" )
@@ -123,17 +121,16 @@ def getReturnTemplate(textResponse):
123121 requestedValuesKeys = []
124122 if userInput1 :
125123 for req in map (lambda x : x .strip (), userInput1 .split ("," )):
126- if "=" not in req :
127- resp = "Problems parsing required keys! "
128- resp += "No '=' found in '%s'" % req
129- return getReturnTemplate (resp )
130124 if req .count ("=" ) > 1 :
131125 resp = "Problems parsing required keys! "
132126 resp += "More than one '=' found in '%s'" % req
133127 return getReturnTemplate (resp )
134128
135- reqKey , reqValue = req .split ("=" )
136- requiredKeyValues .append ((reqKey , reqValue ))
129+ if "=" in req :
130+ reqKey , reqValue = req .split ("=" )
131+ requiredKeyValues .append ((reqKey , reqValue ))
132+ else :
133+ requiredKeyValues .append ((req , "" ))
137134
138135 if userInput2 :
139136 for outKey in map (lambda x : x .strip (), userInput2 .split ("," )):
@@ -144,6 +141,9 @@ def getReturnTemplate(textResponse):
144141 return getReturnTemplate (resp )
145142
146143 if requiredKeyValues and requestedValuesKeys :
144+ #~ if "url" in requestedValuesKeys:
145+ #~ requestedValuesKeys.replace
146+
147147 #perform search here
148148 if inSearch :
149149 searchType = "in_search"
@@ -215,16 +215,13 @@ def getReturnTemplate(textResponse):
215215
216216 if key .lower () == "wikiurl" : #remove http:/.../ part
217217 shownValue = value .split ("/" )[- 1 ].replace ("_" , " " )
218-
219- #~ value = "/".join(value.split("/")[:-1]) + \
220- #~ "/" + value.split("/")[-1].capitalize()
221-
222218
223219 url = "http://en.wikipedia.org/w/index.php?search=%s" % \
224220 value .split ("/" )[- 1 ].replace (" " , "%20" )
225221
226222 value = "<a href=%s>%s</a>" % (url , shownValue )
227223 else :
224+ #Don't show really long lines
228225 characterLengthLimit = 90
229226 if len (value ) > characterLengthLimit :
230227 value = value [:characterLengthLimit - 3 ] + "..."
0 commit comments