diff options
Diffstat (limited to 'budget')
| -rw-r--r-- | budget/models.py | 7 | ||||
| -rw-r--r-- | budget/templates/list_bills.html | 4 | ||||
| -rw-r--r-- | budget/templates/settle_bills.html | 2 | ||||
| -rw-r--r-- | budget/tests.py | 5 | ||||
| -rw-r--r-- | budget/web.py | 9 |
5 files changed, 21 insertions, 6 deletions
diff --git a/budget/models.py b/budget/models.py index 900b1d0..55a97c1 100644 --- a/budget/models.py +++ b/budget/models.py @@ -45,7 +45,7 @@ class Project(db.Model): for person in self.members: balance = should_receive[person] - should_pay[person] - balances[person.id] = round(balance, 2) + balances[person.id] = balance return balances @@ -218,7 +218,10 @@ class Bill(db.Model): def pay_each(self): """Compute what each person has to pay""" - return round(self.amount / len(self.owers), 2) + if self.owers: + return self.amount / len(self.owers) + else: + return 0 def __repr__(self): return "<Bill of %s from %s for %s>" % (self.amount, diff --git a/budget/templates/list_bills.html b/budget/templates/list_bills.html index ee97624..f9d372a 100644 --- a/budget/templates/list_bills.html +++ b/budget/templates/list_bills.html @@ -73,8 +73,8 @@ <form class="action reactivate" action="{{ url_for(".reactivate", member_id=member.id) }}" method="POST"> <button type="submit">{{ _("reactivate") }}</button></form></td> {% endif %} - <td class="balance-value {% if balance[member] > 0 %}positive{% elif balance[member.id] < 0 %}negative{% endif %}"> - {% if balance[member.id] > 0 %}+{% endif %}{{ balance[member.id] }} + <td class="balance-value {% if balance[member.id] > 0 %}positive{% elif balance[member.id] < 0 %}negative{% endif %}"> + {% if balance[member.id] > 0 %}+{% endif %}{{ "%.2f" | format(balance[member.id]) }} </td> </tr> {% endfor %} diff --git a/budget/templates/settle_bills.html b/budget/templates/settle_bills.html index 29d9b26..4066b16 100644 --- a/budget/templates/settle_bills.html +++ b/budget/templates/settle_bills.html @@ -15,7 +15,7 @@ <tr id="bal-member-{{ member.id }}" action={% if member.activated %}delete{% else %}reactivate{% endif %}> <td class="balance-name">{{ member.name }}</td> <td class="balance-value {% if balance[member.id] > 0 %}positive{% elif balance[member.id] < 0 %}negative{% endif %}"> - {% if balance[member.id] > 0 %}+{% endif %}{{ balance[member.id] }} + {% if balance[member.id] > 0 %}+{% endif %}{{ "%.2f" | format(balance[member.id]) }} </td> </tr> {% endfor %} diff --git a/budget/tests.py b/budget/tests.py index 9eea518..0f7c2a2 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -289,6 +289,11 @@ class BudgetTestCase(TestCase): self.assertTrue(models.Project.query.get("demo") is not None) def test_authentication(self): + # try to authenticate without credentials should redirect + # to the authentication page + resp = self.app.post("/authenticate") + self.assertIn("Authentication", resp.data) + # raclette that the login / logout process works self.create_project("raclette") diff --git a/budget/web.py b/budget/web.py index 0b302cd..77de026 100644 --- a/budget/web.py +++ b/budget/web.py @@ -72,7 +72,14 @@ def authenticate(project_id=None): if not form.id.data and request.args.get('project_id'): form.id.data = request.args['project_id'] project_id = form.id.data - project = Project.query.get(project_id) + if project_id is None: + #User doesn't provide project identifier, return to authenticate form + msg = _("You need to enter a project identifier") + form.errors["id"] = [msg] + return render_template("authenticate.html", form=form) + else: + project = Project.query.get(project_id) + create_project = False # We don't want to create the project by default if not project: # But if the user try to connect to an unexisting project, we will |
