Changeset - 6fb680931627
[Not reviewed]
0 4 0
Joel Addison - 5 years ago 2019-10-13 12:22:15
joel@addison.net.au
Improve registration report formatting

Show title in list instead of method name.
Add page title and head title to reports.
4 files changed with 11 insertions and 3 deletions:
0 comments (0 inline, 0 general)
pinaxcon/templates/registrasion/report.html
Show inline comments
 
{% extends "site_base.html" %}
 
{% load bootstrap %}
 
{% load registrasion_tags %}
 

	
 
{% block page_title %}Registration report{% endblock %}
 
{% block head_title %}Registration report - {{ title }}{% endblock %}
 

	
 
{% block content %}
 

	
 
  <h2>{{ title }}</h2>
 

	
 
  <p><a href="{% url 'reports_list' %}">Return to reports list</a></p>
 

	
 
  {% if form %}
 
    <form class="form-horizontal" method="GET">
 
      {{ form | bootstrap}}
 
      <br/>
 
      <input class="btn btn-primary" type="submit">
 
    </form>
 
  {% endif %}
 
<hr />
 

	
 
{% for report in reports %}
 
<h3>{{ report.title }}</h3>
 
{% if report.headings %}
 
<table class="table table-striped table-reportdata">
 
{% else %}
 
    <table class="table table-striped">
 
{% endif %}
 
    <thead>
 
        <tr>
pinaxcon/templates/registrasion/reports_list.html
Show inline comments
 
{% extends "site_base.html" %}
 
{% load registrasion_tags %}
 
{% block content %}
 

	
 
<h2>Registration reports</h2>
 
{% block page_title %}Registration reports{% endblock %}
 
{% block head_title %}Registration reports{% endblock %}
 

	
 
{% block content %}
 
<table class="table table-striped">
 
  {% for report in reports %}
 
    <tr>
 
      <td>
 
        <a href="{{ report.url }}">{{ report.name }}</a>
 
        <a href="{{ report.url }}">{{ report.title }}</a>
 
      </td>
 
      <td>
 
        {{ report.description }}
 
      </td>
 
    </tr>
 
  {% endfor %}
 
</table>
 

	
 
{% endblock %}
vendor/registrasion/registrasion/reporting/reports.py
Show inline comments
...
 
@@ -57,48 +57,49 @@ class Report(object):
 
    def _html_link(address, text):
 
        return '<a href="%s">%s</a>' % (address, text)
 

	
 

	
 
class _ReportTemplateWrapper(object):
 
    ''' Used internally to pass `Report` objects to templates. They effectively
 
    are used to specify the content_type for a report. '''
 

	
 
    def __init__(self, content_type, report):
 
        self.content_type = content_type
 
        self.report = report
 

	
 
    def title(self):
 
        return self.report.title()
 

	
 
    def headings(self):
 
        return self.report.headings()
 

	
 
    def rows(self):
 
        return self.report.rows(self.content_type)
 

	
 
    def count(self):
 
        return self.report.count()
 

	
 

	
 
class BasicReport(Report):
 

	
 
    def __init__(self, title, headings, link_view=None):
 
        super(BasicReport, self).__init__()
 
        self._title = title
 
        self._headings = headings
 
        self._link_view = link_view
 

	
 
    def title(self):
 
        ''' Returns the title for this report. '''
 
        return self._title
 

	
 
    def headings(self):
 
        ''' Returns the headings for the table. '''
 
        return self._headings
 

	
 
    def cell_text(self, content_type, index, text):
 
        if index > 0 or not self._link_view:
 
            return text
 
        else:
 
            address = self.get_link(text)
 
            return self._linked_text(content_type, address, text)
 

	
 
    def get_link(self, argument):
...
 
@@ -145,75 +146,77 @@ class QuerysetReport(BasicReport):
 
    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
 

	
 
            return item
 

	
 
        for row in self._queryset:
 
            yield [
 
                self.cell_text(content_type, i, rgetattr(row, attribute))
 
                for i, attribute in enumerate(self._attributes)
 
            ]
 

	
 

	
 
    def count(self):
 
        return self._queryset.count()
 

	
 

	
 
class Links(Report):
 

	
 
    def __init__(self, title, links):
 
        '''
 
        Arguments:
 
            links ([tuple, ...]): a list of 2-tuples:
 
                (url, link_text)
 

	
 
        '''
 
        self._title = title
 
        self._links = links
 

	
 
    def title(self):
 
        return self._title
 

	
 
    def headings(self):
 
        return []
 

	
 
    def rows(self, content_type):
 
        for url, link_text in self._links:
 
            yield [
 
                self._linked_text(content_type, url, link_text)
 
            ]
 

	
 
    def count(self):
 
        return len(self._links)
 

	
 

	
 
def report_view(title, form_type=None):
 
    ''' Decorator that converts a report view function into something that
 
    displays a Report.
 

	
 
    Arguments:
 
        title (str):
 
            The title of the report.
 
        form_type (Optional[forms.Form]):
 
            A form class that can make this report display things. If not
 
            supplied, no form will be displayed.
 

	
 
    '''
 

	
 
    # Create & return view
 
    def _report(view):
 
        report_view = ReportView(view, title, form_type)
 
        report_view = user_passes_test(views._staff_only)(report_view)
 
        report_view = wraps(view)(report_view)
 

	
 
        # Add this report to the list of reports.
 
        _all_report_views.append(report_view)
 

	
 
        return report_view
 

	
vendor/registrasion/registrasion/reporting/views.py
Show inline comments
...
 
@@ -30,48 +30,49 @@ from .reports import get_all_reports
 
from .reports import Links
 
from .reports import ListReport
 
from .reports import QuerysetReport
 
from .reports import report_view
 

	
 
import bleach
 

	
 

	
 
def CURRENCY():
 
    return models.DecimalField(decimal_places=2)
 

	
 

	
 
AttendeeProfile = util.get_object_from_name(settings.ATTENDEE_PROFILE_MODEL)
 

	
 

	
 
@user_passes_test(views._staff_only)
 
def reports_list(request):
 
    ''' Lists all of the reports currently available. '''
 

	
 
    reports = []
 

	
 
    for report in get_all_reports():
 
        reports.append({
 
            "name": report.__name__,
 
            "title": report.title,
 
            "url": reverse(report),
 
            "description": report.__doc__,
 
        })
 

	
 
    reports.sort(key=lambda report: report["name"])
 

	
 
    ctx = {
 
        "reports": reports,
 
    }
 

	
 
    return render(request, "registrasion/reports_list.html", ctx)
 

	
 

	
 
# Report functions
 

	
 
@report_view("Reconcilitation")
 
def reconciliation(request, form):
 
    ''' Shows the summary of sales, and the full history of payments and
 
    refunds into the system. '''
 

	
 
    return [
 
        sales_payment_summary(),
 
        items_sold(),
 
        payments(),
0 comments (0 inline, 0 general)