Python Forum
Buttons in table. Which row was selected to export.
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Buttons in table. Which row was selected to export.
#1
I am using a flask model with sqlalchemy.

The following python code exports a pdf.
@pdf_display_blueprint.route('/download_pdf', methods=['POST' , 'GET'])
def download_pdf():

            selected = request.form['selected']
            selected_row= pdf_store.query.filter.by(export=selected)
            #Get export from a button click, mostlikely going to need to be done by a form of some sort.
            Target_SN = selected_row.product_serial_number

            Target_Doc = selected_row.doctype

            file_data = BytesIO( selected_row.first().data())

            return send_file(file_data, attachment_filename= Target_SN + ' - ' + Target_Doc + '.pdf', as_attachment=True)
            return redirect(url_for('pdf_display.pdf_display_layout'))
This html code displays the rows of the table:

{% for pdf_store in display_pdf_store %}
<tr onclick='highlight()'>
<td> {{ pdf_store.product_serial_number}} </td>
<td> {{ pdf_store.doctype}} </td>
<td> {{ pdf_store.date_time}} </td>
<td> {{ pdf_store.place_of_procedure}} </td>
<td><form action='/download_pdf'><input type='button' id='Export' value='Export'></input></form></td>
</tr>
{% endfor %}

This table will contain many rows, what i want to do is have it so that when you click the 'Export' button on a certain row you get the correct pdf. Does anyone know how I can link the two?

The current setup I have appears to do nothing
Reply


Messages In This Thread
Buttons in table. Which row was selected to export. - by KirkmanJ - Jul-05-2018, 08:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask export/upload database table in cvs/xlsx format steve87bg 4 7,052 Jun-19-2020, 01:46 PM
Last Post: steve87bg
  Want to scrape a table data and export it into CSV format tahir1990 9 5,531 Oct-22-2019, 08:03 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020