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.
#11
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
Reply
#12
Nice job!
At the end how did you do it? With a form on each row or with JS?
Reply
#13
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'))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask export/upload database table in cvs/xlsx format steve87bg 4 6,722 Jun-19-2020, 01:46 PM
Last Post: steve87bg
  Want to scrape a table data and export it into CSV format tahir1990 9 5,094 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