Permalink
Browse files

Adding total sum to selected_measures

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

0 comments on commit c94365d

Please sign in to comment.