Foro: buscador de temas y nombre de autor legible

- forum_search: busca temas por título y contenido (foros visibles)
- db.get_display_name: nombre visible del autor = parte local del email de la cuenta
  (en vez de <bnetId>#1), usado en el panel de posts y la lista de temas
- buscador en la portada del foro + plantilla search.html
- docs/FORO.md actualizado

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-12 17:18:34 +00:00
parent 874a0c1ad9
commit fd49d6cd96
8 changed files with 125 additions and 5 deletions
+46 -1
View File
@@ -231,9 +231,11 @@ def get_author_info(poster_id):
Datos del autor para mostrar en los posts: nivel GM, fecha de registro y
nº de mensajes. Cruza acore_auth (account/account_access) y acore_web.
"""
info = {'gmlevel': 0, 'joindate': None, 'post_count': 0, 'status': 'Miembro'}
info = {'gmlevel': 0, 'joindate': None, 'post_count': 0, 'status': 'Miembro',
'display_name': None}
if not poster_id:
return info
info['display_name'] = get_display_name(poster_id)
try:
with connections['acore_auth'].cursor() as cursor:
cursor.execute("SELECT MAX(gmlevel) FROM account_access WHERE id = %s", [poster_id])
@@ -308,6 +310,49 @@ def mark_read(user_id, topic_id):
)
def get_display_name(poster_id):
"""
Nombre legible del autor a partir de su cuenta: parte local del email
(antes de la @). Si no hay email, devuelve None (la plantilla usa el poster).
"""
if not poster_id:
return None
try:
with connections['acore_auth'].cursor() as cursor:
cursor.execute(
"SELECT email, reg_mail FROM account WHERE id = %s", [poster_id]
)
row = cursor.fetchone()
except Exception:
return None
if not row:
return None
email = (row[0] or row[1] or '').strip()
if '@' in email:
return email.split('@', 1)[0]
return None
def search_topics(query, limit=50):
"""Busca temas por título o por contenido de sus posts (foros visibles)."""
like = f"%{query}%"
with _conn().cursor() as cursor:
cursor.execute(
"""
SELECT DISTINCT t.id, t.name, t.poster, t.poster_id, t.forum_id,
t.created, f.name AS forum_name
FROM forum_topics t
JOIN forums f ON f.id = t.forum_id AND f.visibility = 1 AND f.deleted = 0
LEFT JOIN forum_posts p ON p.topic_id = t.id AND p.deleted = 0
WHERE t.deleted = 0 AND (t.name LIKE %s OR p.text LIKE %s)
ORDER BY t.updated_at DESC
LIMIT %s
""",
[like, like, limit],
)
return _dictfetchall(cursor)
def list_forums_for_move(exclude_forum_id=None):
"""Lista de foros visibles para el desplegable de 'mover tema'."""
with _conn().cursor() as cursor: