renamed uploaded file
This commit is contained in:
79
app.py
79
app.py
@@ -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']
|
||||
|
||||
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':
|
||||
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")
|
||||
|
||||
|
||||
@@ -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())
|
||||
@@ -65,4 +65,3 @@ h5{
|
||||
margin-bottom: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user