Remove flash from the printer class, update web class
This commit is contained in:
parent
dfeb1be0f0
commit
eac737b889
@ -1,5 +1,4 @@
|
||||
# Importing the module to mage the connection to the printer.
|
||||
from flask import flash
|
||||
from escpos.printer import Usb, USBNotFoundError
|
||||
from time import sleep, gmtime, strftime
|
||||
import os.path
|
||||
@ -46,12 +45,10 @@ class Printer(object):
|
||||
match status:
|
||||
case 0:
|
||||
self.app.logger.error('Printer has no more paper, aborting...')
|
||||
flash("No more paper on the printer. Sorry.",category='error')
|
||||
self.printer.close()
|
||||
raise Exception("No more paper in the printer")
|
||||
case 1:
|
||||
self.app.logger.warning('Printer needs paper to be changed very soon ! ')
|
||||
flash('Printer needs paper to be changed very soon ! ', category='info')
|
||||
self.printer.close()
|
||||
case 2:
|
||||
self.app.logger.debug('Printer has paper, good to go')
|
||||
@ -101,7 +98,7 @@ class Printer(object):
|
||||
|
||||
return True
|
||||
|
||||
def print_sms(self, msg, signature) -> None:
|
||||
def print_sms(self, msg, signature="Guest") -> None:
|
||||
clean_msg = str(msg)
|
||||
clean_signature = str(signature)
|
||||
|
||||
@ -109,7 +106,7 @@ class Printer(object):
|
||||
self.app.logger.warning("Could not print message of this length: " + str(len(clean_msg)))
|
||||
raise Exception("Could not print message of this length :" + str(len(clean_msg)) + ", needs to between 3 and 4096 caracters long.")
|
||||
|
||||
if len(signature) > 256 or len(signature) < 3:
|
||||
if len(signature) > 256 or len(signature) < 1:
|
||||
self.app.logger.warning("Could not print signature of this length: " + str(len(clean_signature)))
|
||||
raise Exception("Could not print signature of this length :" + str(len(clean_signature)) + ", needs to between 3 and 256 caracters long.")
|
||||
|
||||
@ -133,13 +130,12 @@ class Printer(object):
|
||||
self.app.logger.error("Unable to print because : " + str(e))
|
||||
raise e
|
||||
|
||||
flash("Message printed : " + clean_msg ,category='info')
|
||||
return True
|
||||
|
||||
def print_img(self, path, sign) -> None:
|
||||
clean_signature = str(sign)
|
||||
|
||||
if len(sign) > 256 or len(sign) < 3:
|
||||
if len(sign) > 256 or len(sign) < 1:
|
||||
self.app.logger.warning("Could not print signature of this length: " + str(len(clean_signature)))
|
||||
raise Exception("Could not print signature of this length :" + str(len(clean_signature)) + ", needs to between 3 and 256 caracters long.")
|
||||
|
||||
@ -160,10 +156,10 @@ class Printer(object):
|
||||
try:
|
||||
self.check_paper()
|
||||
self.printer.open(self.usb_args)
|
||||
self.printer.textln("Printed by LittlePrinter ")
|
||||
self.printer.textln("n07070.xyz/articles/littleprynter")
|
||||
self.printer.textln("> " + clean_signature + " @ " + strftime("%Y-%m-%d %H:%M:%S", gmtime()))
|
||||
self.printer.image(path)
|
||||
self.printer.textln("Printed by LittlePrynter ")
|
||||
self.printer.textln("n07070.xyz/articles/littleprynter")
|
||||
self.printer.textln(clean_signature + " @ " + strftime("%Y-%m-%d %H:%M:%S", gmtime()))
|
||||
self.printer.cut()
|
||||
self.printer.close()
|
||||
self.app.logger.debug("Printed an image : " + str(path))
|
||||
@ -214,7 +210,7 @@ def process_image(self, path):
|
||||
|
||||
# Final resize check
|
||||
if original_img.height > max_height:
|
||||
flash("Image is too long, sorry! Keep it below 575×1000 pixels.", 'error')
|
||||
raise ValueError("Image is too long, sorry! Keep it below 575×1000 pixels.")
|
||||
self.app.logger.error("Image is too long, sorry! Keep it below 575×1000 pixels.")
|
||||
return False
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ class Web(object):
|
||||
self.app.logger.error(e)
|
||||
flash("Error while printing the SMS : "+ str(e))
|
||||
|
||||
flash("You message has been printed :)")
|
||||
flash("You message " + str( texte ) + " has been printed :)")
|
||||
|
||||
|
||||
def print_image(self, image, sign: str):
|
||||
@ -57,7 +57,7 @@ class Web(object):
|
||||
self.app.logger.debug("File saved")
|
||||
except Exception as e:
|
||||
self.app.logger.error("Could not save file")
|
||||
flash(e,'error')
|
||||
flash(str(e),'error')
|
||||
return False
|
||||
|
||||
self.app.logger.debug("File saved to " + str(os.path.join(self.app.config['UPLOAD_FOLDER'], filename)))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user