diff --git a/app.py b/app.py index 8e62534..6cade46 100644 --- a/app.py +++ b/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'] - 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") + diff --git a/models.py b/models.py index ae6c750..5c4995e 100644 --- a/models.py +++ b/models.py @@ -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()) \ No newline at end of file diff --git a/static/css/style.css b/static/css/style.css index 4e40929..12eb775 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -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; -} - +} \ No newline at end of file diff --git a/templates/adminpage.html b/templates/adminpage.html index 8406d46..0e92ddf 100644 --- a/templates/adminpage.html +++ b/templates/adminpage.html @@ -18,7 +18,7 @@
-
+ diff --git a/templates/index.html b/templates/index.html index ba81477..10f1cdb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -33,9 +33,7 @@
- +
22.10.2022