# T12 Analysis — Code Organization & Test Suite Reduction

## Phase 0: Code Organization

### Module boundary decisions

| Module | Decision | Rationale |
|--------|----------|-----------|
| `views.py` | SIMPLIFY | Removed DRF endpoint + helpers; now contains only redirect views (FormWizardsDashboardView, FormEntryImportView) |
| `api/views.py` | NEW | DRF `get_form_fields` + `normalize_field_choices` + helpers moved here |
| `api/urls.py` | NEW | `fobi-form-fields/<slug>/` wired here; consumers use `include("unfold_fobi.api.urls")` |
| `context_processors.py` | KEEP | FOBI_TITLES map + admin_site() are actively used by every fobi template render |
| `forms.py` | KEEP | `apply_unfold_widgets_to_form` + `FormEntryFormWithCloneable` serve admin forms |
| `services.py` | KEEP | `clone_form_entry` used by admin clone action |
| `admin.py` | KEEP | Core FormEntryProxyAdmin; slug added to readonly_fields |
| `apps.py` | SIMPLIFY | Removed unused `BaseModelFormSet` import |
| `fobi_admin.py` | SIMPLIFY | Fixed import ordering (E402), replaced % format with f-strings |
| `templatetags/unfold_fobi_tags.py` | KEEP | `length_is`, `get_form_classes`, `captureas` all actively used |

### Cleanup applied

- Removed unused `BaseModelFormSet` import from `apps.py`
- Removed unused `required` variable from `add_rest_api_form_data.py`
- Fixed all trailing whitespace in blank lines (W293) across 4 files
- Fixed all `%` format strings → f-strings (UP031) across 3 files
- Fixed import ordering in `fobi_admin.py` and `create_test_form.py` (E402)
- Fixed unused loop variable `field_name` → `_field_name` in `forms.py` (B007)
- Ran `ruff format` across all 45 files (28 reformatted)

### Slug read-only

- Slug displayed as read-only on change view via `get_readonly_fields()`
- Hidden on add view (auto-generated by `AutoSlugField(populate_from="name")`)
- Codex P1 finding: global `readonly_fields` would hide slug on add view — fixed by using `get_readonly_fields` with `obj` check

## Phase 1: Test Classification

| Test | Classification | Rationale |
|------|---------------|-----------|
| `test_edit_view::test_form_name_displayed` | REMOVE_REDUNDANT | Duplicate of `test_t03_view_contracts::test_change_view_contains_form_name` |
| `TestGermanTranslationActivation` (5 tests) | MERGE | 5 identical test bodies → 1 parametrized test with 5 cases |
| All other tests | KEEP_CRITICAL/KEEP_USEFUL | Cover core admin, DRF, popup, i18n, and routing contracts |

## Metrics

| Metric | Before | After |
|--------|--------|-------|
| Test count | 134 | 133 |
| Ruff lint errors | 20 | 0 |
| Files needing format | 29 | 0 |
| Source files changed | 0 | 12 |
| New files | 0 | 3 (`api/__init__.py`, `api/views.py`, `api/urls.py`) |

## Status: DONE