Allows for callable attributes to be specified in QuerysetReports.

This commit is contained in:
Christopher Neugebauer 2016-09-13 18:44:13 +10:00
parent 4c9f426a47
commit bbce369a38
2 changed files with 14 additions and 13 deletions

View file

@ -128,6 +128,13 @@ class QuerysetReport(BasicReport):
def rgetattr(item, attr):
for i in attr.split("__"):
item = getattr(item, i)
if callable(item):
try:
return item()
except TypeError:
pass
return item
for row in self._queryset:

View file

@ -285,21 +285,16 @@ def attendee(request, form, user_id=None):
))
# Invoices
# TODO make this a querysetreport
headings = ["Invoice ID", "Status", "Value"]
data = []
invoices = commerce.Invoice.objects.filter(
user=attendee.user,
)
for invoice in invoices:
data.append([
invoice.id, invoice.get_status_display(), invoice.value,
])
reports.append(
ListReport("Invoices", headings, data, link_view=views.invoice)
)
reports.append(QuerysetReport(
"Invoices",
["Invoice ID", "Status", "Value"],
["id", "get_status_display", "value"],
invoices,
link_view=views.invoice,
))
# Credit Notes
credit_notes = commerce.CreditNote.objects.filter(
@ -325,7 +320,6 @@ def attendee(request, form, user_id=None):
link_view=views.invoice,
))
return reports