summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--forum/templatetags/extra_tags.py2
-rw-r--r--forum/urls.py2
-rw-r--r--forum/views.py43
-rw-r--r--templates/user_stats.html9
4 files changed, 40 insertions, 16 deletions
diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py
index 96dc9024..b2199284 100644
--- a/forum/templatetags/extra_tags.py
+++ b/forum/templatetags/extra_tags.py
@@ -251,7 +251,7 @@ def diff_date(date, limen=2):
return _('2 days ago')
elif days == 1:
return _('yesterday')
- elif minutes > 60:
+ elif minutes >= 60:
return ungettext('%(hr)d hour ago','%(hr)d hours ago',hours) % {'hr':hours}
else:
return ungettext('%(min)d min ago','%(min)d mins ago',minutes) % {'min':minutes}
diff --git a/forum/urls.py b/forum/urls.py
index a08fe716..ee4f0992 100644
--- a/forum/urls.py
+++ b/forum/urls.py
@@ -50,7 +50,7 @@ urlpatterns = patterns('',
#place general question item in the end of other operations
url(r'^%s(?P<id>\d+)//*' % _('question/'), app.question, name='question'),
url(r'^%s$' % _('tags/'), app.tags, name='tags'),
- url(r'^%s(?P<tag>[^/]+)/$' % _('tags/'), app.tag),
+ url(r'^%s(?P<tag>[^/]+)/$' % _('tags/'), app.tag, name='tag_questions'),
url(r'^%s$' % _('users/'),app.users, name='users'),
url(r'^%s(?P<id>\d+)/$' % _('moderate-user/'), app.moderate_user, name='moderate_user'),
url(r'^%s(?P<id>\d+)/%s$' % (_('users/'), _('edit/')), app.edit_user, name='edit_user'),
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,
diff --git a/templates/user_stats.html b/templates/user_stats.html
index 2b7949e8..06f1cd2b 100644
--- a/templates/user_stats.html
+++ b/templates/user_stats.html
@@ -84,7 +84,7 @@
<a name="tags"></a>
{% spaceless %}
<h2>
- {% blocktrans count tags|length as counter %}
+ {% blocktrans count user_tags|length as counter %}
<span class="count">1</span> Tag
{% plural %}
<span class="count">{{counter}}</span> Tags
@@ -95,10 +95,11 @@
<table class="tags">
<tr>
<td width="180" valign="top">
- {% for tag in tags%}
+ {% for tag in user_tags%}
<a rel="tag"
- title="{% blocktrans %}see other questions tagged '{{ tag }}' {% endblocktrans %}"
- href="{% url forum.views.tag tag|urlencode %}">{{tag.name}}</a><span class="tag-number"> &#215; {{ tag.used_count|intcomma }}</span><br/>
+ title="{% blocktrans with tag.name as tag_name %}see other questions tagged '{{ tag_name }}' {% endblocktrans %}"
+ href="{% url forum.views.tag tag|urlencode %}?user={{view_user.username}}">{{tag.name}}</a>
+ <span class="tag-number">&#215; {{ tag.user_tag_usage_count|intcomma }}</span><br/>
{% if forloop.counter|divisibleby:"10" %}
</td>
<td width="180" valign="top">