[mod_python] how to create a 'submit' page while background function runs

Cameron McPherson cameron.mcpherson at florey.edu.au
Tue Oct 30 10:25:48 EDT 2007


I am using the mod_python publisher handler to control form data. It works fine, but
what I want to do is create a submit 'please wait while request is processed' kind
of page upon form submit.
AFAIK, publisher has to either return a string to complete, or use req.write(x)
followed by return(apache.OK) to finish. with this in mind, how can I return html
showing a submit page, whilst running the script on the form data in the background,
then return that html string when it's done?

I've tried javascript through the form onsubmit, which is fine for most form data
entered, except it chokes on the file upload value - it cannot pass this correctly
to the handler req object (I need it as req.form['file']), and the inbuilt read-only
prevents me from assigning it to a input file value using js (see below).

Any ideas on implementing this are greatly appreciated.


Cam.


==> submits sequence or file to 'ProcessForm'; calls 'submitCheck()' first
<form enctype="multipart/form-data" action= "./ProcessForm" method="post"
onsubmit="submitCheck()" name="ppg">
    <p><input type="textarea" name="sequence" maxlength="100000"
autofocus="autofocus" cols="80" rows="10" wrap="hard" /></p>
    <p><input type="file" name="file" /> &nbsp;&nbsp;<input type="submit"
value="submit" /> <input type="reset" value="reset" /></p>
...
</form>

==> Processes form data, returns a formatted string to the client
def ProcessForm(req): # called from 'submit'
...
    if not sequence: # (or =='')
        fileitem=req.form['file']
        if fileitem.filename:    #check that file was uploaded
...         #process uploaded file data
        return Display(req,probeList)

==> Hack job to try to make a submit page w' JS - works fine for form data
'sequence' in the form textarea, but cannot adequately pass the file item data to
the 'ProcessForm' script (ie: i think it's not recognised properly as a req object
file? I've commented out the bits which dont work)
function submitCheck() {
    if (document.forms.ppg.sequence.value) {
    var seq=document.forms.ppg.sequence.value
    var fil=document.forms.ppg.file.value
    var gen=document.forms.ppg.gene_id.value
    var num=document.forms.ppg.number_probes.value
    var smin=document.forms.ppg.size_min.value
    var smax=document.forms.ppg.size_max.value
    var tmin=document.forms.ppg.tm_min.value
    var tmax=document.forms.ppg.tm_max.value
    var gmin=document.forms.ppg.gc_min.value
    var gmax=document.forms.ppg.gc_max.value
    var subS1="<html>\n<head>\n<link rel=\"stylesheet\" type=\"text/css\"
href=\"./assets/style/style.css\" />\n</head>\n<body>\n<h3
style=\"text-decoration:blink;\">Please wait while your request is
processed...</h3>";
    var subS2="</form>\n</body>\n</html>";
    document.write(subS1);
    document.write("<form enctype=\"multipart/form-data\" action=\"./ProcessForm\"
method=\"post\" onsubmit=\"submitResult()\" name=\"ppgSubmit\">");
    document.write("<input type=\"hidden\" name=\"sequence\" value="+seq+">");
    //document.write("<input type=\"file\" name=\"file\" value="+fil+">");
    //document.write("<input type=\"hidden\" name=\"file\" value="+fil+">");
    document.write("<input type=\"hidden\" name=\"gene_id\" value="+gen+">");
    document.write("<input type=\"hidden\" name=\"number_probes\" value="+num+">");
    document.write("<input type=\"hidden\" name=\"size_min\" value="+smin+">");
    document.write("<input type=\"hidden\" name=\"size_max\" value="+smax+">");
    document.write("<input type=\"hidden\" name=\"tm_min\" value="+tmin+">");
    document.write("<input type=\"hidden\" name=\"tm_max\" value="+tmax+">");
    document.write("<input type=\"hidden\" name=\"gc_min\" value="+gmin+">");
    document.write("<input type=\"hidden\" name=\"gc_max\" value="+gmax+">");
    document.write(subS2);
    document.forms.ppgSubmit.submit();
    //alert(fil);
    }
}










More information about the Mod_python mailing list