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
...
 
@@ -109,29 +109,38 @@ class ListReport(BasicReport):
 
    def rows(self, content_type):
 
        ''' Returns the data rows for the table. '''
 

	
 
        for row in self._data:
 
            yield [
 
                self.cell_text(content_type, i, cell)
 
                for i, cell in enumerate(row)
 
            ]
 

	
 

	
 
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):
 
            for i in attr.split("__"):
 
                item = getattr(item, i)
 

	
 
            if callable(item):
 
                try:
 
                    return item()
 
                except TypeError:
 
                    pass
 

	
registrasion/reporting/views.py
Show inline comments
...
 
@@ -281,49 +281,47 @@ def attendee(request, form, user_id=None):
 
    reports.append(ListReport(
 
        "Unpaid Products",
 
        ["Product", "Quantity"],
 
        [(pq.product, pq.quantity) for pq in ic.items_pending()],
 
    ))
 

	
 
    # Invoices
 
    invoices = commerce.Invoice.objects.filter(
 
        user=attendee.user,
 
    )
 
    reports.append(QuerysetReport(
 
        "Invoices",
 
        ["Invoice ID", "Status", "Value"],
 
        ["id", "get_status_display", "value"],
 
        invoices,
 
        headings=["Invoice ID", "Status", "Value"],
 
        link_view=views.invoice,
 
    ))
 

	
 
    # Credit Notes
 
    credit_notes = commerce.CreditNote.objects.filter(
 
        invoice__user=attendee.user,
 
    )
 
    reports.append(QuerysetReport(
 
        "Credit Notes",
 
        ["Note ID", "Status", "Value"],
 
        ["id", "status", "value"],
 
        credit_notes,
 
        link_view=views.credit_note,
 
    ))
 

	
 
    # All payments
 
    payments = commerce.PaymentBase.objects.filter(
 
        invoice__user=attendee.user,
 
    )
 
    reports.append(QuerysetReport(
 
        "Payments",
 
        ["To Invoice", "Payment ID", "Reference", "Amount"],
 
        ["invoice__id", "id", "reference", "amount"],
 
        payments,
 
        link_view=views.invoice,
 
    ))
 

	
 
    return reports
 

	
 

	
 
def attendee_list(request):
 
    ''' Returns a list of all attendees. '''
 

	
 
    attendees = people.Attendee.objects.all().select_related(
0 comments (0 inline, 0 general)