events imports are checked
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from api_validations.validations_request import ListOptions
|
||||
from databases.sql_models.response_model import AlchemyResponse
|
||||
from databases.sql_models.postgres_database import Base
|
||||
|
||||
@@ -19,6 +20,7 @@ class FilterAttributes:
|
||||
|
||||
pre_query = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
|
||||
filter_attr = None # The filter attributes to use in the model.
|
||||
FilterModel: ListOptions = ListOptions
|
||||
|
||||
def flush(self):
|
||||
"""Flush the current session."""
|
||||
@@ -101,14 +103,16 @@ class FilterAttributes:
|
||||
return arg[0]
|
||||
|
||||
@classmethod
|
||||
def filter_by_all(cls, **kwargs):
|
||||
def filter_by_all(cls, **kwargs):
|
||||
"""
|
||||
Filters all the records regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
filter_list = cls.get_filter_attributes()
|
||||
query = cls._query().filter_by(**kwargs)
|
||||
data = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data, first=False)
|
||||
if cls.filter_attr:
|
||||
filter_list = cls.get_filter_attributes()
|
||||
data_query = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data_query, first=False)
|
||||
return AlchemyResponse(query=query, first=False)
|
||||
|
||||
@classmethod
|
||||
def filter_by_one(cls, **kwargs):
|
||||
@@ -123,17 +127,18 @@ class FilterAttributes:
|
||||
"""
|
||||
Filters all the records regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
filter_list = cls.get_filter_attributes()
|
||||
query = cls._query()
|
||||
data = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data, first=False)
|
||||
query = cls._query().filter(*args)
|
||||
if cls.filter_attr:
|
||||
filter_list = cls.get_filter_attributes()
|
||||
data_query = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data_query, first=False)
|
||||
return AlchemyResponse(query=query, first=False)
|
||||
|
||||
@classmethod
|
||||
def filter_one(cls, *args, expired: bool = False):
|
||||
"""
|
||||
Filters one record regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
|
||||
arg = cls.get_not_expired_query_arg(args, expired=expired)
|
||||
query = cls._query().filter(*arg)
|
||||
return AlchemyResponse(query=query, first=True)
|
||||
|
||||
Reference in New Issue
Block a user