You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix N+1 queries in sessão/relatórios and remove unused painel views
Performance-only slice extracted from feat/rate-limiter-2026 (commit
2f2a976), which bundled query-optimization work in with unrelated
rate-limiter/caching changes.
- customize_link_materia() and the Ordem do Dia / Expediente ListViews
now use prefetched querysets instead of per-row queries.
- get_etiqueta_protocolos() batch-fetches MateriaLegislativa and
DocumentoAdministrativo instead of querying per protocolo in a loop.
- New migration redefines the materia_materiaemtramitacao view and adds
a concurrent index (tram_materia_id_desc) backing the tramitacao
prefetch.
- Drops a redundant .distinct() + order_by on a related field in
RelatorioMateriasTramitacaoFilterSet.qs.
- Removes the unused painel_mensagem/parlamentar/votacao views and
templates (also bundled into 2f2a976 by mistake).
- Adds CLAUDE.md project documentation.
Note: feat/painel-votacao-v2 still imports painel_mensagem_view,
painel_parlamentar_view and painel_votacao_view. That branch will need
reconciling with this removal when it's rebased onto 3.1.x.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## Project Overview
6
+
7
+
SAPL (Sistema de Apoio ao Processo Legislativo) is a Django-based legislative management system used by Brazilian municipal and state legislative houses. It manages bills, parliamentary sessions, committees, norms, protocols, and related legislative workflows.
8
+
9
+
## Commands
10
+
11
+
### Development
12
+
13
+
```bash
14
+
# Run dev server
15
+
python manage.py runserver
16
+
17
+
# Docker (dev, without bundled DB)
18
+
docker-compose -f docker/docker-compose-dev.yml up
19
+
20
+
# Docker (dev, with PostgreSQL container)
21
+
docker-compose -f docker/docker-compose-dev-db.yml up
Tests require `DJANGO_SETTINGS_MODULE=sapl.settings` (set in `pytest.ini`). All tests must be marked with `@pytest.mark.django_db`. The `conftest.py` root fixture provides an `app` fixture (WebTest `DjangoTestApp`).
50
+
51
+
### Linting / Formatting
52
+
53
+
```bash
54
+
flake8 .
55
+
isort .
56
+
autopep8 --in-place <file.py>
57
+
```
58
+
59
+
### Restore Database from Backup
60
+
61
+
```bash
62
+
./scripts/restore_db.sh -f /path/to/dump
63
+
./scripts/restore_db.sh -f /path/to/dump -p 5433 # Docker port
64
+
```
65
+
66
+
## Architecture
67
+
68
+
### Django Apps
69
+
70
+
Apps are under `sapl/` and follow domain boundaries:
71
+
72
+
| App | Domain |
73
+
|-----|--------|
74
+
|`base`|`CasaLegislativa` (legislative house config), `AppConfig`, `Autor` (authorship) |
|`comissoes`| Committees (`Comissao`) and meetings (`Reuniao`) |
80
+
|`protocoloadm`| Administrative protocols and document intake |
81
+
|`compilacao`| Structured/articulated texts (LexML-like tree structure) |
82
+
|`lexml`| LexML XML standard integration |
83
+
|`audiencia`| Public hearings |
84
+
|`painel`| Real-time session display panel |
85
+
|`relatorios`| PDF report generation |
86
+
|`api`| REST API entry point (auto-generated ViewSets) |
87
+
|`crud`| Generic CRUD base views |
88
+
|`rules`| Business rules and permission definitions |
89
+
90
+
### REST API
91
+
92
+
The API uses a custom `drfautoapi` package (`drfautoapi/drfautoapi.py`) that auto-generates DRF ViewSets, Serializers, and FilterSets from Django models. Authentication is Token + Session. Permissions use a custom `SaplModelPermissions` class that maps HTTP methods to Django model permissions.
93
+
94
+
OpenAPI 3.0 docs are generated by drf-spectacular.
0 commit comments