|
@ -15,7 +15,8 @@ from sqlalchemy.exc import ( |
|
|
InterfaceError, |
|
|
InterfaceError, |
|
|
InvalidRequestError, |
|
|
InvalidRequestError, |
|
|
) |
|
|
) |
|
|
from exif import Image |
|
|
import piexif |
|
|
|
|
|
from PIL import Image |
|
|
from app import db |
|
|
from app import db |
|
|
from models.distribusi_model import Distribusis |
|
|
from models.distribusi_model import Distribusis |
|
|
from models.distribusi_file_model import DistribusiFiles |
|
|
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 |
|
|
distribusi_file.id, distribusi_file.path, distribusi_file.type |
|
|
) |
|
|
) |
|
|
save_described_file_to_db(describe_form, distribusi_file) |
|
|
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( |
|
|
distribusi = Distribusis.query.filter_by( |
|
|
id=distribusi_file.distribusi |
|
|
id=distribusi_file.distribusi |
|
|
).first() |
|
|
).first() |
|
@ -138,19 +139,10 @@ def save_described_file_to_db(describe_form, distribusi_file): |
|
|
flash("Error connecting to the database", "danger") |
|
|
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: |
|
|
if not describe_form.alttext.data: |
|
|
return |
|
|
return |
|
|
if distribusi_file.type != "image": |
|
|
filename_no_ext = os.path.splitext(distribusi_file.path)[0] |
|
|
return |
|
|
with open(f'{filename_no_ext}_alttext.txt', 'w') as alttext_file: |
|
|
updating_image = bytearray() |
|
|
alttext_file.write(describe_form.alttext.data) |
|
|
with open(distribusi_file.path, "rb") as image_file: |
|
|
return |
|
|
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 |
|
|
|
|
|