Skip to content

Commit eb9203f

Browse files
committed
Fixed checkboxes not updating properly
1 parent becca7d commit eb9203f

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

src/server/search_template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
Attribute values required: <input type="text" name="query_search_input1"
1010
class="textfield" value="{{default_query_value1}}" autofocus>
1111
<input type="checkbox" name="in_search" value="1" {{in_search_checked}}>
12-
Use "in" search<br>
13-
<input type="checkbox" name="case_sensitive" value="1" {{in_search_checked}}>
12+
Use "in" search
13+
<input type="checkbox" name="case_sensitive" value="1" {{case_sensitive_checked}}>
1414
Case sensitive<br>
1515
<p style='color: #505050'>
1616
(e.g. "nationality=british, occupation=actor")</p>

src/server/server.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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("&lt;","<").replace("&gt;",">").replace('&quot;','"').replace("&#039;",'"')
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] + "..."

src/server/stylesheet.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ body {
44
}
55

66
p {
7-
color: black;
8-
7+
color: black;
98
}
109

1110
.textfield {
@@ -15,9 +14,11 @@ p {
1514
.table_even {
1615
background-color: #BDD8F6;
1716
color: #000000
17+
border: 1px solid black;
1818
}
1919

2020
.table_odd {
2121
background-color: #BDD8F6;
2222
color: #606060
23+
border: 1px solid black;
2324
}

src/statistics.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def doStatistics(self):
210210

211211

212212
def search(self, requiredKeyValues, requestedValuesKeys,
213-
searchType=None):
213+
searchType=None, caseSensitive=False):
214214
""" Returns a list of keyvalue-pairs from articles containing certain key-values
215215
requiredKeyValues: ((key, value)) # Note: uses "in_search searching"
216216
queryOut: (key)
@@ -225,16 +225,23 @@ def search(self, requiredKeyValues, requestedValuesKeys,
225225
results = []
226226
for pageDict in self.j:
227227
wasMatch = True
228+
228229
for key, value in requiredKeyValues:
229-
if key not in pageDict or value not in pageDict[key]:
230-
wasMatch = False
230+
if caseSensitive:
231+
if key not in pageDict or value not in pageDict[key]:
232+
wasMatch = False
233+
else:
234+
if key not in pageDict or isinstance(pageDict[key], list):
235+
wasMatch = False
236+
else:
237+
pageDictValue = pageDict[key].lower()
238+
239+
if value.lower() not in pageDictValue:
240+
wasMatch = False
231241

232242
if not wasMatch:
233243
continue
234244

235-
#print "\n"*3
236-
#print "Found match with pageDict: %s" % str(pageDict)[:500]
237-
238245
r = []
239246
for requestedKey in requestedValuesKeys:
240247
#print "requestedKey:", requestedKey

0 commit comments

Comments
 (0)