def is_exist(document: Document, exp_message: Text = None, raise_error=True, *args, **kwargs): """ check if document exist :param document: document type :param exp_message: exception message :param raise_error: boolean to raise exception :param kwargs: filter parameters :return: boolean """ doc = document.objects(**kwargs) if doc.__len__(): if raise_error: if Utility.check_empty_string(exp_message): raise AppException("Exception message cannot be empty") raise AppException(exp_message) else: return True else: if not raise_error: return False
def is_exist( document: Document, query: Dict, exp_message: Text = None, raise_error=True, ): doc = document.objects(status=True, __raw__=query) if doc.__len__(): if raise_error: if Utility.check_empty_string(exp_message): raise AppException("Exception message cannot be empty") raise AppException(exp_message) else: return True else: if not raise_error: return False
def retrieve_field_values(document: Document, field: str, *args, **kwargs): """ Retrieve particular fields in document if exists, else returns None. This should only be used when the field is a required field in the document. :param document: document type :param field: field to retrieve from documents :param kwargs: filter parameters :return: list of values for a particular field if document exists else None """ documents = document.objects(args, **kwargs) values = None if documents.__len__(): values = [getattr(doc, field) for doc in documents] return values
def is_exist(document: Document, exp_message: Text = None, raise_error=True, *args, **kwargs): doc = document.objects(**kwargs) if doc.__len__(): if raise_error: if Utility.check_empty_string(exp_message): raise AppException("Exception message cannot be empty") raise AppException(exp_message) else: return True else: if not raise_error: return False