def qr_code(self, request): qrcode = QRCode.get_or_create( poim_client=self.poim_client, session_id=session_id, ) qrcode.save() fp = mk_qrcode(qrcode.url) return ResponseStream(fp)
def csv_download_response(rows, filename, fieldnames=None): response = Response( content_type='text/csv', headers={ 'Content-disposition': f'attachment; filename="{filename}"', }, ) csv_writer = csv.DictWriter(ResponseStream(response), fieldnames=fieldnames) csv_writer.writeheader() csv_writer.writerows(rows) return response
def response_with_csv_download(rows, filename_prefix, fieldnames=None): now = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') response = Response( content_type='text/csv', headers={ 'Content-disposition': f'attachment; filename="{filename_prefix}_{now}.csv"', }, ) csv_writer = csv.DictWriter(ResponseStream(response), fieldnames=fieldnames) csv_writer.writeheader() csv_writer.writerows(rows) return response
def out_stream(self): """The response iterable as write-only stream.""" return ResponseStream(self)