main page worked

This commit is contained in:
2022-11-09 19:17:41 +03:00
parent 347f467735
commit 6cad7d6ed6
3 changed files with 30 additions and 21 deletions

40
app.py
View File

@@ -3,13 +3,15 @@ from flask import Flask, render_template, request, flash, redirect, url_for, sen
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
import os import os
import secrets import secrets
from models import db, PrintedDetal
import logging import logging
from models import db, PrintedDetal
from datetime import datetime
logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG) logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG)
app = Flask(__name__) app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
app.config['UPLOAD_IMG_FOLDER'] = os.path.join('static', 'uploads', 'img') app.config['UPLOAD_IMG_FOLDER'] = os.path.join('static', 'uploads', 'img')
app.config['UPLOAD_STL_FOLDER'] = os.path.join('static', 'uploads', 'stl') app.config['UPLOAD_STL_FOLDER'] = os.path.join('static', 'uploads', 'stl')
@@ -18,8 +20,7 @@ app.config['UPLOAD_SRC_FOLDER'] = os.path.join('static', 'uploads', 'src')
db.init_app(app) db.init_app(app)
@app.route("/") def getlldb():
def index():
allDetals = {} allDetals = {}
@@ -27,22 +28,28 @@ def index():
for detal in detalsQuery: for detal in detalsQuery:
detals = {} detals = {}
detals['id'] = detal.id
detals['img'] = detal.img detals['img'] = detal.img
detals['stl'] = detal.stl detals['stl'] = detal.stl
detals['src'] = detal.src detals['src'] = detal.src
detals['isprinted'] = detal.isprinted detals['isprinted'] = detal.isprinted
detals['date'] = detal.dateadd
allDetals[detal.id] = detals allDetals[detal.id] = detals
logging.debug(allDetals) return allDetals
return render_template("index.html", detals=allDetals)
@app.route("/")
def index():
getall = getlldb()
return render_template("index.html", detals=getall)
@app.route("/admin", methods=['GET', 'POST']) @app.route("/admin", methods=['GET', 'POST'])
def admipage(): def admipage():
logging.debug("adminpage loaded")
return render_template("adminpage.html") return render_template("adminpage.html")
@@ -62,35 +69,32 @@ def upload_file():
if len(stl_file.filename) > 0: if len(stl_file.filename) > 0:
filename = stl_file.filename.split('.') filename = stl_file.filename.split('.')
stl_file.filename = secrets.token_hex(15) + '.' + filename[-1] stl_file.filename = secrets.token_hex(15) + '.' + filename[-1]
stl_file.save(os.path.join(app.config['UPLOAD_STL_FOLDER'],stl_file.filename)) stl_file.save(os.path.join(
app.config['UPLOAD_STL_FOLDER'], stl_file.filename))
if len(src_file.filename) > 0: if len(src_file.filename) > 0:
filename = src_file.filename.split('.') filename = src_file.filename.split('.')
src_file.filename = secrets.token_hex(15) + '.' + filename[-1] src_file.filename = secrets.token_hex(15) + '.' + filename[-1]
src_file.save(os.path.join(app.config['UPLOAD_SRC_FOLDER'], src_file.filename)) src_file.save(os.path.join(
app.config['UPLOAD_SRC_FOLDER'], src_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.filename)
logging.debug(stl_file.filename)
logging.debug(src_file.filename)
logging.debug(isprinered)
detal = PrintedDetal(img=image_file.filename, detal = PrintedDetal(img=image_file.filename,
stl=stl_file.filename, stl=stl_file.filename,
src=src_file.filename, src=src_file.filename,
isprinted=isprinered) isprinted=isprinered,
dateadd=datetime.now().strftime('%d.%m.%Y'))
db.session.add(detal) db.session.add(detal)
db.session.commit() db.session.commit()
return redirect(url_for('admipage')) return redirect(url_for('admipage'))
@app.route('/download/<filename>', methods=['GET', 'POST'])
def download(filename):
return send_file(app.config['UPLOAD_SRC_FOLDER']+'/'+ filename, as_attachment=True)
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -10,3 +10,5 @@ class PrintedDetal(db.Model):
stl = db.Column(db.String(3000)) stl = db.Column(db.String(3000))
src = db.Column(db.String(3000)) src = db.Column(db.String(3000))
isprinted = db.Column(db.Boolean()) isprinted = db.Column(db.Boolean())
dateadd = db.Column(db.String(11))

View File

@@ -25,6 +25,9 @@
<div class="card-body"> <div class="card-body">
<dv class="row"> <dv class="row">
<div class="col">
<a href="{{url_for('static', filename='uploads/img/' + value['img'])}}" class="btn btn-block mobile-margin" download>Скачать изображение </a>
</div>
<div class="col"> <div class="col">
<a href="{{url_for('static', filename='uploads/src/' + value['src'])}}" class="btn btn-block mobile-margin" download >Скачать исходник</a> <a href="{{url_for('static', filename='uploads/src/' + value['src'])}}" class="btn btn-block mobile-margin" download >Скачать исходник</a>
</div> </div>
@@ -37,7 +40,7 @@
<label> Напечатано </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> {{value['dateadd']}}</h5>
</div> </div>
</div> </div>
</div> </div>