partsdb

electronic parts inventory
git clone https://git.e1e0.net/partsdb.git
Log | Files | Refs

commit 4cb1bc6860ab058b2a2e0e8b1cb4d14ab7b6d884
parent b13fab7fa881a5702588e44863c3ed67961101a7
Author: Paco Esteban <paco@e1e0.net>
Date:   Sun,  4 Apr 2021 18:45:10 +0200

link datasheets and images for parts that have them

Diffstat:
Mexports/templates/part.html | 13+++++++++++--
Mhelpers.py | 9+++++++++
Mpartsdb.py | 3+++
3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/exports/templates/part.html b/exports/templates/part.html @@ -44,8 +44,17 @@ </tr> <tr> <td colspan="3"> - <a href="" >Datasheet</a> - <a href="" >Image</a> + {% if part.datasheet != None %} + <a href="part_datasheet_{{ part.id }}.pdf">Datasheet</a> + {% else %} + There is no datasheet for this part. + {% endif %} + &nbsp;||&nbsp; + {% if part.image != None %} + <a href="part_image_{{ part.id }}.jpg">Image</a> + {% else %} + There is no image for this part. + {% endif %} </td> </tr> <tr> diff --git a/helpers.py b/helpers.py @@ -125,3 +125,12 @@ def html_css(dest_folder, env): tpl = env.get_template('style.css') with open(f"{dest_folder}/style.css", 'w') as f: f.write(tpl.render()) + + +def html_attachments(dest_folder, part_id, datasheet, image): + if datasheet['datasheet'] is not None: + with open(f"{dest_folder}/part_datasheet_{part_id}.pdf", 'wb') as f: + f.write(datasheet['datasheet']) + if image['image'] is not None: + with open(f"{dest_folder}/part_image_{part_id}.jpg", 'wb') as f: + f.write(image['image']) diff --git a/partsdb.py b/partsdb.py @@ -186,6 +186,9 @@ def export_db(dest_folder): part = db.get_part(p['id']) history = db.get_part_history(p['id']) html_part(dest_folder, part, history, env) + image = db.get_image(p['id']) + datasheet = db.get_datasheet(p['id']) + html_attachments(dest_folder, p['id'], datasheet, image) html_css(dest_folder, env)