def export_events(eventadmin, request, queryset):
    """
    Helper function to export registrations to an excel file."""
    wb = Workbook()
    for event in queryset:
        # Put each event in it's own sheet
        s = wb.add_sheet(event.slug[:30])  # this is the max number of characters for an excel tab
        # Write header
        s.write(0, 0, "Voornaam")
        s.write(0, 1, "Achternaam")
        s.write(0, 2, "Email")
        s.write(0, 3, "Betaald")
        s.write(0, 4, "Prijs")
        s.write(0, 5, "Purchase ID")
        col_count = 6

        q_to_col = {}
        for question in event.eventquestion_set.all():
            if question.question_type == "TEXT":
                continue
            q_to_col[question.id] = col_count
            s.write(0, col_count, question.name)
            col_count += 1

        # Write the data
        row = 1
        for reg in event.registrations.all():
            s.write(row, 0, reg.first_name)
            s.write(row, 1, reg.last_name)
            s.write(row, 2, reg.email)
            s.write(row, 3, reg.paid)
            s.write(row, 4, 100 / float(reg.price))
            s.write(row, 5, reg.id)

            for ans in reg.answers.all():
                s.write(row, q_to_col[ans.question.id], '{}'.format(ans.get_answer()))

            row += 1

    out = BytesIO.BytesIO()
    wb.save(out)
    response = HttpResponse(out.getvalue(), content_type="application/excel")
    response['Content-Disposition'] = 'attachment; filename=events.xls'
    return response
dataset/ETHPy150Open jonge-democraten/dyonisos/subscribe/admin.py/export_events/swapped operands of `/`