Example #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)
Example #2
0
def index(request):
    """
    Renders the search page according to the index.html template, with a
    form.SearchForm as the search form.

    If the search form has any GET data, builds the appropriate context dict
    for the render from the request using an QueryRequestHandler

    :param request:
    :return:
    """
    template = 'experimentsearch/index.html'
    if request.method == 'GET':
        index_helper = QueryRequestHandler(request, testing=testing)
        context = index_helper.handle_request()
        #  if request was from a redirect from a download preparation page
        download = csv_response is not None
        context.update({'download': download})
        return render(request, template, context)
    else:
        return render(
            request, template,
            {'search_form': my_forms.NameSearchForm(),
             'search_select': my_forms.SearchTypeSelect()}
        )
Example #3
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)