aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA.Avenel <avenel.alexandre@gmail.com>2011-12-03 22:25:19 +0100
committerA.Avenel <avenel.alexandre@gmail.com>2011-12-03 22:25:19 +0100
commit1a5abcfbf2c9ceb137b42c177013bd0f54d571fe (patch)
tree27b66d35575d5157d2c72a32409987eea0ed5264
parent0633b153f604d973d1b8a6b5c25d9b048a3de0bb (diff)
downloadihatemoney-mirror-1a5abcfbf2c9ceb137b42c177013bd0f54d571fe.zip
ihatemoney-mirror-1a5abcfbf2c9ceb137b42c177013bd0f54d571fe.tar.gz
ihatemoney-mirror-1a5abcfbf2c9ceb137b42c177013bd0f54d571fe.tar.bz2
Fix for a bug introduced in last commit : crash of dashboard view when there is no bill.
-rw-r--r--budget/models.py4
-rw-r--r--budget/templates/dashboard.html11
2 files changed, 14 insertions, 1 deletions
diff --git a/budget/models.py b/budget/models.py
index b889794..3dcd709 100644
--- a/budget/models.py
+++ b/budget/models.py
@@ -44,6 +44,10 @@ class Project(db.Model):
return balances
+ def has_bills(self):
+ """return if the project do have bills or not"""
+ return self.get_bills().count() != 0
+
def get_bills(self):
"""Return the list of bills related to this project"""
return Bill.query.join(Person, Project)\
diff --git a/budget/templates/dashboard.html b/budget/templates/dashboard.html
index 44ece2d..796f4f4 100644
--- a/budget/templates/dashboard.html
+++ b/budget/templates/dashboard.html
@@ -4,7 +4,16 @@
<table id="bill_table" class="list_bills common-table zebra-striped">
<thead><tr><th>{{ _("Project") }}</th><th>{{ _("Number of members") }}</th><th>{{ _("Number of bills") }}</th><th>{{_("Newest bill")}}</th><th>{{_("Oldest bill")}}</th></tr></thead>
<tbody>{% for project in projects %}
- <tr><td>{{ project.name }}</td><td>{{ project.members | count }}</td><td>{{ project.get_bills().count() }}</td><td>{{ project.get_bills()[1].date }}</td><td>{{ project.get_bills()[-1].date }}</tr>
+ <tr>
+<td>{{ project.name }}</td><td>{{ project.members | count }}</td><td>{{ project.get_bills().count() }}</td>
+{% if project.has_bills() %}
+<td>{{ project.get_bills()[0].date }}</td>
+<td>{{ project.get_bills()[-1].date }}</td>
+{% else %}
+<td></td>
+<td></td>
+{% endif %}
+</tr>
{% endfor %}</tbody>
</table>
{% endblock %}