Level 3 / Project 08 - Template Driven Reporter¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Estimated time: 45 minutes
Focus¶
- report rendering from templates
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-3/08-template-driven-reporter
python project.py render report_template.txt report_data.json
python project.py discover report_template.txt
python project.py batch invoice_template.txt customers.json
pytest -q
Expected terminal output¶
Expected artifacts¶
- Rendered report on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--validateflag that checks all variables are provided before rendering. - Add support for simple conditionals:
${if_debug}...${endif}. - Add an
--outputflag to write rendered output to a file.
Break it (required) — Core¶
- Use a template with a missing variable in strict mode — what happens?
- Pass a data file with nested objects but no
build_report_contextflattening — what renders? - Use
$$literal dollar signs in a template — does Template handle them?
Fix it (required) — Core¶
- Add a
--missingflag that lists all variables not provided by the data. - Improve
build_report_contextto handle deeper nesting (2+ levels). - Add error handling for invalid JSON in the data file.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- How does
string.Templatediffer from f-strings? - What is the difference between
substituteandsafe_substitute? - Why separate data from presentation (templates)?
- How does
discover_variablesfind placeholders in a template?
Mastery check¶
You can move on when you can:
- use string.Template for safe text rendering,
- separate data from presentation in reports,
- discover and validate template variables,
- render templates for batch data (multiple records).
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|