Jul-05-2018, 08:57 AM
I am using a flask model with sqlalchemy.
The following python code exports a pdf.
{% 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
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