|
|
@ -15,7 +15,8 @@ from sqlalchemy.exc import ( |
|
|
|
InterfaceError, |
|
|
|
InvalidRequestError, |
|
|
|
) |
|
|
|
from exif import Image |
|
|
|
import piexif |
|
|
|
from PIL import Image |
|
|
|
from app import db |
|
|
|
from models.distribusi_model import Distribusis |
|
|
|
from models.distribusi_file_model import DistribusiFiles |
|
|
@ -76,7 +77,7 @@ def describe_file(file_id): |
|
|
|
distribusi_file.id, distribusi_file.path, distribusi_file.type |
|
|
|
) |
|
|
|
save_described_file_to_db(describe_form, distribusi_file) |
|
|
|
add_exif_to_image(describe_form, distribusi_file) |
|
|
|
add_alttext_to_file(describe_form, distribusi_file) |
|
|
|
distribusi = Distribusis.query.filter_by( |
|
|
|
id=distribusi_file.distribusi |
|
|
|
).first() |
|
|
@ -138,19 +139,10 @@ def save_described_file_to_db(describe_form, distribusi_file): |
|
|
|
flash("Error connecting to the database", "danger") |
|
|
|
|
|
|
|
|
|
|
|
def add_exif_to_image(describe_form, distribusi_file): |
|
|
|
def add_alttext_to_file(describe_form, distribusi_file): |
|
|
|
if not describe_form.alttext.data: |
|
|
|
return |
|
|
|
if distribusi_file.type != "image": |
|
|
|
return |
|
|
|
updating_image = bytearray() |
|
|
|
with open(distribusi_file.path, "rb") as image_file: |
|
|
|
image_bytes = image_file.read() |
|
|
|
updating_image = Image(image_bytes) |
|
|
|
updating_image.communication = describe_form.alttext.data |
|
|
|
with open(distribusi_file.path, "wb") as new_image_file: |
|
|
|
new_image_file.write(updating_image.get_file()) |
|
|
|
print( |
|
|
|
f"{updating_image.communication} is set from form data: {describe_form.alttext.data}" |
|
|
|
) |
|
|
|
return |
|
|
|
filename_no_ext = os.path.splitext(distribusi_file.path)[0] |
|
|
|
with open(f'{filename_no_ext}_alttext.txt', 'w') as alttext_file: |
|
|
|
alttext_file.write(describe_form.alttext.data) |
|
|
|
return |
|
|
|