#1 closed task (fixed)
Refactor render logic
| Reported by: | bazzuser | Owned by: | enno |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Version: | Keywords: | UX | |
| Cc: |
Description
Description:
The current HTML/Jinja2 template uses multiple nested if/elif blocks to render different question types (text, radio, checkbox, candidate_id) and media (image, audio, video). This approach goes against our goal of a clean, object-oriented architecture and results in a template that is difficult to maintain.
Refactoring Goal:
Move the rendering logic out of the template and into the respective Python classes. Both Question subclasses and MediaItem subclasses should implement a to_html() method that is directly invoked from the template.
Example Jinja2 usage after refactoring:
{{ question.to_html() | safe }}
Acceptance Criteria:
- The template file (exam.html) no longer contains any if q.type or if m.type logic.
- All supported question types are rendered via their respective to_html() methods.
- Optional media items are rendered via to_media_html().
- The visual output is semantically identical to the current implementation.
- All to_html() methods follow a consistent interface and can be tested individually.
Notes:
- to_html() returns HTML strings (not Jinja snippets).
- If a NullMediaItem is used, to_media_html() simply returns an empty string.
- The goal is a "Smalltalk-inspired" design: objects are fully responsible for their own rendering.
Change History (4)
comment:1 by , 4 months ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:2 by , 4 months ago
| Status: | assigned → accepted |
|---|
comment:3 by , 4 months ago
| Resolution: | → fixed |
|---|---|
| Status: | accepted → closed |

fixed