def _get_filtered_properties_for_property_view(request):
    """
    Returns a query set with filtered properties based on saved name filter
    and ordering within the current session.
    """
    properties = Property.objects.filter(local=False)
    property_ordering = request.session.get("property-ordering", "name")
    property_ordering_order = request.session.get("property-ordering-order", "")

    # Filter
    property_filters = request.session.get("property_filters", {})
    name = property_filters.get("property_name", "")
    if name != "":
        properties = properties.filter(Q(name__icontains=name) | Q(title__icontains=name))

    properties = properties.order_by("%s%s" % (property_ordering_order, property_ordering))
    return properties
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/property/views.py/_get_filtered_properties_for_property_view/original