Foro: ocultar contador de visitas cuando la columna no existe

- 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) <noreply@anthropic.com>
This commit is contained in:
2026-07-12 17:25:53 +00:00
parent eb93758c43
commit 071ba031a1
3 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -32,7 +32,7 @@
<div class="desc">por {{ topic.display_poster }} · {{ topic.created }}</div> <div class="desc">por {{ topic.display_poster }} · {{ topic.created }}</div>
</div> </div>
<div class="meta"> <div class="meta">
<div>{{ topic.post_count }} respuestas · {{ topic.views }} vistas</div> <div>{{ topic.post_count }} respuestas{% if has_views %} · {{ topic.views }} vistas{% endif %}</div>
{% if topic.last_poster %}<div>último: {{ topic.last_poster }}</div>{% endif %} {% if topic.last_poster %}<div>último: {{ topic.last_poster }}</div>{% endif %}
{% if topic.last_time %}<div>{{ topic.last_time }}</div>{% endif %} {% if topic.last_time %}<div>{{ topic.last_time }}</div>{% endif %}
</div> </div>
+1 -1
View File
@@ -14,7 +14,7 @@
<div class="forum-wrap"> <div class="forum-wrap">
<div class="forum-actions"> <div class="forum-actions">
{% if forum %}<a class="forum-btn" href="{% url 'forum_view_p1' forum_id=forum.id %}">← {{ forum.name }}</a>{% endif %} {% if forum %}<a class="forum-btn" href="{% url 'forum_view_p1' forum_id=forum.id %}">← {{ forum.name }}</a>{% endif %}
<span style="color:#b1997f; align-self:center">{{ topic.views }} visitas</span> {% if topic.has_views %}<span style="color:#b1997f; align-self:center">{{ topic.views }} visitas</span>{% endif %}
{% if topic.locked %}<span class="forum-badge">Tema bloqueado</span>{% endif %} {% if topic.locked %}<span class="forum-badge">Tema bloqueado</span>{% endif %}
</div> </div>
+8 -4
View File
@@ -82,6 +82,7 @@ def view_forum(request, forum_id, page=1):
'forum': forum, 'forum': forum,
'topics': topics, 'topics': topics,
'pagination': pag, '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) forum = db.get_forum(topic['forum_id'], include_hidden=True)
# Contador de visitas (si la columna existe) # Contador de visitas (solo si la columna existe)
db.increment_views(topic_id) if db.has_views_column():
if topic.get('views') is not None: db.increment_views(topic_id)
topic['views'] = topic['views'] + 1 topic['views'] = (topic.get('views') or 0) + 1
topic['has_views'] = True
else:
topic['has_views'] = False
total = db.count_posts(topic_id) total = db.count_posts(topic_id)
pag, offset = _paginate(total, page, settings.FORUM_POSTS_PER_PAGE) pag, offset = _paginate(total, page, settings.FORUM_POSTS_PER_PAGE)