def get_fields_with_instance(cls, doc_cls): if cls.__cached_fields_with_instance is None: cls.__cached_fields_with_instance = {} if doc_cls not in cls.__cached_fields_with_instance: cls.__cached_fields_with_instance[doc_cls] = get_fields( doc_cls, return_instance=True) return cls.__cached_fields_with_instance[doc_cls]
def get_field_names_for_type(cls, of_type=BaseField): """ Return field names per type including subfields The fields of derived types are also returned """ assert issubclass(of_type, BaseField) if cls.__cached_field_names_per_type is None: fields = defaultdict(list) for name, field in get_fields(cls, return_instance=True, subfields=True): fields[type(field)].append(name) for type_ in fields: fields[type_].extend( chain.from_iterable(fields[other_type] for other_type in fields if other_type != type_ and issubclass(other_type, type_))) cls.__cached_field_names_per_type = fields if of_type not in cls.__cached_field_names_per_type: names = list( chain.from_iterable(field_names for type_, field_names in cls.__cached_field_names_per_type.items() if issubclass(type_, of_type))) cls.__cached_field_names_per_type[of_type] = names return cls.__cached_field_names_per_type[of_type]
def collect_embedded_docs(doc_cls, embedded_doc_field_getter): for field, embedded_doc_field in get_fields(cls_, of_type=doc_cls, return_instance=True): embedded_doc_cls = embedded_doc_field_getter( embedded_doc_field).document_type fields.update({ '.'.join((field, subfield)): doc for subfield, doc in PropsMixin._get_fields_with_attr( embedded_doc_cls, attr).items() })
def get_fields(cls): if cls.__cached_fields is None: cls.__cached_fields = get_fields(cls) return cls.__cached_fields
from database.model.task.output import Output from database.model.task.task import ( Task, TaskStatus, Script, DEFAULT_LAST_ITERATION, Execution, ) from database.utils import get_fields, parse_from_call from service_repo import APICall, endpoint from services.utils import conform_tag_fields, conform_output_tags from timing_context import TimingContext from utilities import safe_get task_fields = set(Task.get_fields()) task_script_fields = set(get_fields(Script)) task_bll = TaskBLL() event_bll = EventBLL() queue_bll = QueueBLL() org_bll = OrgBLL() NonResponsiveTasksWatchdog.start() def set_task_status_from_call(request: UpdateRequest, company_id, new_status=None, **set_fields) -> dict: fields_resolver = SetFieldsResolver(set_fields) task = TaskBLL.get_task_with_access(