Esempio n. 1
0
def _create_filters_query(request):
    """Returns a Q object expression based on query parameters."""
    keyword_param = int_or_none(request.GET.get('keyword'))
    location_param = int_or_none(request.GET.get('location'))
    status_param = int_or_none(request.GET.get('status'))
    organisation_param = int_or_none(request.GET.get('organisation'))
    sector_param = int_or_none(request.GET.get('sector'))
    title_or_subtitle_param = request.GET.get('title_or_subtitle')

    keyword_filter = Q(keywords__id=keyword_param) if keyword_param else None
    location_filter = get_m49_filter(location_param) if location_param else None
    status_filter = Q(iati_status=status_param) if status_param else None
    organisation_filter = Q(partners__id=organisation_param) if organisation_param else None
    sector_filter = (
        Q(sectors__sector_code=sector_param, sectors__vocabulary='2')
        if sector_param else None
    )
    title_or_subtitle_filter = (
        Q(title__icontains=title_or_subtitle_param) | Q(subtitle__icontains=title_or_subtitle_param)
    ) if title_or_subtitle_param else None
    all_filters = [
        keyword_filter,
        location_filter,
        status_filter,
        organisation_filter,
        sector_filter,
    ]
    filters = filter(None, all_filters)
    return reduce(lambda x, y: x & y, filters) if filters else None, title_or_subtitle_filter
Esempio n. 2
0
def _create_filters_query(request):
    """Returns a Q object expression based on query parameters."""
    keyword_param = int_or_none(request.GET.get('keyword'))
    location_param = int_or_none(request.GET.get('location'))
    status_param = int_or_none(request.GET.get('status'))
    organisation_param = int_or_none(request.GET.get('organisation'))
    sector_param = int_or_none(request.GET.get('sector'))
    title_or_subtitle_param = request.GET.get('title_or_subtitle')

    keyword_filter = Q(keywords__id=keyword_param) if keyword_param else None
    location_filter = get_m49_filter(
        location_param) if location_param else None
    status_filter = Q(iati_status=status_param) if status_param else None
    organisation_filter = Q(
        partners__id=organisation_param) if organisation_param else None
    sector_filter = (Q(sectors__sector_code=sector_param,
                       sectors__vocabulary='2') if sector_param else None)
    title_or_subtitle_filter = (
        Q(title__icontains=title_or_subtitle_param)
        | Q(subtitle__icontains=title_or_subtitle_param)
    ) if title_or_subtitle_param else None
    all_filters = [
        keyword_filter,
        location_filter,
        status_filter,
        organisation_filter,
        sector_filter,
    ]
    filters = filter(None, all_filters)
    return reduce(lambda x, y: x & y,
                  filters) if filters else None, title_or_subtitle_filter
Esempio n. 3
0
def _create_filters_query(request):
    """Returns a Q object expression based on query parameters."""
    location_param = int_or_none(request.GET.get('location'))
    organisation_param = int_or_none(request.GET.get('organisation'))
    sector_param = int_or_none(request.GET.get('sector'))
    title_or_subtitle_param = request.GET.get('title_or_subtitle')

    location_filter = (get_m49_filter(location_param,
                                      use_recipient_country=False)
                       if location_param else None)
    organisation_filter = (Organisation.all_updates_filter(organisation_param)
                           if organisation_param else None)
    sector_filter = (Q(project__sectors__sector_code=sector_param,
                       project__sectors__vocabulary='2')
                     if sector_param else None)
    title_filter = Q(title__icontains=title_or_subtitle_param
                     ) if title_or_subtitle_param else None
    all_filters = [
        location_filter,
        organisation_filter,
        sector_filter,
    ]
    filters = [_f for _f in all_filters if _f]
    return reduce(lambda x, y: x & y,
                  filters) if filters else None, title_filter
Esempio n. 4
0
def _create_filters_query(request):
    """Returns a Q object expression based on query parameters."""
    location_param = int_or_none(request.GET.get('location'))
    organisation_param = int_or_none(request.GET.get('organisation'))
    sector_param = int_or_none(request.GET.get('sector'))
    title_or_subtitle_param = request.GET.get('title_or_subtitle')

    location_filter = (
        get_m49_filter(location_param, use_recipient_country=False) if location_param else None
    )
    organisation_filter = (
        Organisation.all_updates_filter(organisation_param)
        if organisation_param else None
    )
    sector_filter = (
        Q(project__sectors__sector_code=sector_param, project__sectors__vocabulary='2')
        if sector_param else None
    )
    title_filter = Q(title__icontains=title_or_subtitle_param) if title_or_subtitle_param else None
    all_filters = [
        location_filter,
        organisation_filter,
        sector_filter,
    ]
    filters = filter(None, all_filters)
    return reduce(lambda x, y: x & y, filters) if filters else None, title_filter
Esempio n. 5
0
def _create_filters_query(request):
    """Returns a Q object expression based on query parameters."""
    location_param = int_or_none(request.GET.get('location'))
    title_or_subtitle_param = request.GET.get('title_or_subtitle')

    location_filter = (
        get_m49_filter(location_param, use_recipient_country=False) if location_param else None
    )
    title_filter = (
        Q(name__icontains=title_or_subtitle_param)
        | Q(long_name__icontains=title_or_subtitle_param)
    ) if title_or_subtitle_param else None
    all_filters = [
        location_filter,
    ]
    filters = [_f for _f in all_filters if _f]
    return reduce(lambda x, y: x & y, filters) if filters else None, title_filter
Esempio n. 6
0
def _create_filters_query(request):
    """Returns a Q object expression based on query parameters."""
    location_param = int_or_none(request.GET.get('location'))
    title_or_subtitle_param = request.GET.get('title_or_subtitle')

    location_filter = (
        get_m49_filter(location_param, use_recipient_country=False) if location_param else None
    )
    title_filter = (
        Q(name__icontains=title_or_subtitle_param) |
        Q(long_name__icontains=title_or_subtitle_param)
    ) if title_or_subtitle_param else None
    all_filters = [
        location_filter,
    ]
    filters = filter(None, all_filters)
    return reduce(lambda x, y: x & y, filters) if filters else None, title_filter