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 -*-
from flask import Flask, render_template, request, flash, redirect, url_for
from werkzeug.utils import secure_filename
import os
from models import db
from models import PrintedDetal
import os, secrets
from models import db, PrintedDetal
import logging
from models import PrintedDetal
logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG)
@@ -24,7 +22,25 @@ db.init_app(app)
@app.route("/")
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)
@@ -32,48 +48,53 @@ def index():
@app.route("/admin", methods=['GET', 'POST'])
def admipage():
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']
stl_file = request.files['stlfile']
src_file = request.files['stlfile']
logging.debug(image_file)
logging.debug(stl_file)
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)))
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':
isprinered = True
else:
isprinered = False
logging.debug(image_file)
logging.debug(stl_file)
logging.debug(isprinered)
# detal = PrintedDetal(imgpath=image_file.filename,
# stlpath=stl_file.filename,
# isprinted=isprinered)
# db.session.add(detal)
# db.session.commit()
return render_template("adminpage.html")
else:
return render_template("adminpage.html")
detal = PrintedDetal(img=image_file.filename,
stl=stl_file.filename,
src=src_file.filename,
isprinted=isprinered)
db.session.add(detal)
db.session.commit()
@app.route('/uploader', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(secure_filename(f.filename))
return 'file uploaded successfully'
return redirect(url_for('admipage'))
if __name__ == "__main__":
app.run(host="0.0.0.0", debug="True", port="3800")

View File

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

View File

@@ -4,7 +4,7 @@ body {
background-color: #dcf3d0;
}
header{
header {
box-shadow: 0px 5px 10px 2px rgba(34, 60, 80, 0.2);
}
@@ -15,14 +15,14 @@ header{
line-height: 100px;
text-align: center;
color: #034956;
}
.row {
margin-top: 20px;
}
.col-md-4{
.col-md-4 {
margin-bottom: 25px;
}
@@ -50,19 +50,18 @@ header{
}
.card-img-top{
.card-img-top {
padding: 10px;
border-radius: 18px;
}
h5{
h5 {
font-size: 17px;
}
.mobile-margin{
.mobile-margin {
margin-bottom: 10px;
padding: 10px;
}
}

View File

@@ -18,7 +18,7 @@
<div class="container">
<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>
<input class=" formblock d-block p-2" type="file" name="imgfile" />
<label class=" d-block p-2">Выберите исходный file </label>

View File

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