Permalink
Browse files

Adding total sum to selected_measures

  • Loading branch information...
1 parent 4fed42d commit c94365dc39f15a5214fa84378d530e725c4f72ba @gijs gijs committed Jun 5, 2012
Showing with 22 additions and 2 deletions.
  1. +1 −1 lizard_blockbox/templates/lizard_blockbox/selected_measures.html
  2. +21 −1 lizard_blockbox/views.py
@@ -75,7 +75,7 @@
{% endfor %}
<h2>Kosten</h2>
- <p>TODO</p>
+ <p>&euro; {{ view.total_cost }} {% trans "m" %}</p>
</div>
</div>
View
@@ -226,19 +226,39 @@ def selected_names(self):
"""Return set of selected measures from session."""
return _selected_measures(self.request)
+ def total_cost(self):
+ reaches = defaultdict(list)
+ measures = models.Measure.objects.filter(
+ short_name__in=self.selected_names())
+ total_cost = 0.0
+ for measure in measures:
+ if measure.total_costs:
+ total_cost = total_cost + measure.total_costs
+ if measure.reach:
+ reach_name = measure.reach.slug
+ else:
+ reach_name = 'unknown'
+ reaches[reach_name].append(measure)
+ result = []
+ return total_cost
+
def measures_per_reach(self):
"""Return selected measures, sorted per reach."""
reaches = defaultdict(list)
measures = models.Measure.objects.filter(
short_name__in=self.selected_names())
+ total_cost = 0.0
for measure in measures:
+ if measure.total_costs:
+ total_cost = total_cost + measure.total_costs
if measure.reach:
reach_name = measure.reach.slug
else:
reach_name = 'unknown'
reaches[reach_name].append(measure)
result = []
- print models.Measure._meta.fields
+ print "total_cost: ", total_cost
+ # print models.Measure._meta.fields
for name, measures in reaches.items():
reach = {'name': name,
'amount': len(measures),

0 comments on commit c94365d

Please sign in to comment.