Commits

Luke Plant committed a7fab9e

Updated export of officer data to use spreadsheet abstraction

Comments (0)

Files changed (3)

cciw/officers/tests/officerlist.py

 from cciw.cciwmain.models import Camp
 from cciw.officers.models import Invitation, Application
 from cciw.officers.tests.references import OFFICER, LEADER
-from cciw.officers.utils import officer_data_to_xls
+from cciw.officers.utils import officer_data_to_spreadsheet
+from cciw.utils.spreadsheet import ExcelFormatter
 
 
 class TestExport(TestCase):
             inv.notes = "Some notes %s" % i
             inv.save()
 
-        workbook = officer_data_to_xls(c)
+        workbook = officer_data_to_spreadsheet(c, ExcelFormatter())
 
         self.assertTrue(workbook is not None)
         wkbk = xlrd.open_workbook(file_contents=workbook)
         app = Application.objects.get(pk=1)
         assert app.officer == u
 
-        workbook = officer_data_to_xls(c)
+        workbook = officer_data_to_spreadsheet(c, ExcelFormatter())
 
         wkbk = xlrd.open_workbook(file_contents=workbook)
         wksh = wkbk.sheet_by_index(0)

cciw/officers/utils.py

 """
 Utility functions for officers app.
 """
-import xlwt
-
-from cciw.utils.xl import add_sheet_with_header_row, workbook_to_string
-
 
 def camp_officer_list(camp):
     """
     return list(camp.officers.order_by('first_name', 'last_name', 'email').exclude(id__in=finished_apps_ids))
 
 
-def officer_data_to_xls(camp):
+def officer_data_to_spreadsheet(camp, spreadsheet):
     # Import here to avoid import cycle when starting from handle_mail script
     from cciw.officers.applications import applications_for_camp
 
                ('Birth date', app_attr_getter('birth_date')),
                ]
 
-    wkbk = xlwt.Workbook(encoding='utf8')
     header_row = [h for h,f in columns]
     def data_rows():
         for inv in invites:
                 row.append(f(user, inv, app))
             yield row
 
-    add_sheet_with_header_row(wkbk, "Officers", header_row, data_rows())
-    return workbook_to_string(wkbk)
+    spreadsheet.add_sheet_with_header_row("Officers", header_row, data_rows())
+    return spreadsheet.to_string()

cciw/officers/views.py

 from cciw.officers.email import make_update_email_hash, send_reference_request_email, make_ref_form_url, make_ref_form_url_hash, send_leaders_reference_email, send_nag_by_officer, send_crb_consent_problem_email
 from cciw.officers.widgets import ExplicitBooleanFieldSelect
 from cciw.officers.models import Application, Reference, ReferenceForm, Invitation, CRBApplication, CRBFormLog
-from cciw.officers.utils import camp_slacker_list, officer_data_to_xls
+from cciw.officers.utils import camp_slacker_list, officer_data_to_spreadsheet
 from cciw.officers.references import reference_form_info
 from cciw.utils.views import close_window_response, user_passes_test_improved, get_spreadsheet_formatter
 from securedownload.views import access_folder_securely
 @camp_admin_required
 def export_officer_data(request, year=None, number=None):
     camp = _get_camp_or_404(year, number)
-    response = HttpResponse(officer_data_to_xls(camp), mimetype="application/vnd.ms-excel")
-    response['Content-Disposition'] = ('attachment; filename=camp-%d-%d-officers.xls'
-                                       % (camp.year, camp.number))
+    formatter = get_spreadsheet_formatter(request)
+    response = HttpResponse(officer_data_to_spreadsheet(camp, formatter),
+                            mimetype=formatter.mimetype)
+    response['Content-Disposition'] = ('attachment; filename=camp-%d-%d-officers.%s'
+                                       % (camp.year, camp.number, formatter.file_ext))
     return response