renamed uploaded file

This commit is contained in:
2022-11-06 15:01:37 +03:00
parent 60f746b2ee
commit de3e20e0cb
5 changed files with 62 additions and 44 deletions

79
app.py
View File

@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from flask import Flask, render_template, request, flash, redirect, url_for from flask import Flask, render_template, request, flash, redirect, url_for
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
import os import os, secrets
from models import db from models import db, PrintedDetal
from models import PrintedDetal
import logging import logging
from models import PrintedDetal
logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG) logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG)
@@ -24,7 +22,25 @@ db.init_app(app)
@app.route("/") @app.route("/")
def index(): def index():
#detals = PrintedDetal.query.all()
allDetals = {}
detalsQuery = PrintedDetal.query.all()
for detal in detalsQuery:
detals = {}
detals['img'] = detal.img
detals['stl'] = detal.stl
detals['src']= detal.src
detals['isprinted'] = detal.isprinted
allDetals[detal.id] = detals
print(allDetals)
return render_template("index.html") # , detals=detals) return render_template("index.html") # , detals=detals)
@@ -32,48 +48,53 @@ def index():
@app.route("/admin", methods=['GET', 'POST']) @app.route("/admin", methods=['GET', 'POST'])
def admipage(): def admipage():
logging.debug("adminpage loaded") logging.debug("adminpage loaded")
if request.method == 'POST':
logging.debug("POST QUERY loaded")
return render_template("adminpage.html")
@app.route('/uploader', methods=['GET', 'POST'])
def upload_file():
hex = secrets.token_hex(15)
if request.method == 'POST':
image_file = request.files['imgfile'] image_file = request.files['imgfile']
stl_file = request.files['stlfile'] stl_file = request.files['stlfile']
src_file = request.files['stlfile']
if len(image_file.filename) > 0:
image_file.save(os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(image_file.filename)))
if len(stl_file.filename) >0:
stl_file.save(os.path.join(app.config['UPLOAD_FOLDER2'], secure_filename(stl_file.filename)))
if len(src_file.filename) >0:
src_file.save(os.path.join(app.config['UPLOAD_FOLDER2'], secure_filename(src_file.filename)))
logging.debug(image_file)
logging.debug(stl_file)
image_file.save(os.path.join(
app.config['UPLOAD_FOLDER'], image_file.filename))
stl_file.save(os.path.join(
app.config['UPLOAD_FOLDER2'], stl_file.filename))
if request.form.get('isprinted') == 'on': if request.form.get('isprinted') == 'on':
isprinered = True isprinered = True
else: else:
isprinered = False isprinered = False
logging.debug(image_file) logging.debug(image_file)
logging.debug(stl_file) logging.debug(stl_file)
logging.debug(isprinered) logging.debug(isprinered)
# detal = PrintedDetal(imgpath=image_file.filename, detal = PrintedDetal(img=image_file.filename,
# stlpath=stl_file.filename, stl=stl_file.filename,
# isprinted=isprinered) src=src_file.filename,
# db.session.add(detal) isprinted=isprinered)
# db.session.commit() db.session.add(detal)
db.session.commit()
return render_template("adminpage.html")
else:
return render_template("adminpage.html")
@app.route('/uploader', methods=['GET', 'POST']) return redirect(url_for('admipage'))
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(secure_filename(f.filename))
return 'file uploaded successfully'
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", debug="True", port="3800") app.run(host="0.0.0.0", debug="True", port="3800")

View File

@@ -6,7 +6,7 @@ db = SQLAlchemy()
class PrintedDetal(db.Model): class PrintedDetal(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True) id = db.Column(db.Integer, primary_key=True, autoincrement=True)
imgpath = db.Column(db.String(3000)) img = db.Column(db.String(3000))
stlpath = db.Column(db.String(3000)) stl = db.Column(db.String(3000))
srcpath = db.Column(db.String(3000)) src = db.Column(db.String(3000))
isprinted = db.Column(db.Boolean()) isprinted = db.Column(db.Boolean())

View File

@@ -65,4 +65,3 @@ h5{
margin-bottom: 10px; margin-bottom: 10px;
padding: 10px; padding: 10px;
} }

View File

@@ -18,7 +18,7 @@
<div class="container"> <div class="container">
<div class="row "> <div class="row ">
<form method="post" enctype=multipart/form-data> <form method="post" enctype=multipart/form-data action="/uploader">
<label class=" d-block p-2">Выберите изображение </label> <label class=" d-block p-2">Выберите изображение </label>
<input class=" formblock d-block p-2" type="file" name="imgfile" /> <input class=" formblock d-block p-2" type="file" name="imgfile" />
<label class=" d-block p-2">Выберите исходный file </label> <label class=" d-block p-2">Выберите исходный file </label>

View File

@@ -33,9 +33,7 @@
<div class="row"> <div class="row">
<div class="col d-flex justify-content-center"> <div class="col d-flex justify-content-center">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" disabled> <input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" disabled>
<label class="form-check-label" for="flexCheckDefault"> <label> Напечатано </label>
Напечатано
</label>
</div> </div>
<div class="col d-flex justify-content-center"> <div class="col d-flex justify-content-center">
<h5> 22.10.2022</h5> <h5> 22.10.2022</h5>