Code formatting

This commit is contained in:
fleaz 2021-12-20 01:39:34 +01:00
parent 8ccf2f2646
commit 3511095be8

View file

@ -39,26 +39,30 @@ def index():
)
if tag_sum:
if tag_sum >= 0:
tag_sum_in[tag] = {"sum":tag_sum, "monthly": floor(tag_sum/months)}
tag_sum_in[tag] = {"sum": tag_sum, "monthly": floor(tag_sum / months)}
else:
tag_sum_out[tag] = {"sum":tag_sum, "monthly": floor(tag_sum/months)}
tag_sum_out[tag] = {"sum": tag_sum, "monthly": floor(tag_sum / months)}
monthly_sum = { "in": format_amount(sum([v["monthly"] for k,v in tag_sum_in.items()])),
"out":format_amount(sum([v["monthly"] for k,v in tag_sum_out.items()]))}
monthly_sum = {
"in": format_amount(sum([v["monthly"] for k, v in tag_sum_in.items()])),
"out": format_amount(sum([v["monthly"] for k, v in tag_sum_out.items()])),
}
tag_sum_in = {
k: format_amount(v) for k, v in sorted(tag_sum_in.items(), key=lambda item: float(item[1]["sum"]), reverse=True)
}
tag_sum_out = {k: format_amount(v) for k, v in sorted(tag_sum_out.items(), key=lambda item: float(item[1]["sum"]))}
return render_template("index.html", tag_sum_in=tag_sum_in, tag_sum_out=tag_sum_out, months=months, monthly_sum=monthly_sum)
return render_template(
"index.html", tag_sum_in=tag_sum_in, tag_sum_out=tag_sum_out, months=months, monthly_sum=monthly_sum
)
@app.route("/tags")
def tags():
tags = session.query(Tag).all()
#Sort alphabetically
tags = sorted(tags, key=lambda item:item.name)
# Sort alphabetically
tags = sorted(tags, key=lambda item: item.name)
return render_template("tags.html", tags=tags)
@ -66,11 +70,17 @@ def tags():
def tag(name):
tag = session.query(Tag).filter(Tag.name == name).first()
transactions = session.query(Transaction).filter(Transaction.tags.any(id=tag.id)).all()
sum_months = session.query(func.sum(Transaction.amount).label("amount"), func.strftime("%Y-%m",Transaction.date).label("month")).filter(Transaction.tags.any(id=tag.id)).group_by("month").all()
sum_months = (
session.query(
func.sum(Transaction.amount).label("amount"), func.strftime("%Y-%m", Transaction.date).label("month")
)
.filter(Transaction.tags.any(id=tag.id))
.group_by("month")
.all()
)
months = []
for m in sum_months:
months.append({'amount' : format_amount(m['amount']),
"month": m['month']})
months.append({"amount": format_amount(m["amount"]), "month": m["month"]})
return render_template("tag.html", tag=tag, months=months, transactions=transactions)