def stream_experiment_csv(request, experi_id): """ Queries the genotype collection with the experiment that matches experi_id as a filter on 'study'. Creates a csv representation of the query set. Writes a http response which downloads the csv file for the client. This response is stored by this module to be downloaded by the download_experiment() view, which gets called by the index.html template once there is a redirect to the index() view, which this view returns :param request: :param experi_id: name of experiment to query for associations :return: Redirect to index """ global csv_response redirect_address = get_redirect_address(request) genotype, experi = query_genotype_by_experiment(experi_id) if len(genotype) == 0: # No data found so go to the no_download page return render( request, "experimentsearch/no_download.html", {"from_url": redirect_address} ) rows = query_to_csv_rows_list(genotype, testing=testing) csv_response = write_stream_response(rows, experi.name) return redirect(redirect_address)
def page_report(request, report, fmt='csv', conf=None): """ For downloading a file listing documents of a given type with their field values :param report: Name of document type to list :param fmt: Format of file to download with list of documents. Defaults to csv :return: HttpResponse or StreamingHttpResponse with document list file as attachment """ objs = get_queryset(request, report, request.GET)[:100] if objs.count() == 0: return HttpResponse('No Data') rows = query_to_csv_rows_list(objs, testing=testing) return write_stream_response(rows, report)
def page_report(request, report, fmt='csv', conf=None): """ For downloading a file listing documents of a given type with their field values :param report: Name of document type to list :param fmt: Format of file to download with list of documents. Defaults to csv :return: HttpResponse or StreamingHttpResponse with document list file as attachment """ objs = get_queryset(request, report, request.GET)[:100] if objs.count()==0: return HttpResponse('No Data') rows = query_to_csv_rows_list(objs, testing=testing) return write_stream_response(rows, report)
def genotype_csv_report(db_alias, experiment): """ Queries the Genotype collection for documents referencing the given Experiment, then returns a StreamingHttpResponse with a csv representation of the resulting queryset as an attachment :param db_alias: Alias of database to query :param experiment: Experiment use to query genotype by study :return: StreamingHttpResponse with csv representation of acquired queryset as an attachment """ with switch_db(Genotype, db_alias) as Gen: obs = Gen.objects.filter(study=experiment) if len(obs) == 0: return HttpResponse('No Data') rows = query_to_csv_rows_list(obs, testing=testing) return write_stream_response(rows, "Genotype")