예제 #1
0
def get_search_query(user, params):
    other_search_params = params.get('filter_params', {})
    q = other_search_params.get('q', '')
    order_by = params.get('order_by', 'pk')
    sort_reverse = params.get('sort_reverse', False)

    if order_by:
        if sort_reverse:
            order_by = "-%s" % order_by
        building_snapshots = BuildingSnapshot.objects.order_by(
            order_by
        ).filter(
            super_organization__in=user.orgs.all(),
            canonicalbuilding__active=True,
        )
    else:
        building_snapshots = BuildingSnapshot.objects.filter(
            super_organization__in=user.orgs.all(),
            canonicalbuilding__active=True,
        )

    buildings_queryset = search.search_buildings(
        q, queryset=building_snapshots)
    buildings_queryset = search.filter_other_params(
        buildings_queryset, other_search_params)

    return buildings_queryset
def get_search_query(user, params):
    other_search_params = params.get('filter_params', {})
    q = other_search_params.get('q', '')
    order_by = params.get('order_by', 'pk')
    sort_reverse = params.get('sort_reverse', False)
    project_slug = other_search_params.get('project__slug', None)

    mappable_types = get_mappable_types()

    if project_slug:
        mappable_types['project__slug'] = 'string'

    if order_by:
        if sort_reverse:
            order_by = "-%s" % order_by
        building_snapshots = BuildingSnapshot.objects.order_by(
            order_by).filter(
                super_organization__in=user.orgs.all(),
                canonicalbuilding__active=True,
            )
    else:
        building_snapshots = BuildingSnapshot.objects.filter(
            super_organization__in=user.orgs.all(),
            canonicalbuilding__active=True,
        )

    buildings_queryset = search.search_buildings(q,
                                                 queryset=building_snapshots)

    buildings_queryset = search.filter_other_params(buildings_queryset,
                                                    other_search_params,
                                                    mappable_types)

    return buildings_queryset