summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-07-29 20:27:54 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-07-29 20:27:54 -0400
commitbe849d3052d2fb508484674aad11829683448ff9 (patch)
treed0ec5633d9abc71e5ac92cc074ae554b8fc16f02
parent69a7fe6583e75fecadbe83053957ab93fda9d011 (diff)
downloadaskbot-be849d3052d2fb508484674aad11829683448ff9.tar.gz
askbot-be849d3052d2fb508484674aad11829683448ff9.tar.bz2
askbot-be849d3052d2fb508484674aad11829683448ff9.zip
made badge context display work
-rw-r--r--askbot/models/badges.py2
-rwxr-xr-xaskbot/skins/default/media/style/style.css5
-rw-r--r--askbot/skins/default/templates/user_profile/user_stats.html63
-rw-r--r--askbot/views/users.py26
4 files changed, 49 insertions, 47 deletions
diff --git a/askbot/models/badges.py b/askbot/models/badges.py
index 7c10cb2e..5e56b499 100644
--- a/askbot/models/badges.py
+++ b/askbot/models/badges.py
@@ -6,7 +6,7 @@ However, the database does have model BadgeData, that contains
additional mutable data pertaining to the badges - denormalized award counts
and lists of recipients.
-BadgeData django model is located in askbot/models/meta.py
+BadgeData django model is located in askbot/models/repute.py
Badges in this file are connected with the contents of BadgeData
via key, determined as a slugified version of badge name.
diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css
index 0306e45a..6a95782e 100755
--- a/askbot/skins/default/media/style/style.css
+++ b/askbot/skins/default/media/style/style.css
@@ -76,6 +76,11 @@ a:hover {
text-decoration: underline;
}
+.badge-context-toggle.active {
+ cursor: pointer;
+ text-decoration: underline;
+}
+
h1 {
font-size: 160%;
padding: 10px 0 5px 5px;
diff --git a/askbot/skins/default/templates/user_profile/user_stats.html b/askbot/skins/default/templates/user_profile/user_stats.html
index 7009acb5..8cae46c2 100644
--- a/askbot/skins/default/templates/user_profile/user_stats.html
+++ b/askbot/skins/default/templates/user_profile/user_stats.html
@@ -103,32 +103,26 @@
<tr>
<td style="line-height:35px">
{% for badge in badges %}{# todo: translate badge name properly #}
- <a href="{{badge.get_absolute_url()}}" title="{% trans description=badge.description %}{{description}}{% endtrans %}" class="medal"><span class="{{ badge.css_class }}">&#9679;</span>&nbsp;{% trans name=badge.name %}{{name}}{% endtrans %}</a><span class="tag-number"> &#215; <a href="javascript:void(0)" onclick="var div = jQuery('#badge-context-{{badge.id}}'); if(div.css('display') == 'none') div.show(); else(div.hide());">{{ awarded_badge_counts[badge.id]|intcomma }}</a></span>
+ <a
+ href="{{badge.get_absolute_url()}}"
+ title="{% trans description=badge.description %}{{description}}{% endtrans %}"
+ class="medal"
+ ><span class="{{ badge.css_class }}">&#9679;</span>&nbsp;{% trans name=badge.name %}{{name}}{% endtrans %}
+ </a>&nbsp;
+ <span class="tag-number">&#215;
+ <span class="badge-context-toggle">{{ badge.award_badge.count()|intcomma }}</span>
+ </span>
<ul id="badge-context-{{ badge.id }}" class="badge-context-list" style="display:none">
- {% for abt in awarded_badge_context %}
- {% if abt.badge == badge.id %}
- {% if abt.content_type == question_type %}
- {% for question in questions %}{# could also create a new dict #}
- {% if question.id == abt.object_id %}
- <li>
- <a title="{{question.summary|collapse}}"
- href="{% url question question.id %}{{question.title|slugify}}">{{question.title}}</a>
- </li>
- {% endif %}
- {% endfor %}
+ {% for award in badge.award_badge.filter(user = view_user) %}
+ {% if award.content_type in (question_type, answer_type) %}
+ <li>
+ <a
+ title="{{ award.content_object.get_snippet|collapse }}"
+ href="{{ award.content_object.get_absolute_url() }}"
+ >{% if award.content_type == answer_type %}{% trans %}Answer to:{% endtrans %}{% endif %} {{ award.content_object.get_origin_post().title }}</a>
+ </li>
{% endif %}
- {% if abt.content_type == answer_type %}
- {% for answered_question in answered_questions %}{# could also create a new dict #}
- {% if answered_question.answer_id == abt.object_id %}
- <li>
- <a title="{{answered_question.summary|collapse}}"
- href="{% url question answered_question.id %}{{answered_question.title|slugify}}#{{answered_question.answer_id}}">{{answered_question.title}}</a>
- </li>
- {% endif %}
- {% endfor %}
- {% endif %}
- {% endif %}
- {% endfor %}
+ {% endfor %}
</ul>
{% if loop.index is divisibleby 3 %}
</td></tr>
@@ -140,4 +134,25 @@
</table>
</div>
{% endblock %}
+{% block endjs %}
+ <script type="text/javascript">
+ $(document).ready(function(){
+ $('.badge-context-toggle').each(function(idx, elem){
+ var context_list = $(elem).parent().next('ul');
+ if (context_list.children().length > 0){
+ $(elem).addClass('active');
+ var toggle_display = function(){
+ if (context_list.css('display') == 'none'){
+ $('.badge-context-list').hide();{# hide all context lists #}
+ context_list.show();
+ } else {
+ context_list.hide();
+ }
+ };
+ $(elem).click(toggle_display);
+ }
+ });
+ });
+ </script>
+{% endblock %}
<!-- end user_stats.html -->
diff --git a/askbot/views/users.py b/askbot/views/users.py
index 45aae274..dcbda63c 100644
--- a/askbot/views/users.py
+++ b/askbot/views/users.py
@@ -347,28 +347,12 @@ def user_stats(request, user, context):
question_id_set.update([q.id for q in questions])
question_id_set.update([q['id'] for q in answered_questions])
user_tags = models.Tag.objects.filter(questions__id__in = question_id_set)
+
badges = models.BadgeData.objects.filter(
award_badge__user=user
)
total_awards = badges.count()
- badges = badges.order_by(
- '-slug'
- ).distinct()
- awarded_badge_counts = models.Award.objects.filter(
- user = user
- ).values(
- 'badge'
- ).annotate(
- count = Count('badge__id')
- ).values_list(
- 'badge', 'count'
- )
-
- awarded_badge_context = models.Award.objects.filter(
- user = user
- ).values(
- 'object_id', 'badge', 'content_type'
- )
+ badges = badges.order_by('-slug').distinct()
user_tags = user_tags.annotate(
user_tag_usage_count=Count('name')
@@ -396,8 +380,8 @@ def user_stats(request, user, context):
'page_title' : _('user profile overview'),
'user_status_for_display': user.get_status_display(soft = True),
'questions' : questions,
- 'question_type' : question_type_id,
- 'answer_type' : answer_type_id,
+ 'question_type' : question_type,
+ 'answer_type' : answer_type,
'favorited_myself': favorited_myself,
'answered_questions' : answered_questions,
'up_votes' : up_votes,
@@ -407,8 +391,6 @@ def user_stats(request, user, context):
'votes_total_per_day': votes_total,
'user_tags' : user_tags[:const.USER_VIEW_DATA_SIZE],
'badges': badges,
- 'awarded_badge_counts': dict(awarded_badge_counts),
- 'awarded_badge_context': awarded_badge_context,
'total_awards' : total_awards,
}
context.update(data)