fix: rename schedules

This commit is contained in:
jfmcarreira committed 2026-10-06 10:30:01 +01:00
1 parent 5f4130a50b
commit df8f3a59f2
11 files changed
+119 -47

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ PORT=8000
DATA_DIR=./data
# Initial admin is created only if no users exist.
INITIAL_ADMIN_NAME=Administrator
INITIAL_ADMIN_NAME=Administrador
INITIAL_ADMIN_USERNAME=admin
INITIAL_ADMIN_EMAIL=admin@example.com
INITIAL_ADMIN_PASSWORD=change-me-now
+2 -2
View File
@@ -36,7 +36,7 @@ def ensure_initial_data(db: Session) -> None:
"rotation_anchor_date": None,
},
{
"name": "Almoço de sábado",
"name": "Almoço - Sábados",
"slug": "saturday-lunch",
"schedule_type": "rotation",
"weekdays": "5",
@@ -44,7 +44,7 @@ def ensure_initial_data(db: Session) -> None:
"rotation_anchor_date": date(2024, 1, 6),
},
{
"name": "Almoço de domingo",
"name": "Almoço - Domingo",
"slug": "sunday-lunch",
"schedule_type": "rotation",
"weekdays": "6",
-13
View File
@@ -81,7 +81,6 @@
{% else %}
<section class="panel">
<h3>Repete todos os meses</h3>
<p class="muted">Uma pessoa para cada dia do mês, igual todos os meses. Os dias 29 a 31 só se aplicam a meses que os tenham. Ao guardar, são preenchidas as noites que ainda não têm ninguém; as noites já atribuídas mantêm a sua pessoa.</p>
<form method="post" action="/admin/schedules/{{ schedule.id }}/pattern">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<div class="pattern-grid">
@@ -98,17 +97,5 @@
</form>
</section>
{% endif %}
{% if cards | length > 1 %}
<section class="panel">
<h3>Outras escalas</h3>
<ul class="link-list">
{% for other in cards %}
{% if other.schedule.id != schedule.id %}
<li><a href="/admin/schedules/{{ other.schedule.id }}">{{ other.schedule.name }}</a> <span class="muted">{{ other.kind_label }}</span></li>
{% endif %}
{% endfor %}
</ul>
</section>
{% endif %}
</div>
{% endblock %}
-2
View File
@@ -2,9 +2,7 @@
{% block content %}
<div class="page-head">
<div>
<p class="eyebrow">Rota</p>
<h1>{{ month_name }} {{ year }}</h1>
<p class="muted">Noite todos os dias, mais as escalas de almoço de sábado e de domingo.</p>
</div>
<div class="month-nav">
<a class="button secondary" href="/?year={{ prev[0] }}&month={{ prev[1] }}">← Anterior</a>
-13
View File
@@ -21,7 +21,6 @@
{% else %}<li class="muted">Ainda não há membros.</li>{% endfor %}
</ol>
{% else %}
<p class="muted">Igual todos os meses: uma pessoa para cada dia do mês.</p>
<h3>Padrão</h3>
<ul class="link-list">
{% for day, person_name in card.pattern %}
@@ -30,18 +29,6 @@
</ul>
{% endif %}
</section>
{% if cards | length > 1 %}
<section class="panel">
<h3>Outras escalas</h3>
<ul class="link-list">
{% for other in cards %}
{% if other.schedule.id != schedule.id %}
<li><a href="/schedules/{{ other.schedule.id }}">{{ other.schedule.name }}</a> <span class="muted">{{ other.kind_label }}</span></li>
{% endif %}
{% endfor %}
</ul>
</section>
{% endif %}
</div>
{% if not current_user %}
<div class="top-space"><a class="button primary" href="/login">Entrar</a></div>
+3 -3
View File
@@ -8,7 +8,7 @@ This distinction is intentional: editing a rotation must not retroactively chang
## Seeded schedules
Seeded names are Portuguese (`Noite`, `Almoço de sábado`, `Almoço de domingo`); the slugs stay `night`, `saturday-lunch` and `sunday-lunch`.
Seeded names are Portuguese (`Noite`, `Almoço - Sábados`, `Almoço - Domingo`); the slugs stay `night`, `saturday-lunch` and `sunday-lunch`.
### Night (`Noite`)
@@ -19,14 +19,14 @@ Seeded names are Portuguese (`Noite`, `Almoço de sábado`, `Almoço de domingo`
- There is no per-month configuration for Night: the same pattern is used every month.
- Existing assignments are never rewritten by a pattern change; they keep the person they already had.
### Saturday Lunch (`Almoço de sábado`)
### Saturday Lunch (`Almoço - Sábados`)
- Saturdays only.
- Type: `rotation`.
- Has its own ordered member list.
- Continues after the previous assigned person's position in the rotation, including across month boundaries. The anchor date is the fallback when there is no usable previous assignee.
### Sunday Lunch (`Almoço de domingo`)
### Sunday Lunch (`Almoço - Domingo`)
- Sundays only.
- Type: `rotation`.
@@ -0,0 +1,61 @@
"""rename seeded schedules to Portuguese
Revision ID: bd2d4bb905b1
Revises: 0002_monthly_pattern
Create Date: 2026-10-06 10:17:33.738521
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'bd2d4bb905b1'
down_revision: Union[str, Sequence[str], None] = '0002_monthly_pattern'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
# slug -> (name, names it may already have, label_time, label_times it may already have)
RENAMES = {
"night": ("Noite", {"Night"}, "Noite", {"Night"}),
"saturday-lunch": ("Almoço - Sábados", {"Saturday Lunch", "Almoço de sábado"}, "Almoço", {"Lunch"}),
"sunday-lunch": ("Almoço - Domingo", {"Sunday Lunch", "Almoço de domingo"}, "Almoço", {"Lunch"}),
}
def _rename(connection, renames: dict[str, tuple[str, set[str], str, set[str]]]) -> None:
for slug, (name, old_names, label_time, old_label_times) in renames.items():
for old_name in sorted(old_names):
connection.execute(
sa.text(
"UPDATE schedules SET name = :name, label_time = :label_time "
"WHERE slug = :slug AND name = :old_name"
),
{"name": name, "label_time": label_time, "slug": slug, "old_name": old_name},
)
for old_label_time in sorted(old_label_times):
connection.execute(
sa.text("UPDATE schedules SET label_time = :label_time "
"WHERE slug = :slug AND label_time = :old_label_time"),
{"label_time": label_time, "slug": slug, "old_label_time": old_label_time},
)
def upgrade() -> None:
"""Rename the seeded schedules without touching a name an administrator chose."""
_rename(op.get_bind(), RENAMES)
def downgrade() -> None:
"""Restore the previous English names."""
_rename(
op.get_bind(),
{
"night": ("Night", {"Noite"}, "Night", {"Noite"}),
"saturday-lunch": ("Saturday Lunch", {"Almoço - Sábados"}, "Lunch", {"Almoço"}),
"sunday-lunch": ("Sunday Lunch", {"Almoço - Domingo"}, "Lunch", {"Almoço"}),
},
)
+3 -3
View File
@@ -53,7 +53,7 @@ def seed(db):
is_active=True,
)
sat = Schedule(
name="Almoço de sábado",
name="Almoço - Sábados",
slug="saturday-lunch",
schedule_type="rotation",
weekdays="5",
@@ -63,7 +63,7 @@ def seed(db):
rotation_anchor_date=date(2026, 1, 3),
)
sun = Schedule(
name="Almoço de domingo",
name="Almoço - Domingo",
slug="sunday-lunch",
schedule_type="rotation",
weekdays="6",
@@ -249,7 +249,7 @@ def test_saturday_page_only_shows_saturdays(client, db):
page = client.get(f"/admin/schedules/{sat.id}?year={YEAR}&month={MONTH}").text
assert page.count("assignment_") == len([d for d in range(1, 32) if date(2026, 10, d).weekday() == 5])
assert "Almoço de domingo" in page # listed under other schedules
assert "Almoço - Domingo" in page # listed under other schedules
assert "Guardar Outubro" in page
+2 -2
View File
@@ -26,5 +26,5 @@ def test_seeded_schedules_are_named_in_portuguese(monkeypatch):
for slug, name in db.execute(select(Schedule.slug, Schedule.name)).all()
}
assert names["night"] == "Noite"
assert names["saturday-lunch"] == "Almoço de sábado"
assert names["sunday-lunch"] == "Almoço de domingo"
assert names["saturday-lunch"] == "Almoço - Sábados"
assert names["sunday-lunch"] == "Almoço - Domingo"
+40 -1
View File
@@ -24,7 +24,46 @@ def test_migrations_produce_the_model_schema(tmp_path, monkeypatch):
with engine.connect() as connection:
head = connection.execute(text("select version_num from alembic_version")).scalar_one()
assert head == "0002_monthly_pattern"
assert head == "bd2d4bb905b1"
def test_seeded_schedule_names_are_renamed_without_touching_custom_names(tmp_path, monkeypatch):
"""Old English databases get the Portuguese names; a name the admin chose is kept."""
from alembic import command
from app.database import alembic_config
db_path = tmp_path / "names.db"
url = f"sqlite:///{db_path}"
monkeypatch.setenv("DATABASE_URL", url)
monkeypatch.setattr("app.config.settings.database_url", url)
config = alembic_config()
command.upgrade(config, "0002_monthly_pattern")
engine = create_engine(url)
with engine.begin() as connection:
connection.execute(text(
"INSERT INTO schedules (slug, name, schedule_type, weekdays, label_time, "
"requires_manager_approval, is_active, created_at) VALUES "
"('night', 'Night', 'fixed', '0,1,2,3,4,5,6', 'Night', 1, 1, '2024-01-01 00:00:00'), "
"('saturday-lunch', 'Saturday Lunch', 'rotation', '5', 'Lunch', 1, 1, '2024-01-01 00:00:00'), "
"('sunday-lunch', 'Sundays off', 'rotation', '6', 'Lunch', 1, 1, '2024-01-01 00:00:00')"
))
command.upgrade(config, "head")
with engine.connect() as connection:
rows = dict(connection.execute(text("select slug, name from schedules")).all())
labels = dict(connection.execute(text("select slug, label_time from schedules")).all())
assert rows == {
"night": "Noite",
"saturday-lunch": "Almoço - Sábados",
"sunday-lunch": "Sundays off", # renamed by an administrator, left alone
}
assert labels["night"] == "Noite"
assert labels["saturday-lunch"] == "Almoço"
assert labels["sunday-lunch"] == "Almoço" # the time label is translated regardless
def test_a_new_column_gets_a_revision(monkeypatch, tmp_path):
+7 -7
View File
@@ -88,8 +88,8 @@ def login(client: TestClient, username: str, password: str) -> str:
def seed_schedules(db):
night = add_schedule(db, name="Noite", slug="night", schedule_type="fixed", weekdays="0,1,2,3,4,5,6", label_time="Noite")
sat = add_schedule(db, name="Almoço de sábado", slug="sat")
sun = add_schedule(db, name="Almoço de domingo", slug="sun", weekdays="6")
sat = add_schedule(db, name="Almoço - Sábados", slug="sat")
sun = add_schedule(db, name="Almoço - Domingo", slug="sun", weekdays="6")
ana = add_person(db, "Ana")
bruno = add_person(db, "Bruno")
add_rotation_member(db, sat, ana, 0)
@@ -105,8 +105,8 @@ def test_public_schedules_page_is_open_to_anonymous_visitors(client, db):
response = client.get("/schedules", follow_redirects=False)
assert response.status_code == 200
assert "Almoço de sábado" in response.text
assert "Almoço de domingo" in response.text
assert "Almoço - Sábados" in response.text
assert "Almoço - Domingo" in response.text
def test_rota_is_the_landing_page_for_signed_out_visitors(client, db):
@@ -116,7 +116,7 @@ def test_rota_is_the_landing_page_for_signed_out_visitors(client, db):
assert ">Rota</p>" in page
assert '<a class="brand" href="/"' in page
assert "Almoço de sábado" in page
assert "Almoço - Sábados" in page
assert "Entrar" in page
assert "Pedir troca" not in page
assert "/swap" not in page
@@ -145,7 +145,7 @@ def test_public_schedules_show_details_and_rotation_order(client, db):
detail = client.get(f"/schedules/{sat.id}").text
assert "Noite" in hub
assert "Almoço de sábado" in hub
assert "Almoço - Sábados" in hub
assert "Ana" in detail
assert "Bruno" in detail
assert "Todos os dias" in client.get(f"/schedules/{night.id}").text
@@ -239,7 +239,7 @@ def test_signed_in_member_can_also_read_public_schedules(client, db):
db.commit()
assert "Entrar" not in login(client, "member", "member-password")
assert "Almoço de sábado" in client.get("/schedules").text
assert "Almoço - Sábados" in client.get("/schedules").text
def test_rota_is_read_only_for_signed_out_visitors(client, db):