From df8f3a59f2a114ef2c162ba642aa8fd1c595cb99 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 6 Oct 2026 10:26:34 +0100 Subject: [PATCH] fix: rename schedules --- .env.example | 2 +- app/bootstrap.py | 4 +- app/templates/admin_schedule.html | 13 ---- app/templates/dashboard.html | 2 - app/templates/schedule.html | 13 ---- docs/DOMAIN.md | 6 +- ...1_rename_seeded_schedules_to_portuguese.py | 61 +++++++++++++++++++ tests/test_admin_schedule_assignments.py | 6 +- tests/test_bootstrap.py | 4 +- tests/test_migrations.py | 41 ++++++++++++- tests/test_public_schedules.py | 14 ++--- 11 files changed, 119 insertions(+), 47 deletions(-) create mode 100644 migrations/versions/bd2d4bb905b1_rename_seeded_schedules_to_portuguese.py diff --git a/.env.example b/.env.example index 52865a7..16daa4e 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/app/bootstrap.py b/app/bootstrap.py index d2437fd..b8a258a 100644 --- a/app/bootstrap.py +++ b/app/bootstrap.py @@ -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", diff --git a/app/templates/admin_schedule.html b/app/templates/admin_schedule.html index 1e4e0bd..4ab3055 100644 --- a/app/templates/admin_schedule.html +++ b/app/templates/admin_schedule.html @@ -81,7 +81,6 @@ {% else %}

Repete todos os meses

-

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.

@@ -98,17 +97,5 @@
{% endif %} - {% if cards | length > 1 %} -
-

Outras escalas

- -
- {% endif %} {% endblock %} diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index c037487..f302dcc 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -2,9 +2,7 @@ {% block content %}
-

Rota

{{ month_name }} {{ year }}

-

Noite todos os dias, mais as escalas de almoço de sábado e de domingo.

← Anterior diff --git a/app/templates/schedule.html b/app/templates/schedule.html index 3bb5886..ba61199 100644 --- a/app/templates/schedule.html +++ b/app/templates/schedule.html @@ -21,7 +21,6 @@ {% else %}
  • Ainda não há membros.
  • {% endfor %} {% else %} -

    Igual todos os meses: uma pessoa para cada dia do mês.

    Padrão

    {% endif %} - {% if cards | length > 1 %} -
    -

    Outras escalas

    - -
    - {% endif %}
    {% if not current_user %} diff --git a/docs/DOMAIN.md b/docs/DOMAIN.md index 1990943..9af58dd 100644 --- a/docs/DOMAIN.md +++ b/docs/DOMAIN.md @@ -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`. diff --git a/migrations/versions/bd2d4bb905b1_rename_seeded_schedules_to_portuguese.py b/migrations/versions/bd2d4bb905b1_rename_seeded_schedules_to_portuguese.py new file mode 100644 index 0000000..2053373 --- /dev/null +++ b/migrations/versions/bd2d4bb905b1_rename_seeded_schedules_to_portuguese.py @@ -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"}), + }, + ) \ No newline at end of file diff --git a/tests/test_admin_schedule_assignments.py b/tests/test_admin_schedule_assignments.py index c0cbb5a..2dfeb9a 100644 --- a/tests/test_admin_schedule_assignments.py +++ b/tests/test_admin_schedule_assignments.py @@ -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 diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 8427baa..6c209c6 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -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" diff --git a/tests/test_migrations.py b/tests/test_migrations.py index b30faeb..db1838e 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -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): diff --git a/tests/test_public_schedules.py b/tests/test_public_schedules.py index a89c8aa..95dd5f2 100644 --- a/tests/test_public_schedules.py +++ b/tests/test_public_schedules.py @@ -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

    " in page assert '