Commit 55e3924c authored by Einar Uvsløkk's avatar Einar Uvsløkk
Browse files

Reduce complexity and simplify OfferList.get_queryset

parent d920b8d3
......@@ -106,28 +106,20 @@ class OfferList(
def get_queryset(self):
result = Offer.objects.none()
if self.request.user:
qs = Offer.objects.filter(
Q(owner=self.request.user) | Q(recipient=self.request.user)
qp = self.request.query_params
u = self.request.user
s = qp.get("status", None)
if s is not None and self.request is not None:
qs = qs.filter(status=s)
if qp.get("status", None) is None:
qs = Offer.objects.filter(Q(owner=u)).distinct()
c = qp.get("category", None)
if c is not None and qp is not None:
if c == "sent":
qs = qs.filter(owner=u)
elif c == "received":
qs = qs.filter(recipient=u)
return qs
return result
if user := self.request.user:
result = Offer.objects.filter(Q(owner=user) | Q(recipient=user)).distinct()
params = self.request.query_params
if status := params.get("status"):
result = result.filter(status=status)
if category := params.get("category"):
if category == "sent":
result = result.filter(owner=user)
elif category == "received":
result = result.filter(recipient=user)
return result
class OfferDetail(
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment