Merge branch 'claude/relaxed-faraday-h4zd09' of https://github.com/pablovolenski/vienalatina

This commit is contained in:
admin 2026-10-06 21:33:21 +00:00
commit 7063c473e7
17 changed files with 479 additions and 45 deletions

View File

@ -20,6 +20,7 @@ from flask import (Blueprint, abort, current_app, flash, g, redirect,
from . import auth, uploads from . import auth, uploads
from .db import get_db from .db import get_db
from . import titles
from .render import excerpt, to_html from .render import excerpt, to_html
from .security import admin_required, is_at_least, login_required from .security import admin_required, is_at_least, login_required
@ -69,9 +70,16 @@ def cooldown_remaining() -> int:
def _clean(title: str, body: str) -> tuple[str, str] | None: def _clean(title: str, body: str) -> tuple[str, str] | None:
title = title.strip()[:TITLE_MAX] title = title.strip()[:TITLE_MAX]
body = body.strip()[:BODY_MAX] body = body.strip()[:BODY_MAX]
if not title or not body: if not body:
flash("El título y el mensaje no pueden estar vacíos.", "error") flash("El mensaje no puede estar vacío.", "error")
return None return None
if not title:
# Counting the deleted ones too: a number that comes back is a thread
# that looks like one somebody remembers reading. See titles.py.
rows = get_db().execute(
"SELECT title FROM threads WHERE title LIKE ?",
(titles.UNTITLED + "%",)).fetchall()
title = titles.next_untitled(row["title"] for row in rows)
return title, body return title, body

View File

@ -30,7 +30,7 @@ import yaml
from flask import (Blueprint, abort, current_app, flash, g, redirect, from flask import (Blueprint, abort, current_app, flash, g, redirect,
render_template, request, url_for) render_template, request, url_for)
from . import gitea from . import gitea, titles
from .db import get_db from .db import get_db
from .render import to_html from .render import to_html
from .security import is_at_least, moderator_required from .security import is_at_least, moderator_required
@ -99,6 +99,34 @@ def filename_for(collection: str, title: str, when: date_type | None) -> str:
return f"{slug}.es.md" return f"{slug}.es.md"
def untitled_for(collection: str, when, skip: str = "") -> str:
"""A name for a post nobody titled, free in the folder it is going into.
Numbered against the *filenames* rather than against the titles, because in
a repository the filename is what collides: two «Sin Título» posts on one
day would both be `<fecha>-sin-titulo.es.md`, and the second would come back
as "somebody else saved this file while you were editing it" — a message
about a conflict that never happened.
A git server that cannot be reached gives the plain name. Publishing fails
in that case anyway, and the failure should say what it is rather than be a
naming error wearing its coat.
"""
try:
names = {entry["name"] for entry in gitea.list_directory(
COLLECTIONS[collection]["folder"], gitea.content_token())}
except gitea.GiteaError:
return titles.UNTITLED
names.discard(skip) # editing a post does not collide with itself
number = 1
while True:
title = titles.UNTITLED if number == 1 else f"{titles.UNTITLED} {number}"
if filename_for(collection, title, when) not in names:
return title
number += 1
def split_frontmatter(text: str) -> tuple[dict, str]: def split_frontmatter(text: str) -> tuple[dict, str]:
match = re.match(r"\A---\n(.*?)\n---\n?(.*)\Z", text, re.DOTALL) match = re.match(r"\A---\n(.*?)\n---\n?(.*)\Z", text, re.DOTALL)
if not match: if not match:
@ -319,8 +347,8 @@ def _read_form(collection: str) -> tuple[dict, str, list[str]]:
errors.append("La imagen no es válida.") errors.append("La imagen no es válida.")
image = "" image = ""
if not title: # A title is not required. An untitled post is named when it is saved, by
errors.append("El título no puede estar vacío.") # untitled_for() — see titles.py for why the form does not insist.
if not body: if not body:
errors.append("El cuerpo no puede estar vacío.") errors.append("El cuerpo no puede estar vacío.")
@ -487,6 +515,8 @@ def publish(collection: str, fields: dict, body: str, author) -> str:
approved submission keeps the member's name in git history. approved submission keeps the member's name in git history.
""" """
fields = dict(fields, **byline(author)) fields = dict(fields, **byline(author))
if not fields.get("title"):
fields["title"] = untitled_for(collection, fields["date"])
name = filename_for(collection, fields["title"], fields["date"]) name = filename_for(collection, fields["title"], fields["date"])
path = f"{COLLECTIONS[collection]['folder']}/{name}" path = f"{COLLECTIONS[collection]['folder']}/{name}"
document = build_document(frontmatter_for(collection, fields), body) document = build_document(frontmatter_for(collection, fields), body)
@ -601,6 +631,11 @@ def edit(collection: str, name: str):
fields["image"] = picture fields["image"] = picture
# Deliberately not through publish(): that stamps the byline of whoever # Deliberately not through publish(): that stamps the byline of whoever
# is publishing, and an edit keeps the author the file already names. # is publishing, and an edit keeps the author the file already names.
if not fields.get("title"):
# `skip` is this post's own file: a title cleared on an edit must
# not count the thing being edited as the collision it has to
# avoid, or every save would walk the number up by one.
fields["title"] = untitled_for(collection, fields["date"], skip=name)
document = build_document(frontmatter_for(collection, fields), body) document = build_document(frontmatter_for(collection, fields), body)
gitea.write_file(path, document.encode("utf-8"), gitea.write_file(path, document.encode("utf-8"),
f"content: actualizar «{fields['title']}»", f"content: actualizar «{fields['title']}»",

View File

@ -249,6 +249,23 @@ textarea { resize: vertical; line-height: 1.55; }
} }
.btn:hover { background: var(--brand-dark); } .btn:hover { background: var(--brand-dark); }
/* The second button in a row of them — Cancelar, mostly. It was a link, which
made leaving look like a footnote next to a filled pill; it is the other
half of a decision and should be the same size and shape as the half beside
it. Quiet rather than loud: same geometry, no fill, so the eye still knows
which one publishes. */
.btn--quiet {
background: var(--surface);
color: var(--muted);
border: 1px solid var(--border);
padding: calc(0.6rem - 1px) calc(1.4rem - 1px); /* the border, given back */
}
.btn--quiet:hover {
background: var(--surface-soft);
color: var(--text);
border-color: var(--brand);
}
/* A button sitting straight in a card, rather than in an .actions row, still /* A button sitting straight in a card, rather than in an .actions row, still
* needs air above it. Five of them did not have any — the one under the "escribir * needs air above it. Five of them did not have any — the one under the "escribir
* a" picker was flush against the select — because the space every other form * a" picker was flush against the select — because the space every other form
@ -382,6 +399,33 @@ textarea { resize: vertical; line-height: 1.55; }
.fieldset legend { padding: 0 0.4rem; font-weight: 600; font-size: 0.9rem; } .fieldset legend { padding: 0 0.4rem; font-weight: 600; font-size: 0.9rem; }
.fieldset .check { margin: 0.35rem 0; } .fieldset .check { margin: 0.35rem 0; }
/* The same box, folded shut. Most posts are not events, and three date
pickers between the title and the text are three fields most people scroll
past — the form should ask what it needs and keep the rest within reach
rather than in the way. A <details>, like the account menu: no script, and
it opens by itself when the post already has a date. */
.fold {
border: 1px solid var(--border-light);
border-radius: var(--radius-md);
padding: 0 1rem;
margin: 1rem 0 0;
background: var(--surface);
}
.fold > summary {
cursor: pointer;
padding: 0.8rem 0;
font-weight: 600;
font-size: 0.9rem;
color: var(--muted);
}
.fold > summary:hover { color: var(--brand-dark); }
.fold[open] > summary {
color: var(--text);
border-bottom: 1px solid var(--border-light);
margin-bottom: 0.75rem;
}
.fold > :last-child { margin-bottom: 1rem; }
input[type="file"] { input[type="file"] {
width: 100%; width: 100%;
padding: 0.5rem 0; padding: 0.5rem 0;
@ -1021,8 +1065,10 @@ input[type="file"] {
/* The disclosure switch: 16px of words and a 13px box before this. The /* The disclosure switch: 16px of words and a 13px box before this. The
checkbox itself grows too — a label you can hit around a box you checkbox itself grows too — a label you can hit around a box you
cannot is a control that looks broken when it misses. */ cannot is a control that looks broken when it misses. */
.switch { padding: 0.7rem 0; } /* The switch and its words, which were 16px of line box before this. The
.switch input { width: 20px; height: 20px; } track is already 22px tall and does not need to grow — the label around
it does, so the whole thing is one target. */
.toggle { padding: 0.65rem 0; }
.cal__add { .cal__add {
display: inline-flex; display: inline-flex;
@ -1045,16 +1091,67 @@ input[type="file"] {
border: 1px solid var(--border-light); border: 1px solid var(--border-light);
} }
/* The switch in the form's action row. A checkbox and its words on one line, /* A real switch rather than a checkbox, because what it says is not a detail
beside the button that publishes — visible at the moment of publishing, * of the form — it is a statement about the text, made at the moment of
which is when it is answered, and costing one line rather than a fieldset. */ * publishing, and it should look like something that is on or off.
.switch { *
* Drawn entirely from the checkbox's own `:checked` state. There is no script
* anywhere near it: under a policy with no 'unsafe-inline' a control that
* needs one is a control that silently does nothing. The input is visually
* hidden but not `display: none` — it keeps its place in the tab order and is
* still announced with its label, so the switch works from a keyboard.
*/
.toggle {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
gap: 0.45rem; gap: 0.55rem;
font-size: 0.9rem; font-size: 0.9rem;
color: var(--muted); color: var(--muted);
cursor: pointer; cursor: pointer;
/* So the hidden input below is positioned against this label and not
against whatever happens to be the nearest positioned ancestor — a 1px
invisible control adrift somewhere else on the page is a thing that gets
clicked by accident exactly once and is never explained. */
position: relative;
}
.toggle input {
position: absolute;
top: 0;
left: 0;
width: 1px;
height: 1px;
opacity: 0;
}
.toggle__track {
position: relative;
flex: none;
width: 40px;
height: 22px;
border-radius: 999px;
background: var(--border);
transition: background 140ms ease;
}
.toggle__track::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 16px;
height: 16px;
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
transition: transform 140ms ease;
}
.toggle input:checked + .toggle__track { background: var(--brand); }
.toggle input:checked + .toggle__track::after { transform: translateX(18px); }
/* Focus has to land somewhere visible: the thing with the outline is hidden. */
.toggle input:focus-visible + .toggle__track {
outline: 2px solid var(--brand-dark);
outline-offset: 2px;
}
.toggle input:checked ~ .toggle__text { color: var(--brand-dark); font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
.toggle__track, .toggle__track::after { transition: none; }
} }
.switch input { margin: 0; }
.switch:has(input:checked) { color: var(--brand-dark); font-weight: 600; }

View File

@ -30,7 +30,7 @@ from datetime import date as date_type
from flask import (Blueprint, abort, current_app, flash, g, redirect, from flask import (Blueprint, abort, current_app, flash, g, redirect,
render_template, request, send_from_directory, url_for) render_template, request, send_from_directory, url_for)
from . import activity, content, gitea, uploads from . import activity, content, gitea, titles, uploads
from .db import get_db from .db import get_db
from .render import excerpt, to_html from .render import excerpt, to_html
from .security import is_at_least, login_required, moderator_required from .security import is_at_least, login_required, moderator_required
@ -107,7 +107,12 @@ def _read_proposal() -> tuple[dict, list[str]]:
**content.read_event_fields(request.form, errors), **content.read_event_fields(request.form, errors),
} }
if not fields["title"]: if not fields["title"]:
errors.append("El título no puede estar vacío.") # Not an error: a proposal without a headline is named when it is sent,
# the same way a thread is. See titles.py.
rows = get_db().execute(
"SELECT title FROM submissions WHERE title LIKE ?",
(titles.UNTITLED + "%",)).fetchall()
fields["title"] = titles.next_untitled(row["title"] for row in rows)
if not fields["body"]: if not fields["body"]:
errors.append("El texto no puede estar vacío.") errors.append("El texto no puede estar vacío.")
return fields, errors return fields, errors

View File

@ -16,7 +16,7 @@
<div class="actions"> <div class="actions">
<button class="btn" type="submit">Guardar</button> <button class="btn" type="submit">Guardar</button>
<a class="linkish" href="{{ url_for('board.thread', thread_id=comment.thread_id) }}">Cancelar</a> <a class="btn btn--quiet" href="{{ url_for('board.thread', thread_id=comment.thread_id) }}">Cancelar</a>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -30,7 +30,7 @@
<h1>{{ ('Editar ' ~ meta.singular|lower) if item else meta.new_label }}</h1> <h1>{{ ('Editar ' ~ meta.singular|lower) if item else meta.new_label }}</h1>
<label for="title">Título</label> <label for="title">Título</label>
<input id="title" name="title" maxlength="140" required value="{{ f.title or '' }}"> <input id="title" name="title" maxlength="140" value="{{ f.title or '' }}">
{% if meta.dated %} {% if meta.dated %}
<label for="date">Fecha</label> <label for="date">Fecha</label>
@ -69,8 +69,12 @@
{# An event's own date, which is not the day the post goes up. The date is {# An event's own date, which is not the day the post goes up. The date is
also what makes this post an event: there is nothing to tick first, so also what makes this post an event: there is nothing to tick first, so
there is no way to say "this is an event" and then not say when. #} there is no way to say "this is an event" and then not say when. #}
<fieldset class="fieldset"> {#- A fold rather than a fieldset: most posts are not events, and six
<legend>Si es un evento</legend> inches of date pickers between the title and the text is six inches
most people scroll past. Open by itself when the post already has a
date, so editing an event does not hide the thing being edited. -#}
<details class="fold" {{ 'open' if f.event_date }}>
<summary>Si es un evento <span class="muted small">(fecha, hora, lugar)</span></summary>
<p class="muted small"> <p class="muted small">
Pon la fecha y será un evento: aparecerá en la agenda del sitio, con el Pon la fecha y será un evento: aparecerá en la agenda del sitio, con el
día y el lugar destacados, y se podrá añadir al calendario del móvil. día y el lugar destacados, y se podrá añadir al calendario del móvil.
@ -88,7 +92,7 @@
<input id="event_location" name="event_location" maxlength="200" <input id="event_location" name="event_location" maxlength="200"
value="{{ f.event_location or '' }}"> value="{{ f.event_location or '' }}">
<p class="muted small">Dónde es: el sitio, la calle, el barrio.</p> <p class="muted small">Dónde es: el sitio, la calle, el barrio.</p>
</fieldset> </details>
<label for="description">Resumen</label> <label for="description">Resumen</label>
<textarea id="description" name="description" rows="2">{{ f.description or '' }}</textarea> <textarea id="description" name="description" rows="2">{{ f.description or '' }}</textarea>
@ -141,16 +145,22 @@
{#- Beside the button that publishes, because that is the moment it is {#- Beside the button that publishes, because that is the moment it is
answered. One line rather than a fieldset: it has to be seen, not answered. One line rather than a fieldset: it has to be seen, not
to take up the form. -#} to take up the form. -#}
<label class="switch"> <label class="toggle">
<input type="checkbox" name="ai_generated" {{ 'checked' if f.ai_generated }}> <input type="checkbox" name="ai_generated" {{ 'checked' if f.ai_generated }}>
Contenido generado con IA {#- The switch itself is drawn by board.css from the checkbox's own
state. No script: a control that needs one is a control that
does nothing under this Content-Security-Policy. -#}
<span class="toggle__track" aria-hidden="true"></span>
<span class="toggle__text">Contenido generado con IA</span>
</label> </label>
<button class="linkish" type="submit" {#- Beside Cancelar and shaped like it: both are things you press in this
row, and a bare link wedged between two buttons reads as unfinished. -#}
<button class="btn btn--quiet" type="submit"
formaction="{{ url_for('content.preview', collection=collection) }}"> formaction="{{ url_for('content.preview', collection=collection) }}">
Vista previa Vista previa
</button> </button>
<a class="linkish" href="{{ url_for('content.index', collection=collection) }}">Cancelar</a> <a class="btn btn--quiet" href="{{ url_for('content.index', collection=collection) }}">Cancelar</a>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -49,7 +49,7 @@
<div class="actions"> <div class="actions">
<button class="btn" type="submit">Guardar</button> <button class="btn" type="submit">Guardar</button>
<a class="linkish" href="{{ url_for('events.month') }}">Cancelar</a> <a class="btn btn--quiet" href="{{ url_for('events.month') }}">Cancelar</a>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -43,7 +43,7 @@
<div class="actions"> <div class="actions">
<button class="btn" type="submit">Dar de alta</button> <button class="btn" type="submit">Dar de alta</button>
<a class="linkish" href="{{ url_for('members.index') }}">Cancelar</a> <a class="btn btn--quiet" href="{{ url_for('members.index') }}">Cancelar</a>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -41,7 +41,7 @@
<div class="actions"> <div class="actions">
<button class="btn" type="submit">Enviar enlace</button> <button class="btn" type="submit">Enviar enlace</button>
<a class="linkish" href="{{ url_for('auth.login') }}">Cancelar</a> <a class="btn btn--quiet" href="{{ url_for('auth.login') }}">Cancelar</a>
</div> </div>
</form> </form>
{% endif %} {% endif %}

View File

@ -16,7 +16,7 @@
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<label for="title">Título</label> <label for="title">Título</label>
<input id="title" name="title" type="text" required maxlength="140" <input id="title" name="title" type="text" maxlength="140"
value="{{ fields.title if fields else '' }}"> value="{{ fields.title if fields else '' }}">
<label for="description">Resumen <span class="muted small">(opcional)</span></label> <label for="description">Resumen <span class="muted small">(opcional)</span></label>
@ -27,8 +27,12 @@
{# An event's own date, which is not the day the post goes up. The date is {# An event's own date, which is not the day the post goes up. The date is
also what makes this an event: there is nothing to tick first, so there is also what makes this an event: there is nothing to tick first, so there is
no way to say "this is an event" and then not say when. #} no way to say "this is an event" and then not say when. #}
<fieldset class="fieldset"> {#- A fold rather than a fieldset: most posts are not events, and six
<legend>Si es un evento</legend> inches of date pickers between the title and the text is six inches
most people scroll past. Open by itself when the post already has a
date, so editing an event does not hide the thing being edited. -#}
<details class="fold" {{ 'open' if fields.event_date }}>
<summary>Si es un evento <span class="muted small">(fecha, hora, lugar)</span></summary>
<p class="muted small"> <p class="muted small">
Pon la fecha y será un evento: aparecerá en la agenda del sitio, con el Pon la fecha y será un evento: aparecerá en la agenda del sitio, con el
día y el lugar destacados. Déjala vacía y es un artículo normal. día y el lugar destacados. Déjala vacía y es un artículo normal.
@ -45,7 +49,7 @@
<input id="event_location" name="event_location" maxlength="200" <input id="event_location" name="event_location" maxlength="200"
value="{{ fields.event_location or '' }}"> value="{{ fields.event_location or '' }}">
<p class="muted small">Dónde es: el sitio, la calle, el barrio.</p> <p class="muted small">Dónde es: el sitio, la calle, el barrio.</p>
</fieldset> </details>
<label for="body">Texto</label> <label for="body">Texto</label>
<textarea id="body" data-markdown data-rich="full" name="body" rows="16" required <textarea id="body" data-markdown data-rich="full" name="body" rows="16" required
@ -69,12 +73,16 @@
{#- Beside the button that publishes, because that is the moment it is {#- Beside the button that publishes, because that is the moment it is
answered. One line rather than a fieldset: it has to be seen, not answered. One line rather than a fieldset: it has to be seen, not
to take up the form. -#} to take up the form. -#}
<label class="switch"> <label class="toggle">
<input type="checkbox" name="ai_generated" {{ 'checked' if (fields.ai_generated if fields else False) }}> <input type="checkbox" name="ai_generated" {{ 'checked' if (fields.ai_generated if fields else False) }}>
Contenido generado con IA {#- The switch itself is drawn by board.css from the checkbox's own
state. No script: a control that needs one is a control that
does nothing under this Content-Security-Policy. -#}
<span class="toggle__track" aria-hidden="true"></span>
<span class="toggle__text">Contenido generado con IA</span>
</label> </label>
<a class="linkish" href="{{ url_for('submissions.index') }}">Cancelar</a> <a class="btn btn--quiet" href="{{ url_for('submissions.index') }}">Cancelar</a>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -8,7 +8,7 @@
<h1>{{ 'Editar tema' if thread else 'Nuevo tema' }}</h1> <h1>{{ 'Editar tema' if thread else 'Nuevo tema' }}</h1>
<label for="title">Título</label> <label for="title">Título</label>
<input id="title" name="title" maxlength="140" required <input id="title" name="title" maxlength="140"
value="{{ thread.title if thread else '' }}"> value="{{ thread.title if thread else '' }}">
<label for="body">Mensaje</label> <label for="body">Mensaje</label>
@ -33,12 +33,16 @@
{#- Beside the button that publishes, because that is the moment it is {#- Beside the button that publishes, because that is the moment it is
answered. One line rather than a fieldset: it has to be seen, not answered. One line rather than a fieldset: it has to be seen, not
to take up the form. -#} to take up the form. -#}
<label class="switch"> <label class="toggle">
<input type="checkbox" name="ai_generated" {{ 'checked' if (thread.ai_generated if thread else False) }}> <input type="checkbox" name="ai_generated" {{ 'checked' if (thread.ai_generated if thread else False) }}>
Contenido generado con IA {#- The switch itself is drawn by board.css from the checkbox's own
state. No script: a control that needs one is a control that
does nothing under this Content-Security-Policy. -#}
<span class="toggle__track" aria-hidden="true"></span>
<span class="toggle__text">Contenido generado con IA</span>
</label> </label>
<a class="linkish" href="{{ url_for('board.thread', thread_id=thread.id) if thread else url_for('board.threads') }}">Cancelar</a> <a class="btn btn--quiet" href="{{ url_for('board.thread', thread_id=thread.id) if thread else url_for('board.threads') }}">Cancelar</a>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -183,3 +183,62 @@ def test_editing_a_thread_can_add_or_remove_the_disclosure(client, post, make_me
post("/comunidad/tema/1/editar", {"title": "Resumen", "body": "Otra vez con ayuda.", post("/comunidad/tema/1/editar", {"title": "Resumen", "body": "Otra vez con ayuda.",
"ai_generated": "on"}) "ai_generated": "on"})
assert "Generado con IA" in client.get("/comunidad/tema/1").get_data(as_text=True) assert "Generado con IA" in client.get("/comunidad/tema/1").get_data(as_text=True)
# --- a post nobody titled -------------------------------------------------
def test_a_thread_with_no_title_gets_one(client, post, make_member, sign_in):
"""Asking for a headline before a sentence is how a form stops somebody
writing. The ones people leave blank are often the best writing on a
wall — somebody answering a question, somebody saying a thing happened."""
sign_in(make_member("maria"))
post("/comunidad/nuevo", {"title": "", "body": "Ya está arreglado, gracias."})
page = client.get("/comunidad/tema/1").get_data(as_text=True)
assert "Sin Título" in page
assert "Ya está arreglado" in page
def test_untitled_threads_are_numbered_so_they_can_be_told_apart(
client, post, make_member, sign_in):
sign_in(make_member("maria"))
post("/comunidad/nuevo", {"title": "", "body": "Uno."})
post("/comunidad/nuevo", {"title": "", "body": "Dos."})
post("/comunidad/nuevo", {"title": "Con título", "body": "Tres."})
post("/comunidad/nuevo", {"title": "", "body": "Cuatro."})
wall = client.get("/comunidad/muro").get_data(as_text=True)
for expected in ("Sin Título", "Sin Título 2", "Sin Título 3"):
assert expected in wall
assert "Sin Título 4" not in wall
def test_a_deleted_untitled_thread_does_not_give_its_number_back(
client, post, db, make_member, sign_in):
"""A number that comes back is a thread that looks like one somebody
remembers reading. The soft-deleted row keeps its title, and counting it
is what prevents that."""
sign_in(make_member("maria"))
post("/comunidad/nuevo", {"title": "", "body": "Uno."})
post("/comunidad/nuevo", {"title": "", "body": "Dos."})
post("/comunidad/tema/2/eliminar")
post("/comunidad/nuevo", {"title": "", "body": "Tres."})
titles = [row["title"] for row in db.execute("SELECT title FROM threads ORDER BY id")]
assert titles == ["Sin Título", "Sin Título 2", "Sin Título 3"]
def test_a_title_that_only_looks_numbered_is_left_alone(client, post, db,
make_member, sign_in):
sign_in(make_member("maria"))
post("/comunidad/nuevo", {"title": "Sin Título ni ganas", "body": "Uno."})
post("/comunidad/nuevo", {"title": "", "body": "Dos."})
titles = [row["title"] for row in db.execute("SELECT title FROM threads ORDER BY id")]
assert titles == ["Sin Título ni ganas", "Sin Título"]
def test_a_thread_still_needs_something_to_say(client, post, make_member, sign_in):
"""The title is optional; the message is the post."""
sign_in(make_member("maria"))
post("/comunidad/nuevo", {"title": "Solo el título", "body": " "})
assert client.get("/comunidad/tema/1").status_code == 404

View File

@ -698,3 +698,63 @@ def test_the_disclosure_is_not_one_of_the_keys_translation_rewrites(repo, editor
fm, _ = translate.split_frontmatter(repo.files[path].decode()) fm, _ = translate.split_frontmatter(repo.files[path].decode())
assert fm["ai_generated"] is True assert fm["ai_generated"] is True
assert "ai_generated" not in translate.TRANSLATED_KEYS assert "ai_generated" not in translate.TRANSLATED_KEYS
# --- a post nobody titled -------------------------------------------------
def test_an_untitled_post_is_named_when_it_is_published(repo, editor, post):
publish(post, title="")
path, = repo.files
assert path == "content/post/2026-09-25-sin-titulo.es.md"
fm, _ = translate.split_frontmatter(repo.files[path].decode())
assert fm["title"] == "Sin Título"
def test_two_untitled_posts_on_one_day_do_not_collide(repo, editor, post):
"""The filename is what collides in a repository, not the title: both
would be `<fecha>-sin-titulo.es.md`, and the second would come back as
"somebody else saved this file while you were editing it" — a message
about a conflict that never happened. So the numbering is done against
the names already in the folder."""
publish(post, title="")
publish(post, title="")
assert sorted(repo.files) == [
"content/post/2026-09-25-sin-titulo-2.es.md",
"content/post/2026-09-25-sin-titulo.es.md",
]
fm, _ = translate.split_frontmatter(
repo.files["content/post/2026-09-25-sin-titulo-2.es.md"].decode())
assert fm["title"] == "Sin Título 2"
def test_the_same_name_is_free_again_on_another_day(repo, editor, post):
"""A dated collection only collides within its own day, so the number
starts over rather than counting up forever."""
publish(post, title="", date="2026-09-25")
publish(post, title="", date="2026-10-25")
assert sorted(repo.files) == [
"content/post/2026-09-25-sin-titulo.es.md",
"content/post/2026-10-25-sin-titulo.es.md",
]
def test_clearing_the_title_on_an_edit_does_not_walk_the_number_up(
repo, editor, post):
"""The post being edited must not count as the collision it has to avoid,
or every save would rename it one higher."""
publish(post, title="")
path, = repo.files
name = path.rsplit("/", 1)[1]
for _ in range(3):
post(f"/comunidad/contenido/post/editar/{name}",
{"title": "", "body": "Otra corrección.", "date": "2026-09-25",
"sha": repo._sha(repo.files[path])})
fm, _ = translate.split_frontmatter(repo.files[path].decode())
assert fm["title"] == "Sin Título"
assert list(repo.files) == [path]
def test_a_post_still_needs_a_body(repo, editor, post):
response = publish(post, title="", body="")
assert not repo.files
assert "cuerpo no puede estar vacío" in response.get_data(as_text=True)

View File

@ -553,3 +553,19 @@ def test_the_moderator_can_see_what_they_are_approving(client, db, post, maria,
sign_in(luisa) sign_in(luisa)
page = client.get(f"/comunidad/publicaciones/{submission_id}").get_data(as_text=True) page = client.get(f"/comunidad/publicaciones/{submission_id}").get_data(as_text=True)
assert "IA" in page assert "IA" in page
def test_an_untitled_proposal_is_named_rather_than_refused(db, post, maria, sign_in):
"""Same rule as the wall: the text is the post, the headline is optional."""
sign_in(maria)
propose(post, title="")
assert only_submission(db)["title"] == "Sin Título"
def test_untitled_proposals_are_numbered(db, post, maria, sign_in):
sign_in(maria)
propose(post, title="")
propose(post, title="")
rows = [row["title"] for row in
db.execute("SELECT title FROM submissions ORDER BY id")]
assert rows == ["Sin Título", "Sin Título 2"]

46
apps/board/titles.py Normal file
View File

@ -0,0 +1,46 @@
"""The name a post gets when nobody gives it one.
A title is not required anywhere a member writes. Most things people post have
one, and the ones that do not are usually the best writing on a wall: somebody
answering a question, somebody saying a thing happened. Demanding a headline
first is how a form stops a person mid-sentence.
So an untitled post is called «Sin Título», and the second one is «Sin Título
2». The number is there to keep them apart — in a list of twenty threads, three
rows reading the same four characters are three rows nobody can tell apart or
link to with any confidence.
Numbers are never reused. A deleted thread keeps its title in the database, and
counting it is what stops a new post inheriting the name of one somebody
remembers reading.
"""
from __future__ import annotations
import re
from typing import Iterable
UNTITLED = "Sin Título"
# «Sin Título», «Sin Título 2». Anchored, so a post somebody deliberately
# called «Sin Título ni ganas» is not read as a number and does not take one.
NUMBERED = re.compile(r"^Sin Título(?:\s+(\d+))?$")
def next_untitled(taken: Iterable[str]) -> str:
"""The first «Sin Título» name not in `taken`.
`taken` is every title already in that place — the wall's threads, the
queue's proposals — including deleted ones, because a number that comes
back is a post that looks like a different post.
"""
used = set()
for title in taken:
match = NUMBERED.match((title or "").strip())
if match:
used.add(int(match.group(1) or 1))
number = 1
while number in used:
number += 1
return UNTITLED if number == 1 else f"{UNTITLED} {number}"

View File

@ -39,6 +39,51 @@ Check propagation (repeat until it prints the server IP):
local$ dig +short git.vienalatina.com local$ dig +short git.vienalatina.com
``` ```
### 1.1 A second domain that leads here
`vielac.at` is the second name, and it redirects: everything that arrives goes
to the same path on vienalatina.com. Two A records in that domain's **zone
editor**, both at the server:
| Name | Type | Value | TTL |
|---|---|---|---|
| `@` | A | `<SERVER-IP>` | 300 |
| `www` | A | `<SERVER-IP>` | 300 |
**Not the nameserver page.** On Hetzner's Konsole H those fields hand the whole
zone to another provider's DNS, which is a different thing entirely and turns
off the zone editor you want. *Standard Nameserver eintragen*, save, then edit
the zone.
Then the block in `infra/caddy/Caddyfile`, which carries both spellings and
answers with a **301** — a permanent redirect is what folds the two names into
one site for a search engine rather than two copies of it, and `{uri}` keeps
the path so a shared link still lands where it was pointing.
**Order matters, and it is the same order as the cutover above**: the A records
go in first, because Caddy asks Let's Encrypt for the certificate the first time
the name resolves to this server. A reload before DNS has propagated is not
harmful — nothing reaches the block — but it does not get a certificate either,
so reload again afterwards.
```sh
sudo cp ~/vienalatina/infra/caddy/Caddyfile /etc/caddy/Caddyfile
sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy
```
`validate` before every `reload`, without exception: it is the one command
between a typo in that file and vienalatina.com going down with it.
```sh
curl -sI https://vielac.at/ | head -3 # 301 → vienalatina.com
curl -sI https://www.vielac.at/page/agenda/ | grep -i location # the path survives
curl -sI https://vienalatina.com/ | head -1 # 200, unchanged
```
The third is the one that matters. A Caddyfile edit that breaks the site it was
meant to leave alone is the failure this ordering exists to prevent.
## 2. First login + basic hardening ## 2. First login + basic hardening
```sh ```sh
@ -1080,9 +1125,34 @@ Choosing a picture shows a thumbnail with its name and size before anything is
uploaded. That is the one reason `blob:` is in the `img-src` policy — a handle to uploaded. That is the one reason `blob:` is in the `img-src` policy — a handle to
bytes already in the page, which reaches no network. bytes already in the page, which reaches no network.
### 11.17a A title is optional
Nowhere a member writes insists on a headline — not the wall, not a proposal,
not the editor. The ones people leave blank are often the best writing on a
wall: somebody answering a question, somebody saying a thing happened. Asking
for a title first is how a form stops a person mid-sentence, and the field says
nothing about being optional, because a field labelled *(opcional)* is a field
asking to be filled in.
An untitled post is called **Sin Título**, and the next one **Sin Título 2**.
`apps/board/titles.py` holds the rule; the numbering is done per place, against
what is already there:
| Where | Numbered against |
|---|---|
| The wall, the queue | Every title in that table, **including deleted rows** — a number that comes back is a thread that looks like one somebody remembers reading |
| A public post | The **filenames** in the folder, not the titles: two untitled posts on one day would both be `<fecha>-sin-titulo.es.md`, and the second would fail as "somebody else saved this file while you were editing it" — a message about a conflict that never happened |
A post deliberately called «Sin Título ni ganas» is left alone: the pattern is
anchored, so it is not read as a number and does not take one. Editing a post
and clearing its title does not walk the number up either — the file being
edited is excluded from its own collision check.
### 11.17b «Contenido generado con IA» ### 11.17b «Contenido generado con IA»
A switch beside the button that publishes, on the three boxes that hold a post: A real switch — drawn by `board.css` from the checkbox's own `:checked` state,
with no script anywhere near it — beside the button that publishes, on the
three boxes that hold a post:
the editor, a member's proposal and a wall thread. Where the post is read it is the editor, a member's proposal and a wall thread. Where the post is read it is
a pill next to the date — on the article, on the cards in the listings, on the a pill next to the date — on the article, on the cards in the listings, on the
thread and in the wall's list — because a disclosure somebody meets after thread and in the wall's list — because a disclosure somebody meets after

View File

@ -21,6 +21,22 @@ www.vienalatina.com {
redir https://vienalatina.com{uri} 301 redir https://vienalatina.com{uri} 301
} }
# The second name, which leads here rather than somewhere else.
#
# Both spellings in one block, and 301 rather than 302: a permanent redirect is
# what makes a search engine fold the two names into one site instead of
# indexing them as duplicates of each other, and what makes a browser stop
# asking after the first visit. `{uri}` carries the path, so a link somebody
# shared to vielac.at/page/agenda/ lands on the agenda rather than on the home
# page.
#
# Caddy asks Let's Encrypt for this certificate the first time the name
# resolves to this server, so the A records go in before this file is reloaded.
# Until they do, the block is harmless: nothing reaches it.
vielac.at, www.vielac.at {
redir https://vienalatina.com{uri} 301
}
vienalatina.com { vienalatina.com {
root * /var/www/vienalatina.com root * /var/www/vienalatina.com
encode zstd gzip encode zstd gzip