webp support
This commit is contained in:
29
app.py
29
app.py
@@ -147,9 +147,8 @@ class Receipt(db.Model):
|
||||
list_id = db.Column(db.Integer, db.ForeignKey("shopping_list.id"), nullable=False)
|
||||
filename = db.Column(db.String(255), nullable=False)
|
||||
uploaded_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
shopping_list = db.relationship("ShoppingList", backref="receipts", lazy=True)
|
||||
|
||||
filesize = db.Column(db.Integer, nullable=True)
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
@@ -298,6 +297,7 @@ def delete_receipts_for_list(list_id):
|
||||
print(f"Nie udało się usunąć pliku {filename}: {e}")
|
||||
|
||||
|
||||
|
||||
# zabezpieczenie logowani do systemu - błędne hasła
|
||||
def is_ip_blocked(ip):
|
||||
now = time.time()
|
||||
@@ -935,6 +935,7 @@ def upload_receipt(list_id):
|
||||
return redirect(request.referrer) """
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
@app.route("/upload_receipt/<int:list_id>", methods=["POST"])
|
||||
def upload_receipt(list_id):
|
||||
@@ -953,7 +954,15 @@ def upload_receipt(list_id):
|
||||
|
||||
save_resized_image(file, file_path)
|
||||
|
||||
new_receipt = Receipt(list_id=list_id, filename=webp_filename)
|
||||
filesize = os.path.getsize(file_path) if os.path.exists(file_path) else None
|
||||
uploaded_at = datetime.utcnow()
|
||||
|
||||
new_receipt = Receipt(
|
||||
list_id=list_id,
|
||||
filename=webp_filename,
|
||||
filesize=filesize,
|
||||
uploaded_at=uploaded_at
|
||||
)
|
||||
db.session.add(new_receipt)
|
||||
db.session.commit()
|
||||
|
||||
@@ -967,12 +976,6 @@ def upload_receipt(list_id):
|
||||
|
||||
return _receipt_error("Niedozwolony format pliku")
|
||||
|
||||
def _receipt_error(message):
|
||||
if request.is_json or request.headers.get("X-Requested-With") == "XMLHttpRequest":
|
||||
return jsonify({"success": False, "message": message}), 400
|
||||
flash(message, "danger")
|
||||
return redirect(request.referrer)
|
||||
|
||||
|
||||
|
||||
@app.route("/uploads/<filename>")
|
||||
@@ -1195,9 +1198,6 @@ def delete_user(user_id):
|
||||
flash("Użytkownik usunięty", "success")
|
||||
return redirect(url_for("list_users"))
|
||||
|
||||
|
||||
import os
|
||||
|
||||
@app.route("/admin/receipts/<id>")
|
||||
@login_required
|
||||
@admin_required
|
||||
@@ -1216,14 +1216,9 @@ def admin_receipts(id):
|
||||
flash("Nieprawidłowe ID listy.", "danger")
|
||||
return redirect(url_for("admin_panel"))
|
||||
|
||||
for r in receipts:
|
||||
path = os.path.join(app.config["UPLOAD_FOLDER"], r.filename)
|
||||
r.filesize = os.path.getsize(path) if os.path.exists(path) else 0
|
||||
|
||||
return render_template("admin/receipts.html", receipts=receipts)
|
||||
|
||||
|
||||
|
||||
@app.route("/admin/delete_receipt/<filename>")
|
||||
@login_required
|
||||
@admin_required
|
||||
|
Reference in New Issue
Block a user