From 0c2f5189abf622bb3677958158fb0ca8ed286598 Mon Sep 17 00:00:00 2001 From: Vikrant Date: Sun, 13 Sep 2026 15:04:05 +0530 Subject: [PATCH] Print whole credit counts without a decimal point The Grade Validation PDFs showed Units as 1.0, 3.0, 2.0 and the credit totals as 19.0, because the semester builder casts every credit through float and the PDF printed the value as it stood. JSON drops a trailing zero, so the screen was already right and only the generated file was affected. Formatted the same way the client does it: bare when the count is whole, one decimal when it is not, so a half credit course is still printed in full. SPI and CPI keep their one decimal. --- .../applications/examination/api/views.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/FusionIIIT/applications/examination/api/views.py b/FusionIIIT/applications/examination/api/views.py index f001de03c..3b2a2c25b 100644 --- a/FusionIIIT/applications/examination/api/views.py +++ b/FusionIIIT/applications/examination/api/views.py @@ -4695,6 +4695,15 @@ def post(self, request): ) +def _credits_text(value): + """A whole credit count prints bare; a fractional one keeps one decimal.""" + try: + number = float(value) + except (TypeError, ValueError): + return str(value) + return str(int(number)) if number == int(number) else '{:.1f}'.format(number) + + def _build_grade_validation_semesters(student): """One student's full semester-by-semester grade history for Grade Validation -- shared by GradeValidationView's get_all_grades action and export_all_zip action @@ -5136,7 +5145,7 @@ def _build_pdf_bytes(stu_info, semesters): tbl_data.append([ Paragraph(str(c["code"]), small), Paragraph(str(c["name"]), small), - Paragraph(str(c["credits"]), small), + Paragraph(_credits_text(c["credits"]), small), Paragraph(str(c["grade"]), small), Paragraph(f'{rem}', small), ]) @@ -5161,7 +5170,7 @@ def _build_pdf_bytes(stu_info, semesters): # Summary row — 4 equal columns, fills full width if is_reg: sum_row = [ - Paragraph(f"Total Registered Credits: {sem['semester_credits']}", small), + Paragraph(f"Total Registered Credits: {_credits_text(sem['semester_credits'])}", small), Paragraph("", small), Paragraph("", small), Paragraph("", small), @@ -5171,8 +5180,8 @@ def _build_pdf_bytes(stu_info, semesters): spi_str = f"{sem['spi']:.1f}" if sem.get('spi') is not None else "—" cpi_str = f"{sem['cpi']:.1f}" if sem.get('cpi') is not None else "—" sum_row = [ - Paragraph(f"Total Credits Earned: {sem['total_credits']}", small), - Paragraph(f"Semester Credits Earned: {sem['semester_credits']}", small), + Paragraph(f"Total Credits Earned: {_credits_text(sem['total_credits'])}", small), + Paragraph(f"Semester Credits Earned: {_credits_text(sem['semester_credits'])}", small), Paragraph(f"SPI: {spi_str}", small), Paragraph(f"CPI: {cpi_str}", small), ]