Skip to content

feat(examination): dynamic heading, center alignment, auto subject numbering in approval sheet - #2009

Closed
dreamweaver19 wants to merge 1 commit into
FusionIIIT:examination-v1from
dreamweaver19:feat/exam-approval-sheet-improvements
Closed

dreamweaver19 wants to merge 1 commit into
FusionIIIT:examination-v1from
dreamweaver19:feat/exam-approval-sheet-improvements

Conversation

@dreamweaver19

Copy link
Copy Markdown

Summary

Three improvements to the Examination approval-sheet Excel generation (GenerateResultAPI in examination/api/views.py). No database migrations, no model changes, no serializer changes, no frontend changes required.


Changes

REQ-1 – Dynamic Approval-Sheet Heading

  • Heading is now fully dynamic — example output:
    Approval sheet for Even Semester AY2025-26 (UG2023 Batch (CSE) - SEM-6th)
  • Academic year is read from Student_grades.academic_year (ground truth). A fallback formula computes it from batch admission year + semester number when no grade records exist yet (semester pairs 1-2, 3-4, 5-6, 7-8 share the same AY).
  • Added _ordinal_suffix() static helper: 1→1st, 2→2nd, 3→3rd, 6→6th, 11→11th, etc.
  • Added _derive_academic_year() static helper with primary DB source + fallback.
  • Row 1 of the Excel: institute name (full-width merged, blue background).
  • Row 2 of the Excel: fully dynamic approval-sheet heading (full-width merged).
  • Works correctly for any semester (1–8), any batch (UG2021/2022/2023/2024…), any branch (CSE/ECE/ME/IT…), and any academic year.

REQ-2 – Excel Header Alignment

  • All header cells (rows 3–7) now have horizontal="center" and vertical="center" alignment.
  • S.No / Roll No / Name columns are merged across all 5 header rows (rows 3–7) to match the multi-row course columns — previously these were single-row and appeared misaligned.
  • SPI / CPI / SU / TU / SP / TP columns are also merged across all 5 header rows.
  • The mass-fill loop now unconditionally applies center_align to every header cell, so no cell is left without alignment regardless of future column additions.
  • Title rows 1 and 2 are also center-aligned.

REQ-3 – Automatic Sequential Subject Numbering

  • Courses queryset now uses .order_by('code') for deterministic, alphabetical ordering (previously unordered / PK order).
  • A dedicated subject-number row (row 3 of the header block) is inserted above the course-code row; numbers are generated via enumerate(courses_list, start=1).
  • Numbers automatically adjust when subjects are added or removed — no manual numbering required.
  • The same courses_list (evaluated once) drives both the Excel header block and the per-student grade data loop, guaranteeing identical subject order between the web preview and the downloaded Excel.

Files Modified

File Change
FusionIIIT/applications/examination/api/views.py GenerateResultAPI: added 2 helpers, rewrote Excel generation block (201 insertions, 76 deletions)

Testing

38/38 tests passed (pure-Python, no DB required):

Category Tests Result
Ordinal suffix helper 3 ✅ All pass
Academic year derivation (all 8 semesters, 4 batches) 12 ✅ All pass
Dynamic heading string construction 6 ✅ All pass
Excel header alignment (H+V center, merges) 4 ✅ All pass
Subject numbering & ordering 5 ✅ All pass
End-to-end heading in Excel cell A2 6 ✅ All pass
Integration (save + reload workbook) 2 ✅ All pass

Test script: .agents/tasks/test_approval_sheet.py


Checklist

  • No hardcoded academic year, batch, branch, semester, or subject numbers
  • No database migrations
  • No model changes
  • No serializer changes
  • No frontend changes
  • Existing Acad Admin permission check preserved (role == "acadadmin")
  • Existing API contract unchanged (same endpoint, same request body)
  • Works for all semesters 1–8, all batches, all branches

…mbering in approval sheet

REQ-1 – Dynamic approval-sheet heading
- Added _ordinal_suffix() helper to produce '1st', '2nd', '3rd', '6th', etc.
- Added _derive_academic_year() helper that reads the AY from Student_grades
  records (primary source) with a fallback formula based on batch admission
  year + semester number (pairs 1-2, 3-4, 5-6, 7-8 share the same AY).
- Row 1 of the Excel now contains the institute name (full-width merged cell,
  blue background).
- Row 2 contains the fully dynamic heading, e.g.
  'Approval sheet for Even Semester AY2025-26 (UG2023 Batch (CSE) - SEM-6th)'
  No values are hardcoded; all components are derived from request params and
  database records.

REQ-2 – Excel header alignment
- S.No / Roll No / Name columns are now merged across all five header rows
  (rows 3-7) to match the multi-row course columns.
- The mass-fill loop now explicitly sets Alignment(horizontal='center',
  vertical='center', wrap_text=True) on every header cell, covering both
  merged-cell anchors and standalone cells (SPI/CPI tail columns).
- Title rows 1-2 are also center-aligned.

REQ-3 – Automatic sequential subject numbering
- Courses queryset now uses .order_by('code') for deterministic ordering.
- A dedicated subject-number row is added above the course-code row; numbers
  are generated with enumerate(courses_list, start=1) so they automatically
  adjust when subjects are added or removed.
- The same courses_list drives both the header block and the per-student grade
  loop, guaranteeing identical order in web preview and downloaded Excel.

No migrations, no model changes, no serializer changes, no frontend changes.
Existing API contract and Acad Admin permission check are preserved.
@FusionIIIT-Bot

Copy link
Copy Markdown
Collaborator

Congratulations for making your first Pull Request at Fusion!! 🎉 Someone from our team will review it soon.

@vikrantwiz02

Copy link
Copy Markdown
Member

@dreamweaver19, this was not the latest branch, and due to this it have many conflicts and can't get merged in production. I'm pulling your code changes and raising PR again into branch prod/acad-react.

@vikrantwiz02

Copy link
Copy Markdown
Member

Closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants