forked from crunk/distribusi-verse
adding exif data start
This commit is contained in:
parent
b7310c837b
commit
e5d8da2568
@ -14,6 +14,7 @@ from sqlalchemy.exc import (
|
|||||||
InterfaceError,
|
InterfaceError,
|
||||||
InvalidRequestError,
|
InvalidRequestError,
|
||||||
)
|
)
|
||||||
|
from exif 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
|
||||||
@ -51,6 +52,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)
|
||||||
distribusi = Distribusis.query.filter_by(
|
distribusi = Distribusis.query.filter_by(
|
||||||
id=distribusi_file.distribusi
|
id=distribusi_file.distribusi
|
||||||
).first()
|
).first()
|
||||||
@ -110,3 +112,21 @@ def save_described_file_to_db(describe_form, distribusi_file):
|
|||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
describe_form.save.errors.append("Error connecting to the database")
|
describe_form.save.errors.append("Error connecting to the database")
|
||||||
flash("Error connecting to the database", "danger")
|
flash("Error connecting to the database", "danger")
|
||||||
|
|
||||||
|
|
||||||
|
def add_exif_to_image(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
|
||||||
|
8
verse/describer/forms/redistribusi_form.py
Normal file
8
verse/describer/forms/redistribusi_form.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from flask_wtf import FlaskForm
|
||||||
|
from wtforms import SubmitField
|
||||||
|
|
||||||
|
|
||||||
|
class DistribusiForm(FlaskForm):
|
||||||
|
"""Distribusi class to launch your distribusi website"""
|
||||||
|
|
||||||
|
submit = SubmitField("Re-Distribusi!")
|
Loading…
Reference in New Issue
Block a user