mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Add a set_default argument to the get_billform_for function.
This commit is contained in:
parent
67350e7acc
commit
065fe965a0
2 changed files with 12 additions and 5 deletions
|
@ -4,11 +4,19 @@ from flask import redirect, url_for, session, request
|
|||
from models import Bill, Project
|
||||
from forms import BillForm
|
||||
|
||||
def get_billform_for(project):
|
||||
"""Return an instance of BillForm configured for a particular project."""
|
||||
def get_billform_for(project, set_default=True):
|
||||
"""Return an instance of BillForm configured for a particular project.
|
||||
|
||||
:set_default: if set to True, on GET methods (usually when we want to
|
||||
display the default form, it will call set_default on it.
|
||||
|
||||
"""
|
||||
form = BillForm()
|
||||
form.payed_for.choices = form.payer.choices = [(str(m.id), m.name) for m in project.active_members]
|
||||
form.payed_for.default = [ str(m.id) for m in project.active_members]
|
||||
form.payed_for.default = [str(m.id) for m in project.active_members]
|
||||
|
||||
if set_default and request.method == "GET":
|
||||
form.set_default()
|
||||
return form
|
||||
|
||||
def requires_auth(f):
|
||||
|
|
|
@ -173,7 +173,6 @@ def add_bill(project):
|
|||
flash("The bill has been added")
|
||||
return redirect(url_for('list_bills', project_id=project.id))
|
||||
|
||||
form.set_default()
|
||||
return render_template("add_bill.html", form=form, project=project)
|
||||
|
||||
|
||||
|
@ -192,7 +191,7 @@ def delete_bill(project, bill_id):
|
|||
@requires_auth
|
||||
def edit_bill(project, bill_id):
|
||||
bill = Bill.query.get_or_404(bill_id)
|
||||
form = get_billform_for(project)
|
||||
form = get_billform_for(project, set_default=False)
|
||||
if request.method == 'POST' and form.validate():
|
||||
form.save(bill)
|
||||
db.session.commit()
|
||||
|
|
Loading…
Reference in a new issue