From 1431e6d934aa52c41d303b157b7e3c587601f5c7 Mon Sep 17 00:00:00 2001 From: hernani Date: Sat, 10 Jul 2010 01:26:49 +0000 Subject: [PATCH] Fixes question and answer count in the sidebar. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@516 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/node.py | 3 +++ .../default/templates/question_list/count.html | 14 +++++++++----- forum/views/readers.py | 2 -- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/forum/models/node.py b/forum/models/node.py index 75b3933..a8c674c 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -106,6 +106,9 @@ class NodeQuerySet(CachedQuerySet): apply_bool = lambda q, b: b and q or ~q return self.filter(*[apply_bool(models.Q(state_string__contains="(%s)" % s), b) for s, b in kwargs.items()]) + def children_count(self, child_type): + return NodeMetaClass.types[child_type].objects.filter_state(deleted=False).filter(parent__in=self).count() + class NodeManager(CachedManager): use_for_related_fields = True diff --git a/forum/skins/default/templates/question_list/count.html b/forum/skins/default/templates/question_list/count.html index cf347ed..dbb45eb 100644 --- a/forum/skins/default/templates/question_list/count.html +++ b/forum/skins/default/templates/question_list/count.html @@ -1,15 +1,18 @@ -{% load i18n %} -{% load humanize %} +{% spaceless %} +{% load i18n humanize extra_tags %} +{% declare %} + answer_count = questions.children_count('answer') +{% enddeclare %}
- {{ questions_count }}{{ list_description }} + {{ questions.paginator.count }}{{ list_description }}
{% if answer_count %}
- {{ answer_count }}{{ answer_description }} + {{ answer_count }}{% trans "answers" %}
{% endif %} @@ -19,4 +22,5 @@ {{ questions.paginator.sort_description }}

- \ No newline at end of file + +{% endspaceless %} \ No newline at end of file diff --git a/forum/views/readers.py b/forum/views/readers.py index 40bd16c..a47d42c 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -165,10 +165,8 @@ def question_list(request, initial, return pagination.paginated(request, ('questions', paginator_context or QuestionListPaginatorContext()), { "questions" : questions, "questions_count" : questions.count(), - "answer_count" : answer_count, "keywords" : keywords, "list_description": list_description, - "answer_description": answer_description, "base_path" : base_path, "page_title" : page_title, "tab" : "questions", -- 2.45.2