From 071ba031a1cdeae2e2bc5943b3a634d99b1be458 Mon Sep 17 00:00:00 2001 From: adevopg Date: Sun, 12 Jul 2026 17:25:53 +0000 Subject: [PATCH] Foro: ocultar contador de visitas cuando la columna no existe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - corrige que se mostrara '1 visitas' sin la columna forum_topics.views: el incremento y la visualización solo ocurren si has_views_column() es true Co-Authored-By: Claude Opus 4.8 (1M context) --- forum/templates/forum/forum.html | 2 +- forum/templates/forum/topic.html | 2 +- forum/views.py | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/forum/templates/forum/forum.html b/forum/templates/forum/forum.html index 1674cc8..f78ecd4 100644 --- a/forum/templates/forum/forum.html +++ b/forum/templates/forum/forum.html @@ -32,7 +32,7 @@
por {{ topic.display_poster }} · {{ topic.created }}
-
{{ topic.post_count }} respuestas · {{ topic.views }} vistas
+
{{ topic.post_count }} respuestas{% if has_views %} · {{ topic.views }} vistas{% endif %}
{% if topic.last_poster %}
último: {{ topic.last_poster }}
{% endif %} {% if topic.last_time %}
{{ topic.last_time }}
{% endif %}
diff --git a/forum/templates/forum/topic.html b/forum/templates/forum/topic.html index 6ead61a..76de7c1 100644 --- a/forum/templates/forum/topic.html +++ b/forum/templates/forum/topic.html @@ -14,7 +14,7 @@
{% if forum %}← {{ forum.name }}{% endif %} - {{ topic.views }} visitas + {% if topic.has_views %}{{ topic.views }} visitas{% endif %} {% if topic.locked %}Tema bloqueado{% endif %}
diff --git a/forum/views.py b/forum/views.py index 9819be7..2a7efce 100644 --- a/forum/views.py +++ b/forum/views.py @@ -82,6 +82,7 @@ def view_forum(request, forum_id, page=1): 'forum': forum, 'topics': topics, 'pagination': pag, + 'has_views': db.has_views_column(), })) @@ -114,10 +115,13 @@ def view_topic(request, topic_id, page=1): forum = db.get_forum(topic['forum_id'], include_hidden=True) - # Contador de visitas (si la columna existe) - db.increment_views(topic_id) - if topic.get('views') is not None: - topic['views'] = topic['views'] + 1 + # Contador de visitas (solo si la columna existe) + if db.has_views_column(): + db.increment_views(topic_id) + topic['views'] = (topic.get('views') or 0) + 1 + topic['has_views'] = True + else: + topic['has_views'] = False total = db.count_posts(topic_id) pag, offset = _paginate(total, page, settings.FORUM_POSTS_PER_PAGE)