Fix error flashing and transmission
This commit is contained in:
66
src/web.py
66
src/web.py
@@ -6,51 +6,63 @@ import os
|
||||
|
||||
|
||||
class Web(object):
|
||||
"""docstring for web."""
|
||||
"""Web is the class that gets all of the information from web calls ( API and Web page ) and provides checks before sending stuff to printing"""
|
||||
|
||||
def __init__(self, app, printer):
|
||||
super(Web).__init__()
|
||||
self.printer = printer
|
||||
self.app = app
|
||||
|
||||
def print_sms(self, texte, sign: str):
|
||||
# TODO: verify the texte before printing it here ?
|
||||
def print_sms(self, texte, sign: str) -> bool:
|
||||
"""
|
||||
Get text and a signature, prints the text and cuts after that.
|
||||
"""
|
||||
self.app.logger.debug("Printing : " + str(texte) + " from " + str(sign))
|
||||
try:
|
||||
self.printer.print_sms(texte, sign)
|
||||
self.printer.cut()
|
||||
except Exception as e:
|
||||
self.app.logger.error(e)
|
||||
flash("Error while printing the SMS : " + str(e))
|
||||
raise RuntimeError("Could not print SMS, " + str(e)) from e
|
||||
|
||||
flash("You message " + str(texte) + " has been printed :)")
|
||||
return True
|
||||
|
||||
def print_image(self, image, sign):
|
||||
self.app.logger.debug("Uploading file")
|
||||
def print_image(self, image, sign: str) -> bool:
|
||||
"""
|
||||
Get an image and a signature, prints the image and cuts after that.
|
||||
"""
|
||||
try:
|
||||
self.app.logger.debug("Uploading file from " + str(sign))
|
||||
if self.upload_file(image):
|
||||
self.app.logger.debug("File has been uploaded, printing...")
|
||||
self.printer.print_img(
|
||||
os.path.join(
|
||||
self.app.config["UPLOAD_FOLDER"],
|
||||
secure_filename(image.filename),
|
||||
),
|
||||
sign=sign,
|
||||
process=True,
|
||||
)
|
||||
self.printer.cut()
|
||||
self.upload_file(image)
|
||||
except Exception as e:
|
||||
self.app.logger.error(e)
|
||||
flash("Could not upload file." + str(e))
|
||||
raise RuntimeError("Could not upload file") from e
|
||||
|
||||
flash("Your image has been printed :)")
|
||||
self.app.logger.debug("File has been uploaded, printing...")
|
||||
|
||||
def login(username: str, password: str) -> bool:
|
||||
pass
|
||||
|
||||
def logout(username: str, password: str) -> bool:
|
||||
pass
|
||||
try:
|
||||
self.printer.print_img(
|
||||
os.path.join(
|
||||
self.app.config["UPLOAD_FOLDER"],
|
||||
secure_filename(image.filename),
|
||||
),
|
||||
sign=sign,
|
||||
process=True,
|
||||
)
|
||||
self.printer.cut()
|
||||
except Exception as e:
|
||||
raise RuntimeError("Could not print file") from e
|
||||
|
||||
self.app.logger.debug("Image printed and cut !")
|
||||
return True
|
||||
|
||||
def login(self, username: str, password: str) -> bool:
|
||||
"""Not implemented"""
|
||||
return
|
||||
|
||||
def logout(self, username: str, password: str) -> bool:
|
||||
"""Not implemented"""
|
||||
return
|
||||
|
||||
def allowed_file(self, filename) -> bool:
|
||||
self.app.logger.debug("Is the filename allowed ?")
|
||||
@@ -67,10 +79,8 @@ class Web(object):
|
||||
self.app.logger.debug("File valid")
|
||||
try:
|
||||
image.save(os.path.join(self.app.config["UPLOAD_FOLDER"], filename))
|
||||
self.app.logger.debug("File saved")
|
||||
except Exception as e:
|
||||
self.app.logger.error("Could not save file")
|
||||
flash(str(e), "error")
|
||||
self.app.logger.error("Could not save file %s", e)
|
||||
return False
|
||||
|
||||
self.app.logger.debug(
|
||||
|
||||
Reference in New Issue
Block a user