# ALPHA — the ATO page generator

> **DRAFT — do not use.** This folder is waiting for MT to confirm the themes.
> Do not run the generator to produce pages until MT says so.
> The locked page look is tag `locked/ato-page-final-v2-10nov` (`b18669e9`):
> `site/ato-v6.html` and `site/ato-v6/`. That look must stay pixel-identical.

## Fixed on 11 Nov 2026 (branch `preview/reviews-d1-and-generator-fixes-11nov`)

The page look was not changed. No CSS file and no drawing in `svg.py` was touched.

| # | Bug | Fix |
|---|---|---|
| 1 | Bars, "Written reviews" and "Rated 4.0+" were counted from the 3 reviews on the page; the big number came from all of them | Every card number comes from one rating summary (`rating.py`), the object the server sends. A summary that does not add up stops the build |
| 2 | `round()` put a 4.5 review in the 4 bar | One rule, halves up, in `rating.bar_of` |
| 3 | `--today` defaulted to 2026-11-09 | Default is today in South Africa |
| 4 | Rating showed at 3 reviews, ignoring the 7-day account rule | The page uses the server's `shown` flag |
| 5 | "N more reviews" counted hidden stars-only and deleted reviews | It counts written reviews only |
| 6 | Two schools with one slug overwrote each other | The build stops and names both |
| 7 | Any name containing "skyhawk", "aeronav" or "excellentia" was merged into Aeronav | Merges are an exact list (`master_convert.MERGES`); merged schools keep every certificate |
| 8 | The slug was not checked before it became a folder name | Checked in `check()`; reserved names refused; the path must stay inside the output folder |
| 9 | Phone, email and website went into links unchecked; missing ones were dead `#` links | Validated; a bad value is left out and reported; a missing one is not a link |
| 10 | Upvote counting used the clock and skipped the 20-a-day cap | The server's count (`up`) is used; example data uses the build date, so builds repeat |
| 11 | "pilot" was stripped from course names with no choice | Same default; `--keep-pilot-in-courses` keeps it (decision D4) |
| 12 | `rules.py`, README and tests described superseded rules | Updated to N-10, REV-029, REV-049 |
| 13 | Every page was `noindex` with no description, canonical link or rating markup; sign-in lost the page | `--index`, `--site`, description, rating markup only when shown, sign-in returns to the school |
| + | The viewer API address used the certificate number | `/api/ato/{slug}/view`: reviews belong to the school (REV-003) |
| + | Anonymous reviews showed a made-up day ("1 Aug 2026") | Month only ("Aug 2026", REV-038) |
| + | Private fields were blocked by a short list of names | An allow-list: any unknown field stops the build |
| + | Pages of removed schools stayed in the output | Reported in `manifest.json`; `--prune` removes them |

**Not done, and why.** The locked page shows the seven category averages under the rating card (t1289u). This
template does not draw them. `--show-categories` draws them from the summary, but with the class names found in
this folder's CSS copy, which is older than the locked page. It is off by default. The row markup must be copied
from `site/ato-v6/v6.js` at `b18669e9` before it is switched on.

**Styles (fixed 11 Nov).** `static/ato-v6.css` and `static/ato-page.css` are now exact copies of the locked page's
`site/ato-v6/v6.css` and `site/c/wst/ato-page.css` at `b18669e9`. Pages link them at `/ato/static/`, in the same
order as the locked page. Before this, pages linked `/ato-v6/v6.css`, which is not on main, and never loaded
`ato-page.css`, so each base row's arrow was drawn the size of the card. The 390px Amethyst picture was taken after the fix.

**In plain words:** one template makes every ATO page. You give it a school's data file (or the master file) and a colour theme; it writes the finished guest page body. The top bar and logo live in `/ato/_shared/topbar.js` (ATO-20) and are not copied into each page. Design = the approved 2-column page (REV-061 / DEC-011).

## How to run (one command)
```
cd ato-generator && pip install -r requirements.txt && python3 generator.py && python3 -m pytest -q
```
Example pages appear in `out/<school-slug>/index.html`. All 277 schools:
`python3 generator.py --master ../docs/ato-master/ato-master-10nov.json --out build`
(writes `build/<slug>/index.html` plus `_redirects`). Another theme: `python3 generator.py --theme pearl --out out-pearl`.

## What each file does
| File | What it does |
|---|---|
| `generator.py` | The main script. Reads each school file, checks it, decides the rules once (gold tick only if paid, rating only from 3 reviews, shiny stars from 4.0, guests see the top 3 reviews by counted upvotes with ties going to the newest, the 7 categories in order), then fills the approved 2-column template and writes one page per school. Also writes `out/manifest.json` (which pages, which data). |
| `rating.py` | The rating summary: checks the one the server sends, and mirrors the server's arithmetic for tests and example data (exact fractions, halves up). |
| `rules.py` | The review rules the server will enforce later. Stars first and text later: stars stay locked, it is not a new review, it uses no quota, and the review shows "Text added <date>". The 6-month replace is the only way to change stars. Replies under your own Anonymous review stay Anonymous; a named review means named replies; otherwise Trial, Pro and Founding choose per reply (N-10). |
| `svg.py` | The locked drawings: ticks (DFE blue, ATO gold), Founding compass, glass / flat / empty stars, star pyramid. Same as the v6.2 design. |
| `template/ato.html.j2` | The page shell: puts the parts in order. |
| `template/parts/hero.j2` | Base, school name (+ gold tick if paid), `.official` handle, big score + stars, "4.3 from N reviews". |
| `template/parts/bases_certificates.j2` | Each base (ICAO + name → `/ad/{CODE}`, or plain text when there is no code) with its certificate on one line: Current/Expired + date + "Updated &lt;date&gt;". |
| `template/parts/about_contact.j2` | About text + Call / Email / Website in one card. |
| `template/parts/reviews.j2` | Reviews heading, the approved rating card (score, 2×2 stats, 5-to-1 bars), guest top 3 by counted aged upvotes, then "Sign in to see the rest". |
| `template/parts/courses.j2` | Courses under About and Bases: Licences / Ratings / Other, first 3 + More. |
| `template/parts/badges.j2` | Name + badge rules: DFE wins over Founding. Anonymous shows "Anonymous" with no avatar, no badges and no licences. Gold tick for paid or gifted Premium. |
| `themes/*.css` | The 4 colour token files: Midnight, Amethyst, Pearl, Champagne. Colours only. |
| `static/` | Shared page CSS (from the v6.2 design) + a small script: number fit and sweep, replies and courses open smoothly. |
| `data/ato/*.json` | 2 example schools: one paid (2 bases, 2 certificates, one expired), one unpaid verified (1 base, 2 reviews, so no rating yet). |
| `tests/` | Automatic checks (pytest), listed below. |
| `out/` | The generated pages. Never edited by hand. |

## Later, not in the static page
The generated page is the guest view only (REV-061). The review form, votes and the rest of the reviews come after sign-in, not from placeholders copied into the static HTML.

## Tests (83, all pass)
- Gold tick only for paid schools, and it goes away when a school stops paying.
- Rating hidden under 3 reviews.
- Shiny from 4.0: 4.3 and 4.0 are shiny, 3.99 and 3.6 are flat. The 4.3 page has the sweep.
- 7 categories in the right order.
- Guests get the top 3 reviews by counted upvotes, ties go to the newest.
- Anonymous carries no name, badges or licences.
- Certificates show Current and Expired, plus "Updated <date>".
- No form or votes in the static page.
- "4.3 from N reviews" and the "Edited" tag.
- Stars then text: stars locked, no quota, text only once, replace after 6 months.
- Replies follow the review's anonymous choice.
- Courses show for guests, right after Ratings.
