diff --git a/budget/forms.py b/budget/forms.py index 0d9dae5..9abbb16 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -1,7 +1,6 @@ from flaskext.wtf import * -from models import Project, Person +from models import Project, Person, Bill -# define forms class ProjectForm(Form): name = TextField("Project name", validators=[Required()]) id = TextField("Project identifier", validators=[Required()]) @@ -34,6 +33,15 @@ class BillForm(Form): validators=[Required()]) submit = SubmitField("Add the bill") + def save(self): + bill = Bill(payer_id=self.payer.data, amount=self.amount.data, + what=self.what.data) + # set the owers + for ower in self.payed_for.data: + bill.owers.append(Person.query.get(ower)) + + return bill + class MemberForm(Form): def __init__(self, project, *args, **kwargs): @@ -48,6 +56,7 @@ class MemberForm(Form): .filter(Person.project == form.project).all(): raise ValidationError("This project already have this member") + class InviteForm(Form): emails = TextAreaField("People to notify") submit = SubmitField("Send invites") diff --git a/budget/models.py b/budget/models.py index c0d6db2..bf9ad92 100644 --- a/budget/models.py +++ b/budget/models.py @@ -24,6 +24,9 @@ class Person(db.Model): name = db.Column(db.UnicodeText) # activated = db.Column(db.Boolean, default=True) + def __str__(self): + return self.name + def __repr__(self): return "" % (self.name, self.project.name) diff --git a/budget/static/main.css b/budget/static/main.css index 0ca39ff..d8f25f9 100644 --- a/budget/static/main.css +++ b/budget/static/main.css @@ -37,7 +37,9 @@ float: right; } #topmenu ul li{ + float: right; list-style-type: none; + margin-left: 10px; } /** links **/ diff --git a/budget/templates/add_bill.html b/budget/templates/add_bill.html index 8dec74c..f959a64 100644 --- a/budget/templates/add_bill.html +++ b/budget/templates/add_bill.html @@ -9,7 +9,13 @@ {% if form.errors %}

Your form contains errors.

- + {% endif %}
diff --git a/budget/templates/layout.html b/budget/templates/layout.html index 25c5dd7..cd0fca4 100644 --- a/budget/templates/layout.html +++ b/budget/templates/layout.html @@ -9,11 +9,11 @@

Account manager ! Manage your shared expenses.

+
{% block top_menu %}{% endblock %}
-
{% for message in get_flashed_messages() %}
{{ message }}
{% endfor %} diff --git a/budget/templates/list_bills.html b/budget/templates/list_bills.html index 8f07f9b..a26dccc 100644 --- a/budget/templates/list_bills.html +++ b/budget/templates/list_bills.html @@ -2,8 +2,7 @@ {% block top_menu %} {% endblock %} diff --git a/budget/utils.py b/budget/utils.py index a5f1474..20989e9 100644 --- a/budget/utils.py +++ b/budget/utils.py @@ -7,7 +7,7 @@ from forms import BillForm def get_billform_for(project_id): """Return an instance of BillForm configured for a particular project.""" form = BillForm() - payers = [(m.id, m.name) for m in Project.query.get(project_id).members] + payers = [(str(m.id), m.name) for m in Project.query.get(project_id).members] form.payed_for.choices = form.payer.choices = payers return form diff --git a/budget/web.py b/budget/web.py index 10b2d4a..f313266 100644 --- a/budget/web.py +++ b/budget/web.py @@ -123,18 +123,11 @@ def add_bill(project): form = get_billform_for(project.id) if request.method == 'POST': if form.validate(): - bill = Bill() - form.populate_obj(bill) - - for ower in form.payed_for.data: - ower = BillOwer(name=ower) - db.session.add(ower) - bill.owers.append(ower) - - db.session.add(bill) + db.session.add(form.save()) db.session.commit() + flash("The bill have been added") - return redirect(url_for('list_bills')) + return redirect(url_for('list_bills', project_id=project.id)) return render_template("add_bill.html", form=form, project=project)