MaxKB/apps/dataset/views/common.py
shaohuzhang1 f9d536f5a2
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
Typos Check / Spell Check with Typos (push) Waiting to run
feat: Audit log add operation object (#2681)
2025-03-25 19:07:02 +08:00

57 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding=utf-8
"""
@project: MaxKB
@Author
@file common.py.py
@date2025/3/25 15:43
@desc:
"""
from django.db.models import QuerySet
from dataset.models import DataSet, Document
def get_dataset_operation_object(dataset_id: str):
dataset_model = QuerySet(model=DataSet).filter(id=dataset_id).first()
if dataset_model is not None:
return {
"name": dataset_model.name,
"desc": dataset_model.desc,
"type": dataset_model.type,
"create_time": dataset_model.create_time,
"update_time": dataset_model.update_time
}
return {}
def get_document_operation_object(document_id: str):
document_model = QuerySet(model=Document).filter(id=document_id).first()
if document_model is not None:
return {
"name": document_model.name,
"type": document_model.type,
}
return {}
def get_document_operation_object_batch(document_id_list: str):
document_model_list = QuerySet(model=Document).filter(id__in=document_id_list)
if document_model_list is not None:
return {
"name": f'[{",".join([document_model.name for document_model in document_model_list])}]',
'document_list': [{'name': document_model.name, 'type': document_model.type} for document_model in
document_model_list]
}
return {}
def get_dataset_document_operation_object(dataset_dict: dict, document_dict: dict):
return {
'name': f'{dataset_dict.get("name", "")}/{document_dict.get("name", "")}',
'dataset_name': dataset_dict.get("name", ""),
'dataset_desc': dataset_dict.get("desc", ""),
'dataset_type': dataset_dict.get("type", ""),
'document_name': document_dict.get("name", ""),
'document_type': document_dict.get("type", ""),
}