def post(self, request, *args, **kwargs): try: workbook = get_workbook(request.FILES['bulk_upload_file']) except WorkbookJSONError as e: messages.error(request, str(e)) return self.get(request, *args, **kwargs) msgs = upload_conditional_alert_workbook(self.domain, workbook) for msg in msgs: msg[0](request, msg[1]) return self.get(request, *args, **kwargs)
def _upload(self, data, headers=None): if headers is None: headers = ( ("translated", ("id", "name", "message_en", "message_es")), ("not translated", ("id", "name", "message")), ) file = BytesIO() export_raw(headers, data, file, format=Format.XLS_2007) with tempfile.TemporaryFile(suffix='.xlsx') as f: f.write(file.getvalue()) f.seek(0) workbook = get_workbook(f) msgs = upload_conditional_alert_workbook(self.domain, workbook) return [m[1] for m in msgs] # msgs is tuples of (type, message); ignore the type