Ejemplo n.º 1
0
def __getSearchDatafileForm(request, searchQueryType):
    """Create the search datafile form based on the HTTP GET request.

    :param request: a HTTP Request instance
    :type request: :class:`django.http.HttpRequest`
    :param searchQueryType: The search query type: 'mx' or 'saxs'
    :raises:
       :py:class:`tardis.tardis_portal.errors.UnsupportedSearchQueryTypeError`
       is the provided searchQueryType is not supported.
    :returns: The supported search datafile form

    """

    try:
        SearchDatafileForm = createSearchDatafileForm(searchQueryType)
        form = SearchDatafileForm(request.GET)
        return form
    except UnsupportedSearchQueryTypeError, e:
        raise e
Ejemplo n.º 2
0
def __getSearchDatafileForm(request, searchQueryType):
    """Create the search datafile form based on the HTTP GET request.

    :param request: a HTTP Request instance
    :type request: :class:`django.http.HttpRequest`
    :param basestring searchQueryType: The search query type: 'mx' or 'saxs'
    :raises:
       :py:class:`tardis.tardis_portal.errors.UnsupportedSearchQueryTypeError`
       is the provided searchQueryType is not supported.
    :returns: The supported search datafile form
    :rtype: SearchDatafileForm
    :raises UnsupportedSearchQueryTypeError:
    """

    try:
        SearchDatafileForm = createSearchDatafileForm(searchQueryType)
        form = SearchDatafileForm(request.GET)
        return form
    except UnsupportedSearchQueryTypeError, e:
        raise e
Ejemplo n.º 3
0
def __forwardToSearchDatafileFormPage(request, searchQueryType,
                                      searchForm=None):
    """Forward to the search data file form page."""

    # TODO: remove this later on when we have a more generic search form
    if searchQueryType == 'mx':
        url = 'tardis_portal/search_datafile_form_mx.html'
        searchForm = MXDatafileSearchForm()
        c = {'header': 'Search Datafile',
             'searchForm': searchForm}
        return HttpResponse(render_response_search(request, url, c))

    url = 'tardis_portal/search_datafile_form.html'
    if not searchForm:
        # if searchQueryType == 'saxs':
        SearchDatafileForm = createSearchDatafileForm(searchQueryType)
        searchForm = SearchDatafileForm()  # pylint: disable=R0204
        # else:
        #    # TODO: what do we need to do if the user didn't provide a page to
        #            display?
        #    pass

    from itertools import groupby

    # sort the fields in the form as it will make grouping the related fields
    # together in the next step easier
    sortedSearchForm = sorted(searchForm, lambda x, y: cmp(x.name, y.name))

    # modifiedSearchForm will be used to customise how the range type of fields
    # will be displayed. range type of fields will be displayed side by side.
    modifiedSearchForm = [list(g) for k, g in groupby(
        sortedSearchForm, lambda x: x.name.rsplit('To')[0].rsplit('From')[0])]

    # the searchForm will be used by custom written templates whereas the
    # modifiedSearchForm will be used by the 'generic template' that the
    # dynamic search datafiles form uses.
    c = {'header': 'Search Datafile',
         'searchForm': searchForm,
         'modifiedSearchForm': modifiedSearchForm}
    return HttpResponse(render_response_search(request, url, c))
Ejemplo n.º 4
0
def __forwardToSearchDatafileFormPage(request, searchQueryType,
                                      searchForm=None):
    """Forward to the search data file form page."""

    # TODO: remove this later on when we have a more generic search form
    if searchQueryType == 'mx':
        url = 'tardis_portal/search_datafile_form_mx.html'
        searchForm = MXDatafileSearchForm()
        c = {'header': 'Search Datafile',
             'searchForm': searchForm}
        return HttpResponse(render_response_search(request, url, c))

    url = 'tardis_portal/search_datafile_form.html'
    if not searchForm:
        # if searchQueryType == 'saxs':
        SearchDatafileForm = createSearchDatafileForm(searchQueryType)
        searchForm = SearchDatafileForm()
        # else:
        #    # TODO: what do we need to do if the user didn't provide a page to
        #            display?
        #    pass

    from itertools import groupby

    # sort the fields in the form as it will make grouping the related fields
    # together in the next step easier
    sortedSearchForm = sorted(searchForm, lambda x, y: cmp(x.name, y.name))

    # modifiedSearchForm will be used to customise how the range type of fields
    # will be displayed. range type of fields will be displayed side by side.
    modifiedSearchForm = [list(g) for k, g in groupby(
        sortedSearchForm, lambda x: x.name.rsplit('To')[0].rsplit('From')[0])]

    # the searchForm will be used by custom written templates whereas the
    # modifiedSearchForm will be used by the 'generic template' that the
    # dynamic search datafiles form uses.
    c = {'header': 'Search Datafile',
         'searchForm': searchForm,
         'modifiedSearchForm': modifiedSearchForm}
    return HttpResponse(render_response_search(request, url, c))