common.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from django.db.models import QuerySet
  2. from knowledge.models import Document
  3. def get_document_operation_object(document_id: str):
  4. document_model = QuerySet(model=Document).filter(id=document_id).first()
  5. if document_model is not None:
  6. return {
  7. "name": document_model.name,
  8. "type": document_model.type,
  9. }
  10. return {}
  11. def get_document_operation_object_batch(document_id_list: str):
  12. document_model_list = QuerySet(model=Document).filter(id__in=document_id_list)
  13. if document_model_list is not None:
  14. return {
  15. "name": f'[{",".join([document_model.name for document_model in document_model_list])}]',
  16. 'document_list': [{'name': document_model.name, 'type': document_model.type} for document_model in
  17. document_model_list]
  18. }
  19. return {}
  20. def get_knowledge_document_operation_object(knowledge_dict: dict, document_dict: dict):
  21. return {
  22. 'name': f'{knowledge_dict.get("name", "")}/{document_dict.get("name", "")}',
  23. 'dataset_name': knowledge_dict.get("name", ""),
  24. 'dataset_desc': knowledge_dict.get("desc", ""),
  25. 'dataset_type': knowledge_dict.get("type", ""),
  26. 'document_name': document_dict.get("name", ""),
  27. 'document_type': document_dict.get("type", ""),
  28. }