-1

I'm developing an online GNSS post processing portal for my office website. In the application user have to enter 2 files. I have implemented a html form to get relevant information from user. Generated form

Once user submitted the files, Post-processing function will be executed in the back-end. Since the function is very long I want to display a background progress bar.

Following code represent the post processing function.

@app.route('/pp.php', methods=['GET', 'POST'])
def pp():
    pp = MyForm()
    target = os.path.join(APP_ROOT, 'images/')
    print(target)

    if not os.path.isdir(target):
        os.mkdir(target)

    for obsfile in request.files.getlist("obsfile"):
        print(obsfile)
        filename = obsfile.filename
        destination = "/".join([target, filename])
        print(destination)
        obsfile.save(destination)

    for navfile in request.files.getlist("navfile"):
        print(navfile)
        filename = navfile.filename
        destination = "/".join([target, filename])
        print(destination)
        navfile.save(destination)
        a=obsfile.filename
        b=navfile.filename
        command='rnx2rtkp -p 0 -m '+pp.textarea.data+' -n -o out.pos '+a+' '+b
        os.system(command)

        email_user = '*******'
        email_password = '******'
        email_send = pp.email.data

        subject = 'subject'

        msg = MIMEMultipart()
        msg['From'] = email_user
        msg['To'] = email_send
        msg['Subject'] = subject

        body = 'This is your Post-Processed position file'
        msg.attach(MIMEText(body,'plain'))

        filename='out.pos'
        attachment  =open(filename,'rb')

        part = MIMEBase('application','octet-stream')
        part.set_payload((attachment).read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition',"attachment; filename= "+filename)

        msg.attach(part)
        text = msg.as_string()
        server = smtplib.SMTP('smtp.gmail.com',587)
        server.starttls()
        server.login(email_user,email_password)


        server.sendmail(email_user,email_send,text)
        server.quit()

    return render_template('pp.php', pp=pp)

please let me know any suggestions that might help to resolve this issue

Richiedlon
  • 111
  • 1
  • 4
  • 13

1 Answers1

1

You should use something like Celery to run the background task, and use Javascript to update the browser based on the status returned by the Celery Task.

Arunmozhi
  • 1,034
  • 8
  • 17