Skip to content

Commit

Permalink
deleted unused apply_filters function
Browse files Browse the repository at this point in the history
  • Loading branch information
minghansun1 committed Nov 23, 2024
1 parent c52049e commit 8efe703
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions backend/market/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
ItemSerializerRead,
OfferSerializer,
SubletSerializer,
TagSerializer,
)
from pennmobile.analytics import Metric, record_analytics

Expand Down Expand Up @@ -64,40 +63,6 @@ def get_queryset(self):
return Offer.objects.filter(user=user)


def apply_filters(
queryset, params, filter_mappings, user=None, is_sublet=False, tag_field="tags__name"
):
# Build dynamic filters based on filter mappings
filters = {}
for param, field in filter_mappings.items():
if param_value := params.get(param):
filters[field] = param_value


# Apply tag filtering iteratively if "tags" parameter is provided
for tag in params.getlist("tags"):
queryset = queryset.filter(**{tag_field: tag})

# Handle seller/owner filtering based on user ownership
if not is_sublet:
queryset = queryset.exclude(category__name__in=["Sublet"])
if params.get("seller", "false").lower() == "true" and user:
filters["seller"] = user
else:
filters["expires_at__gte"] = timezone.now()
else:
queryset = queryset.filter(item__category__name__in=["Sublet"])
if params.get("seller", "false").lower() == "true" and user:
filters["item__seller"] = user
else:
filters["item__expires_at__gte"] = timezone.now()

# Apply all filters to the queryset
queryset = queryset.filter(**filters)

return queryset


class Items(viewsets.ModelViewSet):
"""
list:
Expand Down

0 comments on commit 8efe703

Please sign in to comment.