Skip to content

fix: Processing for document export sheet with more than 32 characters #2740

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 1 commit into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/dataset/serializers/document_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ def merge_problem(paragraph_list: List[Dict], problem_mapping_list: List[Dict],

@staticmethod
def reset_document_name(document_name):
if document_name is not None:
document_name = document_name.strip()[0:29]
if document_name is None or not Utils.valid_sheet_name(document_name):
return "Sheet"
return document_name.strip()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function reset_document_name has a few improvements that can be made to enhance its readability and potentially reduce redundancy:

  1. Stripping Whitespace: The line document_name.strip() is redundant inside the condition if document_name is not None, as it would have been stripped anyway before entering the conditional.

  2. Truncating Document Name: While trimming the string to 29 characters might be useful for formatting in some contexts, it should be done based on user preferences rather than automatically changing lengths throughout the application's execution.

Here's an optimized version of the code:

class MergeProblemHelper:
    @staticmethod
    def reset_document_name(document_name):
        """Resets the document name with specific rules."""
        # Strip leading and trailing whitespace
        document_name = document_name.strip()
        
        # Check if document name is valid
        if document_name is None or not Utils.valid_sheet_name(document_name):
            return "Sheet"
        
        # Truncate document name (optional), e.g., for filename purposes
        document_name = document_name[:29].strip()
        
        return document_name
    
    # ... other static methods ...

This refactoring makes each step clear and removes unnecessary logic, maintaining the original functionality while being more efficient and easier to understand.

Expand Down
Loading