diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-08-08 13:09:22 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-08-08 13:09:22 -0400 |
commit | 004141b9f317b92560a282bbac0a13ea8c899cc7 (patch) | |
tree | 2fcda9f4231eab300585c8bac8816f58c072d79d | |
parent | d99ca01f495a76ef0d7d98f0f690676cc7e2995f (diff) | |
parent | ca2c6aa73f31ba1adb5dd62a416807773fb369f3 (diff) | |
download | askbot-004141b9f317b92560a282bbac0a13ea8c899cc7.tar.gz askbot-004141b9f317b92560a282bbac0a13ea8c899cc7.tar.bz2 askbot-004141b9f317b92560a282bbac0a13ea8c899cc7.zip |
Merge branch 'master' into user-groups
-rw-r--r-- | askbot/models/__init__.py | 6 | ||||
-rw-r--r-- | askbot/models/question.py | 26 | ||||
-rw-r--r-- | askbot/skins/default/templates/question/javascript.html | 7 | ||||
-rw-r--r-- | askbot/skins/default/templates/question/sidebar.html | 8 |
4 files changed, 29 insertions, 18 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 395a5c8e..5392fc30 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -2265,14 +2265,14 @@ def user_get_badge_summary(self): bit = ungettext( 'one silver badge', '%(count)d silver badges', - self.gold + self.silver ) % {'count': self.silver} badge_bits.append(bit) - if self.silver: + if self.bronze: bit = ungettext( 'one bronze badge', '%(count)d bronze badges', - self.gold + self.bronze ) % {'count': self.bronze} badge_bits.append(bit) diff --git a/askbot/models/question.py b/askbot/models/question.py index 89ef76b6..14515b8f 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -732,6 +732,8 @@ class Thread(models.Model): """ def get_data(): + # todo: code in this function would be simpler if + # we had question post id denormalized on the thread tags_list = self.get_tag_names() similar_threads = Thread.objects.filter( tags__name__in=tags_list @@ -750,20 +752,28 @@ class Thread(models.Model): similar_threads = similar_threads[:10] # Denormalize questions to speed up template rendering + # todo: just denormalize question_post_id on the thread! thread_map = dict([(thread.id, thread) for thread in similar_threads]) questions = Post.objects.get_questions() questions = questions.select_related('thread').filter(thread__in=similar_threads) for q in questions: thread_map[q.thread_id].question_denorm = q - # Postprocess data - similar_threads = [ - { - 'url': thread.question_denorm.get_absolute_url(), - 'title': thread.get_title(thread.question_denorm) - } for thread in similar_threads - ] - return similar_threads + # Postprocess data for the final output + result = list() + for thread in similar_threads: + question_post = getattr(thread, 'question_denorm', None) + # unfortunately the if statement below is necessary due to + # a possible bug + # all this proves that it's wrong to reference threads by + # the question post id in the question page urls!!! + # this is a "legacy" problem inherited from the old models + if question_post: + url = question_post.get_absolute_url() + title = thread.get_title(question_post) + result.append({'url': url, 'title': title}) + + return result def get_cached_data(): """similar thread data will expire diff --git a/askbot/skins/default/templates/question/javascript.html b/askbot/skins/default/templates/question/javascript.html index 0be3e5a1..4399c823 100644 --- a/askbot/skins/default/templates/question/javascript.html +++ b/askbot/skins/default/templates/question/javascript.html @@ -38,12 +38,7 @@ <script type="text/javascript"> // define reputation needs for comments var repNeededForComments = 50; - $().ready(function(){ - {% if request.user.is_authenticated() %} - if ($('#question-subscribe-updates')[0].checked){ - $('#question-subscribe-sidebar').attr({'checked': 'checked'}); - } - {%endif%} + $(document).ready(function(){ $("#nav_questions").attr('className',"on"); var answer_sort_tab = "{{ tab_id }}"; $("#" + answer_sort_tab).attr('className',"on"); diff --git a/askbot/skins/default/templates/question/sidebar.html b/askbot/skins/default/templates/question/sidebar.html index 30d67c04..7c7f7860 100644 --- a/askbot/skins/default/templates/question/sidebar.html +++ b/askbot/skins/default/templates/question/sidebar.html @@ -27,7 +27,13 @@ </div> <div class="notify-sidebar"> {%if request.user.is_authenticated() %} - <input type="checkbox" id="question-subscribe-sidebar"/> + <input + type="checkbox" + id="question-subscribe-sidebar" + {% if thread.is_followed_by(request.user) %} + checked="checked" + {% endif %} + /> <label for="question-subscribe-sidebar">{% trans %}email the updates{% endtrans %}</label> {%else%} <input type="checkbox" id="question-subscribe-sidebar"/> |