summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2011-12-09 22:58:49 +0100
committerTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2011-12-09 22:58:49 +0100
commitb159c234d18c9c1cd4236f5ef37ad89cd284e480 (patch)
tree1e454dee2d6cd650894e6b3f4f6f7fda2be94f94
parentdfb22a3c8c850b81c5c6926a8487bbcaeab7ec02 (diff)
downloadaskbot-b159c234d18c9c1cd4236f5ef37ad89cd284e480.tar.gz
askbot-b159c234d18c9c1cd4236f5ef37ad89cd284e480.tar.bz2
askbot-b159c234d18c9c1cd4236f5ef37ad89cd284e480.zip
Tickets 104, 107: User_stats tweaks
-rw-r--r--askbot/views/users.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/askbot/views/users.py b/askbot/views/users.py
index 6cb784bc..0d90105d 100644
--- a/askbot/views/users.py
+++ b/askbot/views/users.py
@@ -305,13 +305,12 @@ def user_stats(request, user, context):
votes_today = models.Vote.objects.get_votes_count_today_from_user(user)
votes_total = askbot_settings.MAX_VOTES_PER_USER_PER_DAY
- thread_id_set = set()
- thread_id_set.update([qq.thread_id for qq in questions])
- thread_id_set.update([aa.thread_id for aa in top_answers])
- user_tags = models.Tag.objects.filter(threads__id__in=thread_id_set).\
+ # INFO: There's bug in Django that makes the following query kind of broken (GROUP BY clause is problematic):
+ # http://stackoverflow.com/questions/7973461/django-aggregation-does-excessive-group-by-clauses
+ # Fortunately it looks to return correct results for the test data
+ user_tags = models.Tag.objects.filter(threads__post__author=user).\
annotate(user_tag_usage_count=Count('threads')).\
order_by('-user_tag_usage_count')[:const.USER_VIEW_DATA_SIZE]
- user_tags = list(user_tags) # DEBUG: evaluate
user_awards = models.Award.objects.filter(user=user).select_related('badge')
badges_dict = {}
@@ -325,8 +324,8 @@ def user_stats(request, user, context):
# TODO: fetch award.content_object in one query, as a list of Post-s, and pass to template to avoid subsequent queries there
total_badges = len(badges)
+# INFO: Shorter version for fetching badges, but then it's hard to do the postprocessing (i.e. getting user awards per badge etc.)
# badges = models.BadgeData.objects.filter(award_badge__user=user).annotate(user_awarded_times=Count('award_badge'))
-# total_badges = len(badges)
data = {
'active_tab':'users',
@@ -341,7 +340,6 @@ def user_stats(request, user, context):
'question_type' : ContentType.objects.get_for_model(models.Question),
'answer_type' : ContentType.objects.get_for_model(models.Answer),
- #'answered_questions' : answered_questions,
'top_answers': top_answers,
'top_answer_count': top_answer_count,
@@ -358,8 +356,6 @@ def user_stats(request, user, context):
}
context.update(data)
- len(models.Post.objects.filter(post_type='mikki')) # DEBUG: distinctive query
-
return render_into_skin('user_profile/user_stats.html', context, request)
def user_recent(request, user, context):