Luke Plant committed 11c65bc

Added spreadsheet for booking secretary

Comments (0)

Files changed (4)


 from dateutil.relativedelta import relativedelta
+from cciw.bookings.models import Booking
 def camp_bookings_to_spreadsheet(camp, spreadsheet):
     bookings = list(camp.bookings.confirmed().order_by('first_name', 'last_name'))
     return spreadsheet.to_string()
+# Spreadsheet needed by booking secretary
+def year_bookings_to_spreadsheet(year, spreadsheet):
+    bookings = Booking.objects.filter(camp__year=year).order_by('camp__number', 'account__name', 'first_name', 'last_name').select_related('camp', 'account')
+    columns = [
+        ('Camp', lambda b:,
+        ('Account', lambda b:,
+        ('First name', lambda b: b.first_name),
+        ('Last name', lambda b: b.last_name),
+        ('Sex', lambda b: b.get_sex_display()),
+        ('State', lambda b: b.get_state_display()),
+        ('Confirmed', lambda b: b.confirmed_booking()),
+        ('Date created', lambda b: b.created),
+        ]
+    spreadsheet.add_sheet_with_header_row("All bookings",
+                                          [n for n, f in columns],
+                                          [[f(b) for n, f in columns]
+                                           for b in bookings])
+    return spreadsheet.to_string()


     (r'^leaders/officer-list/(?P<year>\d{4})/(?P<number>\d+)/$', 'officer_list'),
     (r'^leaders/export-officer-data/(?P<year>\d{4})/(?P<number>\d+)/$', 'export_officer_data'),
     (r'^leaders/export-camper-data/(?P<year>\d{4})/(?P<number>\d+)/$', 'export_camper_data'),
+    (r'^leaders/export-camper-data/(?P<year>\d{4})/$', 'export_camper_data_for_year'),
     (r'^leaders/remove-officer/(?P<year>\d{4})/(?P<number>\d+)/$', 'remove_officer'),
     (r'^leaders/add-officers/(?P<year>\d{4})/(?P<number>\d+)/$', 'add_officers'),
     (r'^leaders/update-officer/$', 'update_officer'),


 from django.views.generic.base import TemplateView
 from cciw.auth import is_camp_admin, is_wiki_user, is_cciw_secretary, is_camp_officer, is_booking_secretary
-from cciw.bookings.utils import camp_bookings_to_spreadsheet
+from cciw.bookings.utils import camp_bookings_to_spreadsheet, year_bookings_to_spreadsheet
 from cciw.cciwmain import common
 from cciw.cciwmain.decorators import json_response
 from cciw.cciwmain.models import Camp
     return response
+def export_camper_data_for_year(request, year=None):
+    year = int(year)
+    formatter = get_spreadsheet_formatter(request)
+    response = HttpResponse(year_bookings_to_spreadsheet(year, formatter),
+                            mimetype=formatter.mimetype)
+    response['Content-Disposition'] = ('attachment; filename=CCIW-bookings-%d.%s'
+                                       % (year, formatter.file_ext))
+    return response
 officer_files = access_folder_securely("officers",
                                        lambda request: request.user.is_authenticated() and is_camp_officer(request.user))


   {% if show_booking_secretary_links %}
   <li><a href="/admin/bookings/">Manage bookings</a></li>
   <li><a href="{% url 'cciw.officers.views.booking_secretary_reports' thisyear %}">Booking reports</a></li>
+  <li><a href="{% url 'cciw.officers.views.export_camper_data_for_year' thisyear %}?format=xls">Download bookings data (xls)</a></li>
   {% endif %}
   <li><a href="{% url 'cciw.officers.views.applications' %}">Submit/view applications</a></li>
   <li><a href="{% url '' %}">Information about camp</a></li>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.