DRYs QuerysetReport’s headers

This commit is contained in:
Christopher Neugebauer 2016-09-13 18:47:51 +10:00
parent bbce369a38
commit 12b665acb8
2 changed files with 11 additions and 4 deletions

View file

@ -118,11 +118,20 @@ class ListReport(BasicReport):
class QuerysetReport(BasicReport):
def __init__(self, title, headings, attributes, queryset, link_view=None):
def __init__(self, title, attributes, queryset, headings=None,
link_view=None):
super(QuerysetReport, self).__init__(title, headings, link_view=link_view)
self._attributes = attributes
self._queryset = queryset
def headings(self):
if self._headings is not None:
return self._headings
return [
" ".join(i.split("_")).capitalize() for i in self._attributes
]
def rows(self, content_type):
def rgetattr(item, attr):

View file

@ -290,9 +290,9 @@ def attendee(request, form, user_id=None):
)
reports.append(QuerysetReport(
"Invoices",
["Invoice ID", "Status", "Value"],
["id", "get_status_display", "value"],
invoices,
headings=["Invoice ID", "Status", "Value"],
link_view=views.invoice,
))
@ -302,7 +302,6 @@ def attendee(request, form, user_id=None):
)
reports.append(QuerysetReport(
"Credit Notes",
["Note ID", "Status", "Value"],
["id", "status", "value"],
credit_notes,
link_view=views.credit_note,
@ -314,7 +313,6 @@ def attendee(request, form, user_id=None):
)
reports.append(QuerysetReport(
"Payments",
["To Invoice", "Payment ID", "Reference", "Amount"],
["invoice__id", "id", "reference", "amount"],
payments,
link_view=views.invoice,