nowe funkcje i foxy
This commit is contained in:
83
app.py
83
app.py
@@ -295,7 +295,9 @@ def save_resized_image(file, path):
|
||||
image.info.clear()
|
||||
|
||||
new_path = path.rsplit(".", 1)[0] + ".webp"
|
||||
image.save(new_path, format="WEBP", quality=100, method=0)
|
||||
# image.save(new_path, format="WEBP", quality=100, method=0)
|
||||
image.save(new_path, format="WEBP", lossless=True, method=6)
|
||||
|
||||
except Exception as e:
|
||||
raise ValueError(f"Błąd podczas przetwarzania obrazu: {e}")
|
||||
|
||||
@@ -662,13 +664,34 @@ def favicon():
|
||||
|
||||
@app.route("/")
|
||||
def main_page():
|
||||
# now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc)
|
||||
month_str = request.args.get("month")
|
||||
start = end = None
|
||||
|
||||
if month_str:
|
||||
try:
|
||||
year, month = map(int, month_str.split("-"))
|
||||
start = datetime(year, month, 1, tzinfo=timezone.utc)
|
||||
end = (start + timedelta(days=31)).replace(day=1)
|
||||
except:
|
||||
start = end = None
|
||||
|
||||
def date_filter(query):
|
||||
if start and end:
|
||||
query = query.filter(
|
||||
ShoppingList.created_at >= start, ShoppingList.created_at < end
|
||||
)
|
||||
return query
|
||||
|
||||
if current_user.is_authenticated:
|
||||
user_lists = (
|
||||
ShoppingList.query.filter_by(owner_id=current_user.id, is_archived=False)
|
||||
.filter((ShoppingList.expires_at == None) | (ShoppingList.expires_at > now))
|
||||
date_filter(
|
||||
ShoppingList.query.filter_by(
|
||||
owner_id=current_user.id, is_archived=False
|
||||
).filter(
|
||||
(ShoppingList.expires_at == None) | (ShoppingList.expires_at > now)
|
||||
)
|
||||
)
|
||||
.order_by(ShoppingList.created_at.desc())
|
||||
.all()
|
||||
)
|
||||
@@ -680,11 +703,16 @@ def main_page():
|
||||
)
|
||||
|
||||
public_lists = (
|
||||
ShoppingList.query.filter(
|
||||
ShoppingList.is_public == True,
|
||||
ShoppingList.owner_id != current_user.id,
|
||||
((ShoppingList.expires_at == None) | (ShoppingList.expires_at > now)),
|
||||
ShoppingList.is_archived == False,
|
||||
date_filter(
|
||||
ShoppingList.query.filter(
|
||||
ShoppingList.is_public == True,
|
||||
ShoppingList.owner_id != current_user.id,
|
||||
(
|
||||
(ShoppingList.expires_at == None)
|
||||
| (ShoppingList.expires_at > now)
|
||||
),
|
||||
ShoppingList.is_archived == False,
|
||||
)
|
||||
)
|
||||
.order_by(ShoppingList.created_at.desc())
|
||||
.all()
|
||||
@@ -693,10 +721,15 @@ def main_page():
|
||||
user_lists = []
|
||||
archived_lists = []
|
||||
public_lists = (
|
||||
ShoppingList.query.filter(
|
||||
ShoppingList.is_public == True,
|
||||
((ShoppingList.expires_at == None) | (ShoppingList.expires_at > now)),
|
||||
ShoppingList.is_archived == False,
|
||||
date_filter(
|
||||
ShoppingList.query.filter(
|
||||
ShoppingList.is_public == True,
|
||||
(
|
||||
(ShoppingList.expires_at == None)
|
||||
| (ShoppingList.expires_at > now)
|
||||
),
|
||||
ShoppingList.is_archived == False,
|
||||
)
|
||||
)
|
||||
.order_by(ShoppingList.created_at.desc())
|
||||
.all()
|
||||
@@ -710,6 +743,8 @@ def main_page():
|
||||
user_lists=user_lists,
|
||||
public_lists=public_lists,
|
||||
archived_lists=archived_lists,
|
||||
now=now,
|
||||
timedelta=timedelta,
|
||||
)
|
||||
|
||||
|
||||
@@ -1028,16 +1063,24 @@ def user_expenses():
|
||||
)
|
||||
|
||||
|
||||
@app.route("/user/expenses_data")
|
||||
@app.route("/user_expenses_data")
|
||||
@login_required
|
||||
def user_expenses_data():
|
||||
range_type = request.args.get("range", "monthly")
|
||||
start_date = request.args.get("start_date")
|
||||
end_date = request.args.get("end_date")
|
||||
show_all = request.args.get("show_all", "false").lower() == "true"
|
||||
|
||||
query = Expense.query.join(ShoppingList, Expense.list_id == ShoppingList.id).filter(
|
||||
ShoppingList.owner_id == current_user.id
|
||||
)
|
||||
query = Expense.query.join(ShoppingList, Expense.list_id == ShoppingList.id)
|
||||
|
||||
if show_all:
|
||||
query = query.filter(
|
||||
or_(
|
||||
ShoppingList.owner_id == current_user.id, ShoppingList.is_public == True
|
||||
)
|
||||
)
|
||||
else:
|
||||
query = query.filter(ShoppingList.owner_id == current_user.id)
|
||||
|
||||
if start_date and end_date:
|
||||
try:
|
||||
@@ -2110,15 +2153,15 @@ def crop_receipt():
|
||||
old_path = os.path.join(app.config["UPLOAD_FOLDER"], receipt.filename)
|
||||
|
||||
try:
|
||||
image = Image.open(file).convert("RGB")
|
||||
new_filename = generate_new_receipt_filename(receipt.list_id)
|
||||
new_path = os.path.join(app.config["UPLOAD_FOLDER"], new_filename)
|
||||
image.save(new_path, format="WEBP", quality=100)
|
||||
|
||||
save_resized_image(file, new_path)
|
||||
|
||||
if os.path.exists(old_path):
|
||||
os.remove(old_path)
|
||||
|
||||
receipt.filename = new_filename
|
||||
receipt.filename = os.path.basename(new_path)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify(success=True)
|
||||
|
Reference in New Issue
Block a user