@@ -1,9 +1,12 @@
1−
1+from flask.ext.babel import gettext
22name = "Self IP"
3−description = "Display your source IP address"
3+description = gettext('Display your source IP address if the query expression is "ip"')
44default_on = True
55
66
7+# attach callback to the pre search hook
8+# request: flask request object
9+# ctx: the whole local context of the pre search hook
710def pre_search(request, ctx):
811 if ctx['search'].query == 'ip':
912 x_forwarded_for = request.headers.getlist("X-Forwarded-For")
@@ -13,5 +16,6 @@ def pre_search(request, ctx):
1316 ip = request.remote_addr
1417 ctx['search'].answers.clear()
1518 ctx['search'].answers.add(ip)
19+ # return False prevents exeecution of the original block
1620 return False
1721 return True