redirecting command in python!

Posted on 2007-07-24
Last Modified: 2012-05-05
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;

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

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

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

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

    export_format = 'impress_jpg_Export'

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

    # Load File
    properties = []
    p.Name = "Hidden"
    p.Value = False

    context = uno.getComponentContext()
    resolver = context.ServiceManager.createInstanceWithContext("", context)
    ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
    smgr = ctx.ServiceManager
    desktop = smgr.createInstanceWithContext("",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))
        doc.storeToURL(url_save, outproperties)
        print "Failed while writing:"
    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!
Question by:ldbkutty
    LVL 9

    Accepted Solution

    LVL 9

    Expert Comment

    Any luck?
    LVL 32

    Author Comment

    Sorry for the late response... but yes, I was able to do the redirect using the redirect.external!

    Thank you :)


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now