Skip to content

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

===== Monthly Report =====
Company: Acme Corp
Period: January 2024
...
12 passed

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

  1. Add a --validate flag that checks all variables are provided before rendering.
  2. Add support for simple conditionals: ${if_debug}...${endif}.
  3. Add an --output flag to write rendered output to a file.

Break it (required) — Core

  1. Use a template with a missing variable in strict mode — what happens?
  2. Pass a data file with nested objects but no build_report_context flattening — what renders?
  3. Use $$ literal dollar signs in a template — does Template handle them?

Fix it (required) — Core

  1. Add a --missing flag that lists all variables not provided by the data.
  2. Improve build_report_context to handle deeper nesting (2+ levels).
  3. 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)

  1. How does string.Template differ from f-strings?
  2. What is the difference between substitute and safe_substitute?
  3. Why separate data from presentation (templates)?
  4. How does discover_variables find 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).



← Prev Home Next →