[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2485
  • Last Modified:

redirecting command in python!

Hi All,

We have a PHP based web application which is working fine. There was a new requirement whereby a PPT file should be converted to a JPG and  I found a solution using OpenOffice + SPYCE (Python server pages..) I don't want to go in detail which is not necessary for this question!

Basically, I have this block of HTML form with AJAX form submit:

<script language="Javascript" type="text/javascript">
function fileUpload() {
    if (document.getElementById("upload_file").value == "") {
        alert("Please select ppt file");
        return false;
    }
    var formObject = document.getElementById('frm_upload_file');
    if (formObject) {
        YAHOO.util.Connect.setForm(formObject, true);
    }
    var obj1 = YAHOO.util.Connect.asyncRequest('POST', 'http://localhost:8000/convert.spy', fUpload );
    return false;
}
</script>

<form id="frm_upload_file" name="frm_upload_file">
<input type="file" name="upload_file" value="">
<input type="button" value="Upload" onclick="fileUpload();">
</form>

and convert.spy is the Python server page as follows:

<%@import name=include %>
<%\
if request.file('upload_file')!= None:
    import uno, os
    from com.sun.star.beans import PropertyValue

    (up_path, up_file) = os.path.split(request.file('upload_file').filename)
    tempfile = open(os.getcwd()+'\\temp\\'+up_file, 'wb')
    tempfile.write(request.file('upload_file').value)
    tempfile.close()

    export_format = 'impress_jpg_Export'

    url = os.getcwd()+'\\temp\\'+up_file
    url_save = uno.systemPathToFileUrl(url+ '.jpg')

    # Load File
    properties = []
    p=PropertyValue()
    p.Name = "Hidden"
    p.Value = False
    properties.append(p)

    context = uno.getComponentContext()
    resolver = context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", context)
    ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
    smgr = ctx.ServiceManager
    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)
    doc = desktop.loadComponentFromURL('file:///'+url, "_blank", 0, tuple(properties))

    # Save File
    outproperties = (
            PropertyValue( "FilterName" , 0, export_format , 0 ),
            PropertyValue( "Overwrite" , 0, True , 0 ),
            PropertyValue( "Hidden",0, True,0))
    try:
        doc.storeToURL(url_save, outproperties)
    except:
        print "Failed while writing:"
    doc.dispose()
    raise spyceDone
%>


The convert.spy converts the PPT document into JPG using OpenOffice. It is working fine as well!!

What I want:

When the conversion is completed, I want this file to redirect to "http://localhost/mypage.php" page! I tried using

raise redirect("http://localhost/mypage.php")

but it didn't worked! Maybe because of the AJAX form submission? Is there any other way?

Please advise!
0
ldbkutty
Asked:
ldbkutty
  • 2
1 Solution
 
RurneCommented:
0
 
RurneCommented:
Any luck?
0
 
ldbkuttyAuthor Commented:
Sorry for the late response... but yes, I was able to do the redirect using the redirect.external!

Thank you :)

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now