Changeset - 12b665acb8c7
[Not reviewed]
0 2 0
Christopher Neugebauer - 8 years ago 2016-09-13 08:47:51
chrisjrn@gmail.com
DRYs QuerysetReport’s headers
2 files changed with 11 insertions and 4 deletions:
0 comments (0 inline, 0 general)
registrasion/reporting/reports.py
Show inline comments
...
 
@@ -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):
registrasion/reporting/views.py
Show inline comments
...
 
@@ -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,
0 comments (0 inline, 0 general)