mardi 26 janvier 2016

Downloading csv fiile using python intranet

Hello guys this is the python web application i have made

    """
    This is where  we start the actual web application
    """
    number_of_leads= counter
    unmatched_leads= len(getLeadSettings(in_leads)[0])
    #lead_details=[number_of_leads,unmatched_leads]

    pop_before=int(getPop(coveredzips))
    for z in ziplist:
        if z not in coveredzips:
            coveredzips+=[z]

    pop_after=int(getPop(coveredzips))
    ziplist_pop_percentage=float((ziplist_pop*100.0)/pop_before)
    popdata = [ziplist_pop, pop_before, pop_after,ziplist_pop_percentage]

    number_can_generate= str(float((number_of_leads)/(ziplist_pop/1000000.0))) + " leads per Million"

    lead_details=[number_of_leads,unmatched_leads,number_can_generate]

    file=csv_file
    return render.region_report(partners = partners, popdata = popdata ,lead_details=lead_details,file=file)
    return render.index(greeting = greeting)



    #l=getRegionsWithPop(current_regions)
    #u=getRegionWithPop(l)
    #return u
if __name__ == "__main__":
    app.run()

i am forwarding the whole result to region_report.html.

and the region_report.html looks like

$def with (partners, popdata , lead_details,file)

<html>

    <head>
        <title>Agents with overlapping territories</title>
    </head>
    <h2 align="center" style="color:green">Partner details with overlapping territories</h2>
$if partners:
    <table border="1" style="width:100%" bgcolor="#FFFFCC"  border="black" >
    <tr><td><b>PID</b></td><td><b>Name</b></td><td><b>Lead limit</b></td><td><b>Profit</b></td><td><b>Region percentage</b></td><td><b>Number of leads</b></td></tr>
    $for pid,data in partners.items():
        <tr><td>$pid</td><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td><td>$data[4]</td></tr>
    </table>
$else:
    Oops!
<br/>   
$if popdata:
    <table border="1" style="width:38.5%" bgcolor="#FFFFCC" >
    <tr><td><b>Zip list population<b></td><td>$popdata[0]</td></tr>
    <tr><td><b>Total covered population without ziplist<b></td><td> $popdata[1]</td></tr>
    <tr><td><b>Total covered population with ziplist</td><td> $popdata[2]</td></tr>
    <tr><td><b>Percentage of the population covered </td><td> $popdata[3]</td></tr>
$if lead_details:
    <tr><td><b>Number of leads in the ziplist from the last month </td><td> $lead_details[0]</td></tr>
    <tr><td><b>Number of leads which are unmatched in the last month </td><td> $lead_details[1]</td></tr>
    <tr><td><b>Number of leads we can generate on average </td><td> $lead_details[2]</td></tr>
    </table>
    <button type="submit" value="Submit">Download</button>
$else:
    Oops!

</body>
</html>

In region_report i have added a download button .I want to make that button working so that i can download the whole data as csv. Can anyone please suggest me how i can do that.

Thanks




Aucun commentaire:

Enregistrer un commentaire