Add Unit column to Usage Report table

Change-Id: I8f96195d4fce2d64011e6ef71c8d70db2c9de877
Closes-Bug: #1411066
This commit is contained in:
Cindy Lu 2015-01-26 14:43:40 -08:00
parent 359f92fa34
commit 2839f3b130
3 changed files with 9 additions and 5 deletions

View File

@ -46,6 +46,7 @@ class ReportTable(tables.DataTable):
filters=[show_date])
value = tables.Column('value', verbose_name=_('Value (Avg)'),
filters=[humanize.intcomma])
unit = tables.Column('unit', verbose_name=_('Unit'))
def get_object_id(self, obj):
return "%s-%s-%s" % (obj['project'], obj['service'], obj['meter'])

View File

@ -106,7 +106,8 @@ class UsageReportTab(tabs.TableTab):
"description": meter.description,
"service": service,
"time": value._apiresource.period_end,
"value": value._apiresource.avg}
"value": value._apiresource.avg,
"unit": meter.unit}
report_rows.append(row)
return report_rows

View File

@ -196,7 +196,7 @@ class CsvReportView(django.views.generic.View):
class ReportCsvRenderer(csvbase.BaseCsvResponse):
columns = [_("Project Name"), _("Meter"), _("Description"),
_("Service"), _("Time"), _("Value (Avg)")]
_("Service"), _("Time"), _("Value (Avg)"), _("Unit")]
def get_row_data(self):
@ -207,7 +207,8 @@ class ReportCsvRenderer(csvbase.BaseCsvResponse):
u["description"],
u["service"],
u["time"],
u["value"])
u["value"],
u["unit"])
def load_report_data(request):
@ -230,7 +231,7 @@ def load_report_data(request):
date_to,
date_options)
except Exception:
exceptions.handle(request, _('Dates cannot be recognised.'))
exceptions.handle(request, _('Dates cannot be recognized.'))
try:
project_aggregates = utils_metering.ProjectAggregatesQuery(request,
date_from,
@ -256,7 +257,8 @@ def load_report_data(request):
"description": meter.description,
"service": service,
"time": value._apiresource.period_end,
"value": value._apiresource.avg}
"value": value._apiresource.avg,
"unit": meter.unit}
if r.id not in project_rows:
project_rows[r.id] = [row]
else: