Files
3dprintedDetails/app.py
Александр Геннадьевич Сальный a75a386fed add writte to DB
2022-10-18 21:12:25 +03:00

77 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
from turtle import st
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 logging
from models import PrintedDetal
logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG)
UPLOAD_FOLDER = 'static/img/uploads'
UPLOAD_FOLDER2 = 'static/stl'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'stl'}
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['UPLOAD_FOLDER2'] = UPLOAD_FOLDER2
db.init_app(app)
@app.route("/")
def index():
detals = PrintedDetal.query.all()
logging.debug(detals[0].imgpath)
return render_template("index.html")
@app.route("/admin", methods=['GET', 'POST'])
def admipage():
stl_folder = 'stl/'
img_folder = 'img/uploads/'
if request.method == 'POST':
image_file = request.files['images']
stl_file = request.files['stl']
filename = image_file.filename
path_img = img_folder + filename
logging.debug(path_img)
image_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
filename = stl_file.filename
path_stl = stl_folder + filename
stl_file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename))
if request.form.get('isprinted') == 'on':
isprinered = True
else:
isprinered = False
detal = PrintedDetal(imgpath=str(path_img), stlpath=str(
path_stl), isprinted=isprinered)
db.session.add(detal)
db.session.commit()
logging.debug(path_img)
logging.debug(path_stl)
logging.debug(isprinered)
return render_template("adminpage.html")
else:
return render_template("adminpage.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", debug="True", port="3800")