summaryrefslogtreecommitdiffstats
path: root/forum/views.py
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2009-11-25 19:45:10 -0500
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2009-11-25 19:45:10 -0500
commit19b8d46665cc8fa02121c5761ee62d99e9359105 (patch)
tree29886f27cedc81e3caa012992187bac20bae2460 /forum/views.py
parentad98bb5c3f6408ac9a12d1c79448ca841fbcd904 (diff)
downloadaskbot-19b8d46665cc8fa02121c5761ee62d99e9359105.tar.gz
askbot-19b8d46665cc8fa02121c5761ee62d99e9359105.tar.bz2
askbot-19b8d46665cc8fa02121c5761ee62d99e9359105.zip
fixed user tag selection and count, link points to user authored questions/answers, fixed diff_date a little
Diffstat (limited to 'forum/views.py')
-rw-r--r--forum/views.py43
1 files changed, 33 insertions, 10 deletions
diff --git a/forum/views.py b/forum/views.py
index d9d87e02..53338dd3 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -169,6 +169,15 @@ def questions(request, tagname=None, unanswered=False):
else:
objects = Question.objects.get_questions(orderby)
+ author_name = None
+ if 'user' in request.GET:
+ try:
+ author_name = request.GET['user']
+ u = User.objects.get(username=author_name)
+ objects = objects.filter(Q(author=u) | Q(answers__author=u))
+ except User.DoesNotExist:
+ author_name = None
+
# RISK - inner join queries
objects = objects.select_related(depth=1);
objects_list = Paginator(objects, pagesize)
@@ -181,6 +190,7 @@ def questions(request, tagname=None, unanswered=False):
related_tags = None
return render_to_response(template_file, {
"questions" : questions,
+ "author_name" : author_name,
"tab_id" : view_id,
"questions_count" : objects_list.count,
"tags" : related_tags,
@@ -1221,28 +1231,40 @@ def user_stats(request, user_id, user_view):
down_votes = Vote.objects.get_down_vote_count_from_user(user)
votes_today = Vote.objects.get_votes_count_today_from_user(user)
votes_total = VOTE_RULES['scope_votes_per_user_per_day']
- tags = user.created_tags.all().order_by('-used_count')[:50]
- if settings.DJANGO_VERSION < 1.1:
+
+ question_id_set = set(map(lambda v: v['id'], list(questions))) \
+ | set(map(lambda v: v['id'], list(answered_questions)))
+
+ user_tags = Tag.objects.filter(questions__id__in = question_id_set)
+
+ try:
+ from django.db.models import Count
awards = Award.objects.extra(
- select={'id': 'badge.id', 'count': 'count(badge_id)', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
+ select={'id': 'badge.id', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
tables=['award', 'badge'],
order_by=['-awarded_at'],
where=['user_id=%s AND badge_id=badge.id'],
params=[user.id]
- ).values('id', 'count', 'name', 'description', 'type')
+ ).values('id', 'name', 'description', 'type')
total_awards = awards.count()
- awards.query.group_by = ['badge_id']
- else:
+ awards = awards.annotate(count = Count('badge__id'))
+ user_tags = user_tags.annotate(user_tag_usage_count=Count('name'))
+
+ except ImportError:
awards = Award.objects.extra(
- select={'id': 'badge.id', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
+ select={'id': 'badge.id', 'count': 'count(badge_id)', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
tables=['award', 'badge'],
order_by=['-awarded_at'],
where=['user_id=%s AND badge_id=badge.id'],
params=[user.id]
- ).values('id', 'name', 'description', 'type')
+ ).values('id', 'count', 'name', 'description', 'type')
total_awards = awards.count()
- from django.db.models import Count
- awards = awards.annotate(count = Count('badge__id'))
+ awards.query.group_by = ['badge_id']
+ user_tags = user_tags.extra(
+ select={'user_tag_usage_count': 'COUNT(1)',},
+ order_by=['-user_tag_usage_count'],
+ )
+ user_tags.query.group_by = ['name']
if auth.can_moderate_users(request.user):
moderate_user_form = ModerateUserForm(instance=user)
@@ -1262,6 +1284,7 @@ def user_stats(request, user_id, user_view):
"total_votes": up_votes + down_votes,
"votes_today_left": votes_total-votes_today,
"votes_total_per_day": votes_total,
+ "user_tags" : user_tags[:50],
"tags" : tags,
"awards": awards,
"total_awards" : total_awards,