Changeset - ea07469634ee
[Not reviewed]
0 2 0
Christopher Neugebauer - 8 years ago 2016-12-06 23:18:48
chrisjrn@gmail.com
Fixes individual attendee view, which had disappeared.
2 files changed with 7 insertions and 2 deletions:
0 comments (0 inline, 0 general)
registrasion/reporting/reports.py
Show inline comments
...
 
@@ -232,81 +232,84 @@ class ReportView(object):
 

	
 
            # Pre-validate it
 
            form.is_valid()
 
        else:
 
            form = None
 

	
 
        return form
 

	
 
    @classmethod
 
    def wrap_reports(cls, reports, content_type):
 
        reports = [
 
            _ReportTemplateWrapper(content_type, report)
 
            for report in reports
 
        ]
 

	
 
        return reports
 

	
 
    def render(self, data):
 
        renderers = {
 
            "text/csv": self._render_as_csv,
 
            "text/html": self._render_as_html,
 
            None: self._render_as_html,
 
        }
 
        render = renderers[data.content_type]
 
        return render(data)
 

	
 
    def _render_as_html(self, data):
 
        ctx = {
 
            "title": self.title,
 
            "form": data.form,
 
            "reports": data.reports,
 
        }
 

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

	
 
    def _render_as_csv(self, data):
 
        report = data.reports[data.section]
 

	
 
        # Create the HttpResponse object with the appropriate CSV header.
 
        response = HttpResponse(content_type='text/csv')
 

	
 
        writer = csv.writer(response)
 
        encode = lambda i: i.encode("utf8") if isinstance(i, unicode) else i
 
        writer.writerow(list(encode(i) for i in report.headings()))
 
        for row in report.rows():
 
            writer.writerow(list(encode(i) for i in row))
 

	
 
        return response
 

	
 

	
 
class ReportViewRequestData(object):
 

	
 
    def __init__(self, report_view, request, *a, **k):
 
        self.report_view = report_view
 
        self.request = request
 

	
 
        # Calculate other data
 
        self.form = report_view.get_form(request)
 

	
 
        # Content type and section come from request.GET
 
        self.content_type = request.GET.get("content_type")
 
        self.section = request.GET.get("section")
 
        self.section = int(self.section) if self.section else None
 

	
 
        if self.content_type is None:
 
            self.content_type = "text/html"
 

	
 
        # Reports come from calling the inner view
 
        reports = report_view.inner_view(request, self.form, *a, **k)
 

	
 
        # Normalise to a list
 
        if isinstance(reports, Report):
 
            reports = [reports]
 

	
 
        # Wrap them in appropriate format
 
        reports = ReportView.wrap_reports(reports, self.content_type)
 

	
 
        self.reports = reports
 

	
 

	
 
def get_all_reports():
 
    ''' Returns all the views that have been registered with @report '''
 

	
 
    return list(_all_report_views)
registrasion/reporting/views.py
Show inline comments
...
 
@@ -347,133 +347,135 @@ def paid_invoices_by_date(request, form):
 
    )
 

	
 
    by_date = collections.defaultdict(int)
 
    for time in times:
 
        date = datetime.datetime(
 
            year=time.year, month=time.month, day=time.day
 
        )
 
        by_date[date] += 1
 

	
 
    data = [(date, count) for date, count in sorted(by_date.items())]
 
    data = [(date.strftime("%Y-%m-%d"), count) for date, count in data]
 

	
 
    return ListReport(
 
        "Paid Invoices By Date",
 
        ["date", "count"],
 
        data,
 
    )
 

	
 
@report_view("Credit notes")
 
def credit_notes(request, form):
 
    ''' Shows all of the credit notes in the system. '''
 

	
 
    notes = commerce.CreditNote.objects.all().select_related(
 
        "creditnoterefund",
 
        "creditnoteapplication",
 
        "invoice",
 
        "invoice__user__attendee__attendeeprofilebase",
 
    )
 

	
 
    return QuerysetReport(
 
        "Credit Notes",
 
        ["id", "invoice__user__attendee__attendeeprofilebase__invoice_recipient", "status", "value"],  # NOQA
 
        notes,
 
        headings=["id", "Owner", "Status", "Value"],
 
        link_view=views.credit_note,
 
    )
 

	
 

	
 
@report_view("Invoices")
 
def invoices(request,form):
 
    ''' Shows all of the invoices in the system. '''
 

	
 
    invoices = commerce.Invoice.objects.all().order_by("status")
 

	
 
    return QuerysetReport(
 
        "Invoices",
 
        ["id", "recipient", "value", "get_status_display"],
 
        invoices,
 
        headings=["id", "Recipient", "Value", "Status"],
 
        link_view=views.invoice,
 
    )
 

	
 

	
 
class AttendeeListReport(ListReport):
 

	
 
    def get_link(self, argument):
 
        return reverse(self._link_view) + "?user=%d" % int(argument)
 

	
 

	
 
@report_view("Attendee", form_type=forms.UserIdForm)
 
def attendee(request, form, user_id=None):
 
    ''' Returns a list of all manifested attendees if no attendee is specified,
 
    else displays the attendee manifest. '''
 

	
 
    if user_id is None and form.cleaned_data["user"] is not None:
 
        user_id = form.cleaned_data["user"]
 

	
 
    if user_id is None:
 
        return attendee_list(request)
 

	
 
    if form.cleaned_data["user"] is not None:
 
        user_id = form.cleaned_data["user"]
 
    print user_id
 

	
 
    attendee = people.Attendee.objects.get(user__id=user_id)
 
    name = attendee.attendeeprofilebase.attendee_name()
 

	
 
    reports = []
 

	
 
    profile_data = []
 
    try:
 
        profile = people.AttendeeProfileBase.objects.get_subclass(
 
            attendee=attendee
 
        )
 
        fields = profile._meta.get_fields()
 
    except people.AttendeeProfileBase.DoesNotExist:
 
        fields = []
 

	
 
    exclude = set(["attendeeprofilebase_ptr", "id"])
 
    for field in fields:
 
        if field.name in exclude:
 
            # Not actually important
 
            continue
 
        if not hasattr(field, "verbose_name"):
 
            continue  # Not a publicly visible field
 
        value = getattr(profile, field.name)
 

	
 
        if isinstance(field, models.ManyToManyField):
 
            value = ", ".join(str(i) for i in value.all())
 

	
 
        profile_data.append((field.verbose_name, value))
 

	
 
    cart = CartController.for_user(attendee.user)
 
    reservation = cart.cart.reservation_duration + cart.cart.time_last_updated
 
    profile_data.append(("Current cart reserved until", reservation))
 

	
 
    reports.append(ListReport("Profile", ["", ""], profile_data))
 

	
 
    links = []
 
    links.append((
 
        reverse(views.amend_registration, args=[user_id]),
 
        "Amend current cart",
 
    ))
 
    links.append((
 
        reverse(views.extend_reservation, args=[user_id]),
 
        "Extend reservation",
 
    ))
 

	
 
    reports.append(Links("Actions for " + name, links))
 

	
 
    # Paid and pending  products
 
    ic = ItemController(attendee.user)
 
    reports.append(ListReport(
 
        "Paid Products",
 
        ["Product", "Quantity"],
 
        [(pq.product, pq.quantity) for pq in ic.items_purchased()],
 
    ))
 
    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,
 
    )
0 comments (0 inline, 0 general)