Re: [Tutor] psp_site mmods
Magnus Lycka
magnus at thinkware.se
Wed Jun 23 15:31:16 EDT 2004
Might this excerpt from the mod_python docs be useful?
----
Here is an example of how PSP can be used as a templating mechanism:
The template file:
<html>
<!-- This is a simple psp template called template.html -->
<h1>Hello, <%=what%>!</h1>
</html>
The handler code:
from mod_python import apache, psp
def handler(req):
template = psp.PSP(req, filename='template.html')
template.run({'what':'world'})
return apache.OK
---
By the way, as a general programming advice, I'd suggest that you
keep your swishE logic and your mod_python logic in different
modules. This will have two benefits:
* It gets easier to replace mod_python with something else
without touching your swishE code or vice versa.
* It makes it easier to write/test/debug the swishE code without
having to think about mod_python problems and vice versa.
This means that your code might be something like this (entirely
untested and just guessing wildly):
from mod_python import apache, psp
import search
def results(req, searchWords):
template = psp.PSP(req, filename='template.html')
if not (searchWords):
query = 'Nothing to search for.'
answer = 'Nothing Found'
else:
query = 'Looking for: %s' % searchWords
answer = search.wordSearch(searchWords)
template.run({'query':query, 'answer':answer})
return apache.OK
template.html:
<html>
<!-- This is a simple psp template called template.html -->
<h1><%=query%></h1>
<b><%=answer%></b>
</html>
and then in "search.py":
..
def wordSearch(searchWords):
handle = SwishE.new('/usr/local/swish-e/index.swish-e')
search = handle.search('')
results = search.execute(searchWords)
files = [r.getproperty('swishdocpath') for r in results]
if files:
return "The files found are: %s" % files
else:
return "No files found."
--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus at thinkware.se
More information about the Tutor
mailing list