Beispiel #1
0
def genotype_report(request):
    """
    For downloading data files on Genotype documents.

    Uses the request's GET data to construct a query of the Experiment collection.
    Then, for each Experiment, queries the Genotype collection for documents whose
    study field matches the Experiment. Constructs a file representation of the query
    set(s) (csv format one experiment queried, json format for multiple experiments)
    and returns an HttpResponse with the file as an attachment

    Query parsed from GET data following these rules:

    - search_name=[string] : Queries experiments by name
    - search_pi=[string] : Queries experiments by primary investigator
    - from_date_day=[int]&from_date_month=[int]&from_date_year=[int] : Queries experiments by createddate > from_date
    - to_date_day=[int]&to_date_month=[int]&to_date_year=[int] : Queries experiments by createddate < to_date

    :param request: Use to query Genotype collection with
    :return: HttpResponse with file representation of Genotype query set(s)
    """
    db_alias = TEST_DB_ALIAS if testing else 'default'

    index_helper = QueryRequestHandler(request, testing=testing)
    try:
        experiments = index_helper.query_for_api()
    except ExperiSearchError as e:
        return HttpResponse(str(e))
    if len(experiments) == 0:
        return HttpResponse('No Data')
    if len(experiments) == 1:
        return genotype_csv_report(db_alias, experiments[0])
    else:
        return genotype_json_report(db_alias, experiments)