diff options
-rw-r--r-- | askbot/conf/__init__.py | 2 | ||||
-rw-r--r-- | askbot/conf/skin_counter_settings.py | 2 | ||||
-rw-r--r-- | askbot/setup_templates/settings.py | 4 | ||||
-rw-r--r-- | askbot/skins/default/media/images/wiki.png | bin | 0 -> 5178 bytes | |||
-rwxr-xr-x | askbot/skins/default/media/style/style.css | 39 | ||||
-rw-r--r-- | askbot/skins/default/templates/macros.html | 96 | ||||
-rw-r--r-- | askbot/skins/default/templates/question.html | 36 | ||||
-rw-r--r-- | askbot/skins/default/templates/questions.html | 58 | ||||
-rw-r--r-- | askbot/skins/default/templates/revisions.html | 8 | ||||
-rw-r--r-- | askbot/skins/default/templates/users_questions.html | 77 | ||||
-rw-r--r-- | askbot/views/users.py | 117 |
11 files changed, 190 insertions, 249 deletions
diff --git a/askbot/conf/__init__.py b/askbot/conf/__init__.py index 67ff56a9..3773daa4 100644 --- a/askbot/conf/__init__.py +++ b/askbot/conf/__init__.py @@ -7,7 +7,7 @@ import askbot.conf.forum_data_rules import askbot.conf.flatpages import askbot.conf.site_settings import askbot.conf.external_keys -import askbot.conf.skin_counter_settings +#import askbot.conf.skin_counter_settings import askbot.conf.skin_general_settings import askbot.conf.user_settings import askbot.conf.markup diff --git a/askbot/conf/skin_counter_settings.py b/askbot/conf/skin_counter_settings.py index 54713cb9..7601a7a7 100644 --- a/askbot/conf/skin_counter_settings.py +++ b/askbot/conf/skin_counter_settings.py @@ -184,7 +184,6 @@ settings.register( ).html, description=_('Background color for answers = 0'), help_text=_('HTML color name or hex value'), - hidden=True, ) ) @@ -195,7 +194,6 @@ settings.register( default='yellow', description=_('Foreground color for answers = 0'), help_text=_('HTML color name or hex value'), - hidden=True, ) ) diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index abb2ac6d..86625903 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -7,8 +7,8 @@ import askbot #this line is added so that we can import pre-packaged askbot dependencies sys.path.append(os.path.join(os.path.dirname(askbot.__file__), 'deps')) -DEBUG = True -TEMPLATE_DEBUG = DEBUG +DEBUG = False#set to True to enable debugging +TEMPLATE_DEBUG = False#keep false when debugging jinja2 templates INTERNAL_IPS = ('127.0.0.1',) ADMINS = ( diff --git a/askbot/skins/default/media/images/wiki.png b/askbot/skins/default/media/images/wiki.png Binary files differnew file mode 100644 index 00000000..06d487f3 --- /dev/null +++ b/askbot/skins/default/media/images/wiki.png diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css index 14ea9648..19ca902a 100755 --- a/askbot/skins/default/media/style/style.css +++ b/askbot/skins/default/media/style/style.css @@ -600,6 +600,35 @@ blockquote { padding-top:1px; } +.no-votes { + background: white; + color: gray; +} +.some-votes { + background: #a3d0ff; + color: #4a4a4a; +} +.no-answers { + background: #b63333; + color: yellow; +} +.some-answers { + background: #ffed9c; + color: #a4a4a4; +} +.accepted { + background:#338333; + color:#d0f5a9; +} +.no-views { + background: gray; + color: white; +} +.some-views { + background: #ff8c8c; + color: #4a4a4a; +} + .short-summary .votes, .short-summary .status, .short-summary .views { @@ -1900,6 +1929,11 @@ div.started .reputation-score { margin-left: 1px; } +#top a.user-micro-info { + margin-left:0px; + text-decoration:none; +} + .narrow .tags { float: left; } @@ -2515,7 +2549,6 @@ ul.form-horizontal-rows li input { .post-update-info img { float: left; - width: 32px; margin: 4px 8px 0 0; } @@ -2523,6 +2556,10 @@ ul.form-horizontal-rows li input { clear: both; } +.post-update-info p.tip { + color: #444; +} + .admin { background-color: #fff380; /* nice yellow */ border: 1px solid darkred; diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html index f3ec824a..6bb4a5d7 100644 --- a/askbot/skins/default/templates/macros.html +++ b/askbot/skins/default/templates/macros.html @@ -21,11 +21,13 @@ {%- endmacro -%} {%- macro user_long_score_and_badge_summary(user) -%} - <span class="reputation-score" - title="{{user.get_karma_summary}}" - >{% trans %}karma:{% endtrans %} {{user.reputation}}</span> + <a class="user-micro-info" + href="{{user.get_absolute_url()}}?sort=reputation" + >{% trans %}karma:{% endtrans %} {{user.reputation}}</a> {% if user.gold or user.silver or user.bronze %} - <span title="{{user.get_badge_summary}}">{% trans %}badges:{% endtrans %} + <a class="user-micro-info" + href="{{user.get_absolute_url()}}#badges" + ><span title="{{user.get_badge_summary}}">{% trans %}badges:{% endtrans %} {% if user.gold %} <span class='badge1'>●</span> <span class="badgecount">{{user.gold}}</span> @@ -38,7 +40,7 @@ <span class='badge3'>●</span> <span class="badgecount">{{user.bronze}}</span> {% endif %} - </span> + </span></a> {% endif %} {%- endmacro -%} @@ -119,17 +121,29 @@ {% endspaceless %} {%- endmacro -%} -{%- macro post_contributor_info(post, contributor_type, is_wiki) -%} +{%- macro post_contributor_info(post, contributor_type, is_wiki, wiki_min_rep) -%} <div class='post-update-info'> {# there is a whole bunch of trickery here, probably indicative of poor design of the data or methods on data objects #} {% if contributor_type=="original_author" %} {% if is_wiki %} - <p>{% trans %}community wiki{% endtrans %}</p> - <p> - {% trans rev_count=post.revisions.all()|length %}{{rev_count}} revision{% pluralize %}{{rev_count}} revisions{% endtrans %} + <p style="line-height:12px"> + {%- if post.__class__.__name__ == 'Question' -%} + {%- trans %}asked{% endtrans %} + {% elif post.__class__.__name__ == 'Answer' %} + {%- trans %}answered{% endtrans %} + {% else %} + {%- trans %}posted{% endtrans %} + {% endif %} + <strong>{{post.added_at|diff_date}}</strong> </p> - <p>{{post.author.get_profile_link()}}</p> + <img + src="{{'/images/wiki.png'|media}}" + alt="{% trans %}this post is marked as community wiki{% endtrans %}" + style="float:left" + /> + <p class="tip">{% trans %}This post is a wiki. + Anyone with karma >{{wiki_min_rep}} is welcome to improve it.{% endtrans %}</p> {% else %} <p style="line-height:12px;"> {# todo: access to class names needs to be removed here #} @@ -170,7 +184,7 @@ poor design of the data or methods on data objects #} {% endif %} >{% trans %}updated{% endtrans %} <strong>{{ last_edited_at|diff_date }}</strong></a> </p> - {% if original_author != display_author or is_wiki %} + {% if original_author != update_author or is_wiki %} {{ gravatar(update_author, 32) }} <p style="float:left">{{update_author.get_profile_link()}}<br/> {{ user_score_and_badge_summary(update_author) }}</p> @@ -179,3 +193,63 @@ poor design of the data or methods on data objects #} {% endif %} </div> {%- endmacro -%} + +{%- macro question_summary(question, extra_class=None) -%} + <div class="short-summary{% if extra_class %} {{extra_class}}{% endif %}"> + <div class="counts"> + <div class="votes"> + <span + class="item-count + {% if question.score == 0 -%} + no-votes + {% else -%} + some-votes + {%- endif -%}" + >{{question.score|humanize_counter}}</span> + <div> + {% trans cnt=question.score %}vote{% pluralize %}votes{% endtrans %} + </div> + </div> + <div class="votes"> + <span + class="item-count + {% if question.answer_count == 0 -%} + no-answers + {% else -%} + {%- if question.answer_accepted -%} + accepted + {%- else -%} + some-answers + {%- endif -%} + {%- endif -%}" + >{{question.answer_count|humanize_counter}}{% if question.answer_accepted%}✓{% endif %}</span> + <div> + {% trans cnt=question.answer_count %}answer{% pluralize %}answers{% endtrans %} + </div> + </div> + <div class="votes"> + <span class="item-count + {% if question.view_count == 0 -%} + no-views + {% else -%} + some-views + {%- endif -%}" + >{{question.view_count|humanize_counter}}</span> + <div> + {% trans cnt=question.view_count %}view{% pluralize %}views{% endtrans %} + </div> + </div> + </div> + <h2><a title="{{question.summary|escape}}" href="{{ question.get_absolute_url() }}">{{question.title|escape}}</a></h2> + <div class="userinfo"> + <span class="relativetime" title="{{question.last_activity_at}}">{{ question.last_activity_at|diff_date }}</span> + <a href="{% url user_profile question.last_activity_by.id, question.last_activity_by.username|slugify %}">{{question.last_activity_by.username}}</a> + {{user_score_and_badge_summary(question.last_activity_by)}} + </div> + <div class="tags"> + {% for tag in question.get_tag_names() %} + <a href="{% url questions %}?tags={{tag|urlencode}}" title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}" rel="tag">{{ tag }}</a> + {% endfor %} + </div> + </div> +{%- endmacro -%} diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html index 6c7f288b..a4d8e128 100644 --- a/askbot/skins/default/templates/question.html +++ b/askbot/skins/default/templates/question.html @@ -172,17 +172,19 @@ <div class="post-update-info-container"> {{ macros.post_contributor_info( - question, - "original_author", - question.wiki - ) + question, + "original_author", + question.wiki, + settings.MIN_REP_TO_EDIT_WIKI + ) }} {{ macros.post_contributor_info( - question, - "last_updter", - question.wiki - ) + question, + "last_updater", + question.wiki, + settings.MIN_REP_TO_EDIT_WIKI, + ) }} </div> {% spaceless %} @@ -340,17 +342,19 @@ <div class="post-update-info-container"> {{ macros.post_contributor_info( - answer, - "original_author", - answer.wiki - ) + answer, + "original_author", + answer.wiki, + settings.MIN_REP_TO_EDIT_WIKI + ) }} {{ macros.post_contributor_info( - answer, - "last_updater", - answer.wiki - ) + answer, + "last_updater", + answer.wiki, + settings.MIN_REP_TO_EDIT_WIKI + ) }} </div> {% spaceless %} diff --git a/askbot/skins/default/templates/questions.html b/askbot/skins/default/templates/questions.html index eaf3546d..20b0b0ce 100644 --- a/askbot/skins/default/templates/questions.html +++ b/askbot/skins/default/templates/questions.html @@ -158,63 +158,7 @@ <div id="listA"> {% cache 0 "questions" questions search_tags scope sort query context.page context.page_size language_code %} {% for question in questions.object_list %} - <div class="short-summary"> - <div class="counts"> - <div class="votes"> - <span - class="item-count" - {% if question.score == 0 %} - style="background:{{settings.COLORS_VOTE_COUNTER_EMPTY_BG}};color:{{settings.COLORS_VOTE_COUNTER_EMPTY_FG}}" - {% else %} - style="background:{{settings.COLORS_VOTE_COUNTER_MIN_BG}};color:{{settings.COLORS_VOTE_COUNTER_MIN_FG}}" - {% endif %} - >{{question.score|humanize_counter}}</span> - <div> - {% trans cnt=question.score %}vote{% pluralize %}votes{% endtrans %} - </div> - </div > - <div class="votes"> - <span - class="item-count" - {% if question.answer_count == 0 %} - style="background:{{settings.COLORS_ANSWER_COUNTER_EMPTY_BG}};color:{{settings.COLORS_ANSWER_COUNTER_EMPTY_FG}}" - {% else %} - {% if question.answer_accepted %} - style="background:{{settings.COLORS_ANSWER_COUNTER_ACCEPTED_BG}};color:{{settings.COLORS_ANSWER_COUNTER_ACCEPTED_FG}}" - {% else %} - style="background:{{settings.COLORS_ANSWER_COUNTER_MIN_BG}};color:{{settings.COLORS_ANSWER_COUNTER_MIN_FG}}" - {% endif %} - {% endif %} - >{{question.answer_count|humanize_counter}}</span> - <div> - {% trans cnt=question.answer_count %}answer{% pluralize %}answers{% endtrans %} - </div> - </div> - <div class="votes"> - <span class="item-count" - {% if question.view_count == 0 %} - style="background:{{settings.COLORS_VIEW_COUNTER_EMPTY_BG}};color:{{settings.COLORS_VIEW_COUNTER_EMPTY_FG}}" - {% else %} - style="background:{{settings.COLORS_VIEW_COUNTER_MIN_BG}};color:{{settings.COLORS_VIEW_COUNTER_MIN_FG}}" - {% endif %} - >{{question.view_count|humanize_counter}}</span> - <div> - {% trans cnt=question.view_count %}view{% pluralize %}views{% endtrans %} - </div> - </div> - </div> - <h2><a title="{{question.summary|escape}}" href="{{ question.get_absolute_url() }}">{{question.title|escape}}</a></h2> - <div class="userinfo"> - <span class="relativetime" title="{{question.last_activity_at}}">{{ question.last_activity_at|diff_date }}</span> - <a href="{% url user_profile question.last_activity_by.id, question.last_activity_by.username|slugify %}">{{question.last_activity_by.username}}</a> - {{macros.user_score_and_badge_summary(question.last_activity_by)}} - </div> - <div class="tags"> - {% for tag in question.get_tag_names() %} - <a href="{% url questions %}?tags={{tag|urlencode}}" title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}" rel="tag">{{ tag }}</a> - {% endfor %} - </div> - </div> + {{macros.question_summary(question)}} {% endfor %} {% endcache %} {# comment todo: fix css here #} diff --git a/askbot/skins/default/templates/revisions.html b/askbot/skins/default/templates/revisions.html index d5884dfc..0bd55d75 100644 --- a/askbot/skins/default/templates/revisions.html +++ b/askbot/skins/default/templates/revisions.html @@ -76,9 +76,11 @@ {% set contributor_type = "last_updater" %} {% endif %} {{ macros.post_contributor_info( - revision, - contributor_type, - False) + revision, + contributor_type, + False, + 0 + ) }} </div> </td> diff --git a/askbot/skins/default/templates/users_questions.html b/askbot/skins/default/templates/users_questions.html index 05087b6c..aaec21b7 100644 --- a/askbot/skins/default/templates/users_questions.html +++ b/askbot/skins/default/templates/users_questions.html @@ -3,7 +3,7 @@ <div class="user-stats-table"> {% for question in questions %} {% if question.favourite_count %} - {% if question.favorited_myself %} + {% if question.id in favorited_myself %} <div class="favorites-count"> <img title="{% trans cnt=question.favourite_count %}this questions was selected as favorite {{cnt}} time{% pluralize %}this questions was selected as favorite {{cnt}} times{% endtrans %}" @@ -23,80 +23,7 @@ {% else %} <div class="favorites-empty"> </div> {% endif %} - <div id="question-summary-{{question.id}}" class="short-summary narrow"> - <div class="counts"> - <div class="votes"> - <span - class="item-count" - style="background:{{settings.COLORS_VOTE_COUNTER_MIN_BG}};color:{{settings.COLORS_VOTE_COUNTER_MIN_FG}}" - >{{question.score|humanize_counter}}</span> - <div> - {% trans cnt=question.score %} - vote - {% pluralize %} - votes - {% endtrans %} - </div> - </div > - {# - <div {% if question.answer_accepted %}title="{% trans %}this answer has been accepted to be correct{% endtrans %}"{% endif %} class="status {% if question.answer_accepted %}answered-accepted{% endif %} {% if question.answer_count==0 %}unanswered{% endif %}{% if question.answer_count!=0 %}answered{% endif %}"> - #} - <div class="votes"> - <span - class="item-count" - {% if question.answer_accepted %} - style="background:{{settings.COLORS_ANSWER_COUNTER_ACCEPTED_BG}};color:{{settings.COLORS_ANSWER_COUNTER_ACCEPTED_FG}}" - {% else %} - style="background:{{settings.COLORS_ANSWER_COUNTER_MIN_BG}};color:{{settings.COLORS_ANSWER_COUNTER_MIN_FG}}" - {% endif %} - >{{question.answer_count|humanize_counter}}</span> - <div> - {% trans cnt=question.answer_count %} - answer - {% pluralize %} - answers - {% endtrans %} - </div> - </div> - <div class="votes"> - <span class="item-count" - style="background:{{settings.COLORS_VIEW_COUNTER_MIN_BG}};color:{{settings.COLORS_VIEW_COUNTER_MIN_FG}}" - >{{question.view_count|humanize_counter}}</span> - <div> - {% trans cnt=question.view_count %} - view - {% pluralize %} - views - {% endtrans %} - </div> - </div> - </div> - <h2><a title="{{question.summary|escape}}" href="{% url question id=question.id %}{{question.title|slugify}}">{{question.title|escape}}</a></h2> - <div class="tags"> - {% for tag in question.tagnames|split(' ') %} - <!--todo - move trans below to trans --> - <a href="{% url questions %}?tags={{tag|urlencode}}" title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}" rel="tag">{{ tag }}</a> - {% endfor %} - </div> - <div class="started"> - <span class="relativetime" title="{{question.last_activity_at}}">{{question.last_activity_at|diff_date}}</span> - {% if question.la_username %} - <a - href="{% url users %}{{question.la_user_id}}/{{question.la_username}}" - >{{question.la_username}}</a> - {{ macros.user_score_and_badge_summary( - { - 'reputation': question.la_user_reputaion, - 'gold': question.la_user_gold, - 'silver': question.la_user_silver, - 'bronze': question.la_user_bronze, - } - ) - }} - {% endif %} - </div> - </div> - <br clear="all"/> + {{macros.question_summary(question, extra_class='narrow')}} {% endfor %} </div> <!-- end users_questions.html --> diff --git a/askbot/views/users.py b/askbot/views/users.py index 4db7641a..32a2bdcb 100644 --- a/askbot/views/users.py +++ b/askbot/views/users.py @@ -284,44 +284,23 @@ def edit_user(request, id): def user_stats(request, user): - questions = models.Question.objects.extra( - select={ - 'score' : 'question.score', - 'favorited_myself' : 'SELECT count(*) FROM favorite_question f WHERE f.user_id = %s AND f.question_id = question.id', - 'la_user_id' : 'auth_user.id', - 'la_username' : 'auth_user.username', - 'la_user_gold' : 'auth_user.gold', - 'la_user_silver' : 'auth_user.silver', - 'la_user_bronze' : 'auth_user.bronze', - 'la_user_reputation' : 'auth_user.reputation' - }, - select_params=[user.id], - tables=['question', 'auth_user'], - where=['question.author_id=%s AND question.last_activity_by_id = auth_user.id AND NOT question.deleted'], - params=[user.id], - order_by=['-score', '-last_activity_at'] - ).values('score', - 'favorited_myself', - 'id', - 'title', - 'author_id', - 'added_at', - 'answer_accepted', - 'answer_count', - 'comment_count', - 'view_count', - 'favourite_count', - 'summary', - 'tagnames', - 'vote_up_count', - 'vote_down_count', - 'last_activity_at', - 'la_user_id', - 'la_username', - 'la_user_gold', - 'la_user_silver', - 'la_user_bronze', - 'la_user_reputation')[:100] + questions = models.Question.objects.filter( + author = user + ).order_by( + '-score', '-last_activity_at' + ).select_related( + 'last_activity_by__id', + 'last_activity_by__username', + 'last_activity_by__reputation', + 'last_activity_by__gold', + 'last_activity_by__silver', + 'last_activity_by__bronze' + )[:100] + questions = list(questions) + favorited_myself = models.FavoriteQuestion.objects.filter( + question__in = questions, + user = user + ).values_list('question__id', flat=True) #this is meant for the questions answered by the user (or where answers were edited by him/her?) answered_questions = models.Question.objects.extra( @@ -356,7 +335,7 @@ def user_stats(request, user): question_id_set = set() #todo: there may be a better way to do these queries - question_id_set.update([q['id'] for q in questions]) + 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) try: @@ -424,6 +403,7 @@ def user_stats(request, user): 'view_user' : user, 'user_status_for_display': user.get_status_display(soft = True), 'questions' : questions, + 'favorited_myself': favorited_myself, 'answered_questions' : answered_questions, 'up_votes' : up_votes, 'down_votes' : down_votes, @@ -860,53 +840,28 @@ def user_reputation(request, user): return HttpResponse(template.render(context)) def user_favorites(request, user): - questions = models.Question.objects.extra( - select={ - 'score' : 'question.vote_up_count + question.vote_down_count', - 'favorited_myself' : 'SELECT count(*) FROM favorite_question f WHERE f.user_id = %s '+ - 'AND f.question_id = question.id', - 'la_user_id' : 'auth_user.id', - 'la_username' : 'auth_user.username', - 'la_user_gold' : 'auth_user.gold', - 'la_user_silver' : 'auth_user.silver', - 'la_user_bronze' : 'auth_user.bronze', - 'la_user_reputation' : 'auth_user.reputation' - }, - select_params=[user.id], - tables=['question', 'auth_user', 'favorite_question'], - where=['NOT question.deleted AND question.last_activity_by_id = auth_user.id '+ - 'AND favorite_question.question_id = question.id AND favorite_question.user_id = %s'], - params=[user.id], - order_by=['-score', '-question.id'] - ).values('score', - 'favorited_myself', - 'id', - 'title', - 'author_id', - 'added_at', - 'answer_accepted', - 'answer_count', - 'comment_count', - 'view_count', - 'favourite_count', - 'summary', - 'tagnames', - 'vote_up_count', - 'vote_down_count', - 'last_activity_at', - 'la_user_id', - 'la_username', - 'la_user_gold', - 'la_user_silver', - 'la_user_bronze', - 'la_user_reputation') - + favorited_q_id_list= models.FavoriteQuestion.objects.filter( + user = user + ).values_list('question__id', flat=True) + questions = models.Question.objects.filter( + id__in=favorited_q_id_list + ).order_by( + '-score', '-last_activity_at' + ).select_related( + 'last_activity_by__id', + 'last_activity_by__username', + 'last_activity_by__reputation', + 'last_activity_by__gold', + 'last_activity_by__silver', + 'last_activity_by__bronze' + )[:const.USER_VIEW_DATA_SIZE] data = { 'active_tab':'users', 'tab_name' : 'favorites', 'tab_description' : _('users favorite questions'), 'page_title' : _('profile - favorite questions'), - 'questions' : questions[:const.USER_VIEW_DATA_SIZE], + 'questions' : questions, + 'favorited_myself': favorited_q_id_list, 'view_user' : user } context = RequestContext(request, data) |