Skip to content
Snippets Groups Projects
Verified Commit 28025661 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Evaluate 'printer' field

parent 2fedcc2c
No related branches found
No related tags found
1 merge request!3Resolve "Improve UX with spinners and dismissible alerts"
......@@ -39,7 +39,9 @@ function uploadFile(file) {
$("#dropzone").addClass("drop-uploading");
let formData = new FormData();
formData.append('document', file)
formData.append('document', file);
formData.append('printer', $("#printer").val());
fetch("/", {
method: 'POST',
body: formData
......
......@@ -5,9 +5,6 @@ import cups
from flask import Flask, render_template, request, send_from_directory
from werkzeug.utils import secure_filename
CUPS_SERVER = "10.1.9.104:631"
cups.setServer(CUPS_SERVER)
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = "/tmp/web2print"
os.makedirs("/tmp/web2print", exist_ok=True)
......@@ -23,16 +20,22 @@ def get_printers():
@app.route('/', methods=["POST", "GET"])
def index():
if (request.method == "GET") or ("document" not in request.files) or \
(not request.files["document"].filename):
(not request.files["document"].filename) or \
("printer" not in request.form) or (not request.form["printer"]):
return render_template("index.html", printers=printers)
printer = request.form["printer"]
if printer not in printers:
printer = printers[0]
file = request.files['document']
filename = secure_filename(file.filename)
local_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(local_path)
conn = cups.Connection()
conn.printFile(printers[0], local_path, "web2print-%d" % time(),
conn.printFile(printer, local_path, "web2print-%d" % time(),
{"fit-to-page": "True", "sides": "two-sided-long-edge"})
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment