mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
Add files via upload
implemented the filter feature for bills based on start date and end date.
This commit is contained in:
parent
9433b7de92
commit
9b514ca7c7
2 changed files with 40 additions and 13 deletions
|
@ -264,6 +264,12 @@ class Project(db.Model):
|
||||||
.order_by(Bill.id.desc())
|
.order_by(Bill.id.desc())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def filter(query, start_date, end_date):
|
||||||
|
return (
|
||||||
|
query.filter(Bill.date >= start_date, Bill.date <= end_date)
|
||||||
|
)
|
||||||
|
|
||||||
def get_bill_weights(self):
|
def get_bill_weights(self):
|
||||||
"""
|
"""
|
||||||
Return all bills for this project, along with the sum of weight for each bill.
|
Return all bills for this project, along with the sum of weight for each bill.
|
||||||
|
@ -285,6 +291,9 @@ class Project(db.Model):
|
||||||
"""Ordered version of get_bill_weights"""
|
"""Ordered version of get_bill_weights"""
|
||||||
return self.order_bills(self.get_bill_weights())
|
return self.order_bills(self.get_bill_weights())
|
||||||
|
|
||||||
|
def get_filtered_bill_weights_ordered(self, start_date, end_date):
|
||||||
|
return self.filter(self.get_bill_weights_ordered(), start_date, end_date)
|
||||||
|
|
||||||
def get_member_bills(self, member_id):
|
def get_member_bills(self, member_id):
|
||||||
"""Return the list of bills related to a specific member"""
|
"""Return the list of bills related to a specific member"""
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -642,7 +642,7 @@ def invite():
|
||||||
return render_template("send_invites.html", form=form, qrcode=qrcode_svg)
|
return render_template("send_invites.html", form=form, qrcode=qrcode_svg)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/<project_id>/")
|
@main.route("/<project_id>/", methods=["GET", "POST"])
|
||||||
def list_bills():
|
def list_bills():
|
||||||
bill_form = get_billform_for(g.project)
|
bill_form = get_billform_for(g.project)
|
||||||
# Used for CSRF validation
|
# Used for CSRF validation
|
||||||
|
@ -666,19 +666,37 @@ def list_bills():
|
||||||
# Each item will be a (weight_sum, Bill) tuple.
|
# Each item will be a (weight_sum, Bill) tuple.
|
||||||
# TODO: improve this awkward result using column_property:
|
# TODO: improve this awkward result using column_property:
|
||||||
# https://docs.sqlalchemy.org/en/14/orm/mapped_sql_expr.html.
|
# https://docs.sqlalchemy.org/en/14/orm/mapped_sql_expr.html.
|
||||||
weighted_bills = g.project.get_bill_weights_ordered().paginate(
|
if request.method == "GET":
|
||||||
per_page=100, error_out=True
|
weighted_bills = g.project.get_bill_weights_ordered().paginate(
|
||||||
)
|
per_page=100, error_out=True
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"list_bills.html",
|
||||||
|
bills=weighted_bills,
|
||||||
|
member_form=MemberForm(g.project),
|
||||||
|
bill_form=bill_form,
|
||||||
|
csrf_form=csrf_form,
|
||||||
|
add_bill=request.values.get("add_bill", False),
|
||||||
|
current_view="list_bills",
|
||||||
|
)
|
||||||
|
if request.method == "POST":
|
||||||
|
start_date = request.form['start_date']
|
||||||
|
end_date = request.form['end_date']
|
||||||
|
weighted_bills = g.project.get_filtered_bill_weights_ordered(start_date, end_date).paginate(
|
||||||
|
per_page=100, error_out=True
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"list_bills.html",
|
||||||
|
bills=weighted_bills,
|
||||||
|
member_form=MemberForm(g.project),
|
||||||
|
bill_form=bill_form,
|
||||||
|
csrf_form=csrf_form,
|
||||||
|
add_bill=request.values.get("add_bill", False),
|
||||||
|
current_view="list_bills",
|
||||||
|
start_date=start_date,
|
||||||
|
end_date=end_date,
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
|
||||||
"list_bills.html",
|
|
||||||
bills=weighted_bills,
|
|
||||||
member_form=MemberForm(g.project),
|
|
||||||
bill_form=bill_form,
|
|
||||||
csrf_form=csrf_form,
|
|
||||||
add_bill=request.values.get("add_bill", False),
|
|
||||||
current_view="list_bills",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/<project_id>/members/add", methods=["GET", "POST"])
|
@main.route("/<project_id>/members/add", methods=["GET", "POST"])
|
||||||
|
|
Loading…
Reference in a new issue