Python Forum

Full Version: Buttons in table. Which row was selected to export.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Sorry been a long weekend. Something i completely overlooked. Now just got to get BytestIO() to acdtaully raed the pdf. Shouldnt be too hard :/ . Thanks for all your help :)

Just to conclude, i found my error.
The line:
   file_data = BytesIO( selected_row.first().data())
Should in fact of been
file_data = BytesIO( selected_row.first().data)
changing .data() -> .data ..... data being the column name in which the pdf information was stored

Thanks for all the help Jones and Buran
Nice job!
At the end how did you do it? With a form on each row or with JS?
I used the form process as it seemed to be the most compact way of doing it :). and my java is horrific :P . Final format was as such:
</form>
	{% for pdf_store in display_pdf_store %}
		<tr onclick='highlight()'>
			<form action='/download_pdf' method='POST'>
				<td> {{ pdf_store.product_serial_number}} <input type="hidden" name="product_serial_number" value="{{ pdf_store.product_serial_number}}" /> </td>
				<td> {{ pdf_store.doctype}} <input type="hidden" name="doctype" value="{{ pdf_store.doctype}}" /> </td>
				<td> {{ pdf_store.date_time}} <input type="hidden" name="date_time" value="" /> </td>
				<td> {{ pdf_store.place_of_procedure}}  <input type="hidden" name="place_of_procedure" value="{{ pdf_store.place_of_procedure}}" /></td>
				<td><input type='submit' id='Export' value='Export'></input></td>
			</form>
         </tr>
	{% endfor %}
@pdf_display_blueprint.route('/download_pdf', methods=['POST' , 'GET'])
def download_pdf():
    Target_SN = request.form['product_serial_number']
    Target_Doc = request.form['doctype']

    selected_row= pdf_store.query.filter_by(product_serial_number=Target_SN).filter_by(doctype=Target_Doc).first()
   
    file_data = BytesIO(selected_row.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'))
Pages: 1 2