Example #1
0
    def form_valid(self, form):
        category = form.cleaned_data['category']
        exported_file = export_review_members(category)
        filename = 'review_members_{}_{}.xlsx'.format(
            category.organisation.slug,
            category.slug
        )

        response = HttpResponse(
            exported_file,
            content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
        response['Content-Disposition'] = 'attachment; filename={}'.format(filename)
        return response
Example #2
0
    def test_successful_export(self):
        exported_file = export_review_members(self.category)
        buf = BytesIO(exported_file)
        wb = openpyxl.load_workbook(buf)
        ws = wb.active

        self.assertEqual(ws.max_column, 7)
        self.assertEqual(ws.max_row, 5)

        self.assertEqual(ws.cell(column=1, row=2).value, self.docs[0].document_number)
        self.assertEqual(ws.cell(column=2, row=2).value, None)
        self.assertEqual(ws.cell(column=3, row=2).value, 'L')
        self.assertEqual(ws.cell(column=4, row=2).value, None)

        self.assertEqual(ws.cell(column=1, row=3).value, self.docs[1].document_number)
        self.assertEqual(ws.cell(column=2, row=3).value, None)
        self.assertEqual(ws.cell(column=3, row=3).value, 'A')
        self.assertEqual(ws.cell(column=4, row=3).value, 'L')