Upravy v dotazovani na verejna data
This commit is contained in:
@@ -12,6 +12,7 @@ class QueryBuilder:
|
||||
extra_select: Optional[list] = None,
|
||||
created_by_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
include_deleted: bool = False
|
||||
):
|
||||
if not extra_select:
|
||||
@@ -22,7 +23,9 @@ class QueryBuilder:
|
||||
if not include_deleted and hasattr(self.model, "deleted"):
|
||||
query = query.filter(self.model.deleted.is_(False))
|
||||
|
||||
if hasattr(self.model, "created_by_id") and created_by_id:
|
||||
if only_public and hasattr(self.model, "is_public"):
|
||||
query = query.filter(self.model.is_public.is_(True))
|
||||
elif hasattr(self.model, "created_by_id") and created_by_id:
|
||||
query = query.filter(self.model.created_by_id == created_by_id)
|
||||
|
||||
if order_by:
|
||||
|
||||
@@ -36,16 +36,13 @@ class BaseQueryResolver(BaseResolver):
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
query = self.query_builder.get_simple_query(created_by_id=user_id, order_by=order_by)
|
||||
query = self.query_builder.get_simple_query(created_by_id=user_id, order_by=order_by, only_public=only_public)
|
||||
|
||||
if object_id:
|
||||
if not hasattr(self.model, "id"):
|
||||
raise AssertionError(f"Model {self.model} has no ID column! Cannot query by ID!")
|
||||
query = query.filter(self.model.id == object_id)
|
||||
|
||||
if only_public and hasattr(self.model, "is_public"):
|
||||
query = query.filter(self.model.is_public.is_(True))
|
||||
|
||||
if kwargs:
|
||||
query = query.filter_by(**kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user