Enhance student result PDF generation by applying word wrapping to long names in the student information table#1854
Conversation
…ng names in the student information table
There was a problem hiding this comment.
Pull request overview
This PR enhances the student result PDF generation by implementing comprehensive word wrapping for all text fields in the student information table, replacing the previous approach that only conditionally wrapped long names (over 25 characters).
Key Changes
- Introduced a unified
cell_styleParagraphStyle with word wrapping configuration for all table cells - Converted all student data table cells from plain strings to Paragraph objects for consistent text wrapping behavior
- Removed conditional name wrapping logic in favor of uniform wrapping across all fields
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [Paragraph('Name of Student:', cell_style), Paragraph(student_info.get('name', 'N/A'), cell_style), Paragraph('Roll No.:', cell_style), Paragraph(student_info.get('rollNumber', student_info.get('roll_number', 'N/A')), cell_style)], | ||
| [Paragraph('Programme:', cell_style), Paragraph(student_info.get('programme', 'N/A'), cell_style), Paragraph('Branch:', cell_style), Paragraph(student_info.get('branch', student_info.get('department', 'N/A')), cell_style)], | ||
| [Paragraph('Semester:', cell_style), Paragraph(formatted_semester, cell_style), Paragraph('Academic Year:', cell_style), Paragraph(student_info.get('academicYear', student_info.get('academic_year', 'N/A')), cell_style)] |
There was a problem hiding this comment.
These lines are excessively long (over 200 characters each) and significantly impact code readability. Consider breaking them into multiple lines by extracting the Paragraph creation into variables or using temporary variables for the dictionary .get() calls.
Example refactoring for line 3549:
student_name = Paragraph(student_info.get('name', 'N/A'), cell_style)
roll_number = Paragraph(student_info.get('rollNumber', student_info.get('roll_number', 'N/A')), cell_style)
student_data = [
[Paragraph('Name of Student:', cell_style), student_name, Paragraph('Roll No.:', cell_style), roll_number],
# ... remaining rows
]| parent=styles['Normal'], | ||
| fontSize=10, | ||
| fontName='Times-Roman', | ||
| wordWrap='CJK' |
There was a problem hiding this comment.
The wordWrap parameter is not a standard parameter for ReportLab's ParagraphStyle class. ReportLab's Paragraph class automatically handles word wrapping based on the available width without needing a wordWrap parameter in the style definition. This parameter will likely be ignored, but could cause confusion or issues if the library behavior changes.
Consider removing this line as word wrapping is automatically handled by the Paragraph class when it's constrained by the table column width.
| wordWrap='CJK' |
No description provided.