|
@@ -137,9 +137,16 @@ class Query(graphene.ObjectType):
|
|
|
query_set = Order.objects.filter(owner = user)
|
|
|
|
|
|
|
|
|
- if len(filter_params):
|
|
|
- query_set = query_set.filter(reduce(operator.or_,(Q(**d) for d in [dict([i]) for i in filter_params.items()])))
|
|
|
|
|
|
+ if len(filter_params):
|
|
|
+ or_filter_params = filter_params.pop("or",{})
|
|
|
+ and_filter_params= filter_params.pop("and",{})
|
|
|
+ and_filter_params |= filter_params
|
|
|
+ if len(or_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.or_,(Q(**d) for d in [dict([i]) for i in or_filter_params.items()])))
|
|
|
+ if len(and_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.and_,(Q(**d) for d in [dict([i]) for i in and_filter_params.items()])))
|
|
|
+
|
|
|
query_set = query_set.order_by(order_by)[skip:skip+limit]
|
|
|
return query_set
|
|
|
|
|
@@ -162,8 +169,14 @@ class Query(graphene.ObjectType):
|
|
|
query_set = Order.objects.filter(owner = user)
|
|
|
|
|
|
if len(filter_params):
|
|
|
- query_set = query_set.filter(reduce(operator.and_,(Q(**d) for d in [dict([i]) for i in filter_params.items()])))
|
|
|
-
|
|
|
+ or_filter_params = filter_params.pop("or",{})
|
|
|
+ and_filter_params= filter_params.pop("and",{})
|
|
|
+ and_filter_params |= filter_params
|
|
|
+ if len(or_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.or_,(Q(**d) for d in [dict([i]) for i in or_filter_params.items()])))
|
|
|
+ if len(and_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.and_,(Q(**d) for d in [dict([i]) for i in and_filter_params.items()])))
|
|
|
+
|
|
|
return query_set.first()
|
|
|
|
|
|
|
|
@@ -181,9 +194,16 @@ class Query(graphene.ObjectType):
|
|
|
|
|
|
query_set = OrderGood.objects.all()
|
|
|
|
|
|
- if len(filter_params):
|
|
|
- query_set = query_set.filter(reduce(operator.and_,(Q(**d) for d in [dict([i]) for i in filter_params.items()])))
|
|
|
|
|
|
+ if len(filter_params):
|
|
|
+ or_filter_params = filter_params.pop("or",{})
|
|
|
+ and_filter_params= filter_params.pop("and",{})
|
|
|
+ and_filter_params |= filter_params
|
|
|
+ if len(or_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.or_,(Q(**d) for d in [dict([i]) for i in or_filter_params.items()])))
|
|
|
+ if len(and_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.and_,(Q(**d) for d in [dict([i]) for i in and_filter_params.items()])))
|
|
|
+
|
|
|
|
|
|
return query_set
|
|
|
|
|
@@ -202,8 +222,14 @@ class Query(graphene.ObjectType):
|
|
|
query_set = OrderGood.objects.all()
|
|
|
|
|
|
if len(filter_params):
|
|
|
- query_set = query_set.filter(reduce(operator.and_,(Q(**d) for d in [dict([i]) for i in filter_params.items()])))
|
|
|
-
|
|
|
+ or_filter_params = filter_params.pop("or",{})
|
|
|
+ and_filter_params= filter_params.pop("and",{})
|
|
|
+ and_filter_params |= filter_params
|
|
|
+ if len(or_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.or_,(Q(**d) for d in [dict([i]) for i in or_filter_params.items()])))
|
|
|
+ if len(and_filter_params):
|
|
|
+ query_set = query_set.filter(reduce(operator.and_,(Q(**d) for d in [dict([i]) for i in and_filter_params.items()])))
|
|
|
+
|
|
|
return query_set.first()
|
|
|
|
|
|
|
|
@@ -240,8 +266,10 @@ class OrderUpsert(graphene.Mutation):
|
|
|
if "owner" in order:
|
|
|
try:
|
|
|
owner = User.objects.get(pk =order.pop("owner")["_id"])
|
|
|
+
|
|
|
except:
|
|
|
raise Exception("Не вірні дані")
|
|
|
+
|
|
|
|
|
|
try:
|
|
|
if "_id" in order:
|
|
@@ -258,7 +286,13 @@ class OrderUpsert(graphene.Mutation):
|
|
|
|
|
|
else:
|
|
|
new_order = Order(**order)
|
|
|
- new_order.owner = user
|
|
|
+ if owner:
|
|
|
+ if not user.is_superuser:
|
|
|
+ raise Exception("Authentication credentials were not provided")
|
|
|
+
|
|
|
+ new_order.owner = owner
|
|
|
+ else:
|
|
|
+ new_order.owner = user
|
|
|
|
|
|
except Exception as e:
|
|
|
raise Exception("Не вірні дані")
|