-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: System operate log #3198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: System operate log #3198
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from django.db.models import QuerySet | ||
|
|
||
| from knowledge.models import Document | ||
|
|
||
|
|
||
|
|
||
| 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_knowledge_document_operation_object(knowledge_dict: dict, document_dict: dict): | ||
| return { | ||
| 'name': f'{knowledge_dict.get("name", "")}/{document_dict.get("name", "")}', | ||
| 'dataset_name': knowledge_dict.get("name", ""), | ||
| 'dataset_desc': knowledge_dict.get("desc", ""), | ||
| 'dataset_type': knowledge_dict.get("type", ""), | ||
| 'document_name': document_dict.get("name", ""), | ||
| 'document_type': document_dict.get("type", ""), | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code is mostly clear and well-structured, but there are a few areas where you can make improvements for better performance and clarity:
Function Naming: The function names can be more descriptive to improve readability. For example:
get_document_operation_objectshould be renamed to something likeretrieve_document_details.get_document_operation_object_batchcould becomebatch_retrieve_document_details.get_knowledge_document_operation_objectmight be clearer ascompose_document_and_knowledge.Use of F-Strings: While f-strings are generally preferred, they can be overused. Replace all instances with
.format()or directly interpolate strings in Python version >= 3.6.Return Statement: Ensure that each function returns a dictionary unless specified otherwise. This makes the code easier to understand and maintain.
Null Check: Instead of checking
if document_model is not None, usebool(document_model)which is more concise.Efficient Query Execution: Directly pass variables to method calls rather than using string concatenation within methods.
Here's the updated code incorporating these suggestions:
These changes focus on improving code clarity, readability, and efficiency without altering its functionality. Make sure to test the functions after making these changes to ensure they behave as expected.