color: #666666;
}
+.short-summary .favorites {
+ width: 24px;
+ float: left;
+ text-align: center;
+}
+
#question-table {
margin-bottom: 10px;
}
color: #314362;
}
-.answered-accepted {
+.answer-votes.answered-accepted {
background: none repeat scroll 0 0 #E6F8DD;
color: #3A6231;
}
color: #333333;
font-size: 110%;
font-weight: bold;
+ margin-left: 3px;
}
.footerLinks {
text-decoration: none;
}
-a.post-vote, a.favorite-mark, a.accept-answer {
+a.post-vote, .favorite-mark, a.accept-answer {
display: block;
height: 24px;
position: relative;
padding: 0 0 3px;
}
-a.favorite-mark {
+.favorite-mark {
background: url("/m/default/media/images/vote-favorite-off.png") no-repeat scroll center center transparent;
}
-a.favorite-mark.on, a.favorite-mark:hover {
+.favorite-mark.on, a.favorite-mark:hover {
background: url("/m/default/media/images/vote-favorite-on.png") no-repeat scroll center center transparent;
}
{% load i18n humanize extra_filters extra_tags user_tags %}\r
<div class="short-summary">\r
- <div class="counts">\r
- <div class="votes">\r
+ <div class="counts">{% if favorite_count %}\r
+ <div class="favorites">\r
+ <span class="favorite-mark{% if question.favourite_count %} on{% endif %}"></span>\r
+ <div class="item-count">{{question.favourite_count|intcomma}}</div>\r
+ </div>\r
+ {% endif %}<div class="votes">\r
<div class="item-count">{{question.score|intcomma}}</div>\r
<div>{% trans "votes" %}</div>\r
</div >\r
</div>\r
</div>\r
\r
- <h2><a title="{{question.summary}}" href="{{ question.get_absolute_url }}">{{question.title}}</a></h2>\r
+ <h2><a title="{{question.summary.split|join:" "}}" href="{{ question.get_absolute_url }}">{{question.title}}</a></h2>\r
<div class="userinfo">\r
<span class="relativetime" title="{{question.last_activity_at}}">{% diff_date question.last_activity_at %}</span>\r
- {% if question.last_activity_by %}{% user_signature_small_lite question.last_activity_by %}{% endif %}\r
+ {% if question.last_activity_by %}{% user_signature question.last_activity_by signature_type %}{% endif %}\r
</div>\r
\r
<div class="tags">{% for tag in question.tagname_list %}\r
+++ /dev/null
-{% load i18n %}\r
-{% load humanize %}\r
-{% load extra_filters %}\r
-{% load extra_tags %}\r
-{% load user_tags %}\r
-\r
-<div class="short-summary">\r
- <div class="counts">\r
- <div class="favorites">\r
- <span class="favorite-mark{% if question.favourite_count %} on{% endif %}"></span>\r
- <div class="item-count">{{question.favourite_count|intcomma}}</div>\r
- </div>\r
- <div class="votes">\r
- <div class="item-count">{{question.score|intcomma}}</div>\r
- <div>{% trans "votes" %}</div>\r
- </div>\r
- <div {% if question.answer_accepted %}title="{% trans "this answer has been accepted to be correct" %}"{% endif %} class="status {% if question.answer_accepted %}answered-accepted{% endif %} {% ifequal question.answer_count 0 %}unanswered{% endifequal %}{% ifnotequal question.answer_count 0 %}answered{% endifnotequal %}">\r
- <div class="item-count">{{question.answer_count|intcomma}}</div>\r
- <div>{% trans "answers" %}</div>\r
- </div>\r
- <div class="views">\r
- <div class="item-count">{{question.view_count|cnprog_intword|safe}}</div>\r
- <div>{% trans "views" %}</div>\r
- </div>\r
- </div>\r
-\r
- <h2><a title="{{question.summary}}" href="{{ question.get_absolute_url }}">{{question.title}}</a></h2>\r
- <div class="userinfo">\r
- <span class="relativetime" title="{{question.last_activity_at}}">{% diff_date question.last_activity_at %}</span>\r
- {% if question.last_activity_by %}\r
- {% user_signature_small_full question.last_activity_by %}\r
- {% endif %}\r
- </div>\r
-\r
- <div class="tags">\r
- {% for tag in question.tagname_list %}\r
- <a href="{% url tag_questions tag|urlencode %}" title="{% trans "see questions tagged" %} '{{ tag }}' {% trans "using tags" %}" rel="tag">{{ tag }}</a>\r
- {% endfor %}\r
- </div>\r
-</div>
\ No newline at end of file
{% question_list_title %}\r
{% question_sort_tabs sort_context %}\r
</div>\r
-<div id="listA">\r
-{% for question in questions %}\r
+<div id="listA">{% for question in questions %}\r
{% question_list_item question %}\r
-{% endfor %}\r
-</div>\r
+{% endfor %}</div>\r
{% endblock %}\r
\r
{% block tail %}\r
{% endspaceless %}
<div class="user-stats-table">
{% for question in questions %}
- {% question_list_item_extended question %}
+ {% question_list_item question favorite_count=yes signature_type=badges %}
{% endfor %}
</div>
<br clear="all"/>
<a name="answers"></a>
{% spaceless %}
<h2>
- {% blocktrans count answered_questions|length as counter %}
+ {% blocktrans count answers|length as counter %}
<span class="count">1</span> Answer
{% plural %}
<span class="count">{{counter}}</span> Answers
</h2>
{% endspaceless %}
<div class="user-stats-table">
- {% for answered_question in answered_questions %}
+ {% for answer in answers %}
<div class="answer-summary">
- <a title="{{answered_question.summary|collapse}}"
- href="{{ answered_question.get_absolute_url }}#{{answered_question.answer_id}}">
- <span class="answer-votes {% if answered_question.accepted %}answered-accepted{% endif %}"
- title="{% blocktrans with answered_question.vote_count as vote_count %}the answer has been voted for {{ vote_count }} times{% endblocktrans %} {% if answered_question.accepted %}{% trans "this answer has been selected as correct" %}{%endif%}">
- {{ answered_question.vote_count }}
+ <a title="{{answer.question.title}}"
+ href="{{ answer.get_absolute_url }}">
+ <span class="{% if answer.accepted %}answered-accepted {% endif %} answer-votes"
+ title="{% blocktrans with answer.score as vote_count %}the answer has been voted for {{ vote_count }} times{% endblocktrans %} {% if answer.accepted %}{% trans "this answer has been selected as correct" %}{%endif%}">
+ {{ answer.score }}
</span>
</a>
<div class="answer-link">
{% spaceless %}
- <a href="{{ answered_question.get_absolute_url }}#{{answered_question.answer_id}}">{{answered_question.title}}</a>
+ <a href="{{ answer.get_absolute_url }}#{{answer.id}}">{{answer.question.title}}</a>
{% endspaceless %}
- {% if answered_question.comment_count %}
+ {% if answer.comment_count %}
<span>
- {% blocktrans count answered_question.comment_count as comment_count %}
+ {% blocktrans count answer.comment_count as comment_count %}
(one comment)
{% plural %}
the answer has been commented {{comment_count}} times
+++ /dev/null
-{% load i18n %}\r
-\r
-{% spaceless %}\r
- {% include "users/info_small_lite.html" %}\r
- {% if gold %}\r
- <span title="{{ gold }} {% trans "badges" %}">\r
- <span class="badge1">●</span>\r
- <span class="badgecount">{{ gold }}</span>\r
- </span>\r
- {% endif %}\r
- {% if silver %}\r
- <span title="{{ silver }} {% trans "badges" %}">\r
- <span class="silver">●</span>\r
- <span class="badgecount">{{ silver }}</span>\r
- </span>\r
- {% endif %}\r
- {% if bronze %}\r
- <span title="{{ bronze }} {% trans "badges" %}">\r
- <span class="bronze">●</span>\r
- <span class="badgecount">{{ bronze }}</span>\r
- </span>\r
- {% endif %}\r
-{% endspaceless %}
\ No newline at end of file
+++ /dev/null
-{% load i18n %}<a href="{{ url }}">{{ name }}</a> <span class="score" title="{{ reputation }} {% trans "reputation" %}">{{ reputation }}</span>
\ No newline at end of file
--- /dev/null
+{% load i18n %}{% spaceless %}\r
+{% ifequal format "full" %}\r
+\r
+{% else %}\r
+ <a href="{{ user.get_absolute_url }}">{{ user.username }}</a>\r
+ <span class="score" title="{{ user.reputation }} {% trans "reputation" %}">{{ user.reputation }}</span>\r
+ {% ifequal format "badges" %}\r
+ {% if user.gold %}\r
+ <span title="{{ user.gold }} {% trans "badges" %}">\r
+ <span class="badge1">●</span>\r
+ <span class="badgecount">{{ user.gold }}</span>\r
+ </span>\r
+ {% endif %}\r
+ {% if user.silver %}\r
+ <span title="{{ user.silver }} {% trans "badges" %}">\r
+ <span class="silver">●</span>\r
+ <span class="badgecount">{{ user.silver }}</span>\r
+ </span>\r
+ {% endif %}\r
+ {% if user.bronze %}\r
+ <span title="{{ user.bronze }} {% trans "badges" %}">\r
+ <span class="bronze">●</span>\r
+ <span class="badgecount">{{ user.bronze }}</span>\r
+ </span>\r
+ {% endif %}\r
+ {% endifequal %}\r
+{% endifequal %}\r
+{% endspaceless %}
\ No newline at end of file
+import re\r
+\r
+splitter = re.compile(r'\s*=\s*')\r
+matcher = re.compile(r'^.+=.+$')\r
+\r
+def argument_parser(arguments):\r
+ return dict(splitter.split(s) for s in arguments if matcher.match(s))
\ No newline at end of file
from django.utils.translation import ugettext as _\r
from django.utils.safestring import mark_safe\r
from forum.models import Tag, MarkedTag\r
+from forum.templatetags import argument_parser\r
\r
register = template.Library()\r
\r
-@register.inclusion_tag('question_list/item.html')\r
-def question_list_item(question):\r
- return {'question': question}\r
+class QuestionItemNode(template.Node):\r
+ template = template.loader.get_template('question_list/item.html')\r
\r
-@register.inclusion_tag('question_list/item_extended.html')\r
-def question_list_item_extended(question):\r
- return {'question': question}\r
+ def __init__(self, question, options):\r
+ self.question = template.Variable(question)\r
+ self.options = options\r
+\r
+ def render(self, context):\r
+ return self.template.render(template.Context({\r
+ 'question': self.question.resolve(context),\r
+ 'favorite_count': self.options.get('favorite_count', 'no') == 'yes',\r
+ 'signature_type': self.options.get('signature_type', 'lite'),\r
+ }))\r
+\r
+@register.tag\r
+def question_list_item(parser, token):\r
+ tokens = token.split_contents()[1:]\r
+ return QuestionItemNode(tokens[0], argument_parser(tokens[1:]))\r
+ \r
\r
@register.inclusion_tag('question_list/sort_tabs.html')\r
def question_sort_tabs(sort_context):\r
\r
register = template.Library()\r
\r
+class UserSignatureNode(template.Node):\r
+ template = template.loader.get_template('users/signature.html')\r
\r
-@register.inclusion_tag('users/info_small_lite.html')\r
-def user_signature_small_lite(user):\r
- return {\r
- 'name': user.username,\r
- 'url': user.get_absolute_url(),\r
- 'reputation': user.reputation,\r
- }\r
+ def __init__(self, user, format):\r
+ self.user = template.Variable(user)\r
+ self.format = template.Variable(format)\r
\r
-@register.inclusion_tag('users/info_small_full.html')\r
-def user_signature_small_full(user):\r
- return {\r
- 'name': user.username,\r
- 'url': user.get_absolute_url(),\r
- 'reputation': user.reputation,\r
- 'bronze': user.bronze,\r
- 'silver': user.silver,\r
- 'gold': user.gold\r
- }\r
- pass
\ No newline at end of file
+ def render(self, context):\r
+ return self.template.render(template.Context({\r
+ 'user': self.user.resolve(context),\r
+ 'format': self.format.resolve(context)\r
+ }))\r
+\r
+@register.tag \r
+def user_signature(parser, token):\r
+ try:\r
+ tag_name, user, format = token.split_contents()\r
+ except ValueError:\r
+ raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]\r
+\r
+ return UserSignatureNode(user, format)\r
from django.contrib.auth.decorators import login_required\r
from forum.models import User\r
+from django.db.models import Q, Count\r
from django.core.paginator import Paginator, EmptyPage, InvalidPage\r
from django.template.defaultfilters import slugify\r
from django.contrib.contenttypes.models import ContentType\r
def user_stats(request, user_id, user_view):\r
user = get_object_or_404(User, id=user_id)\r
\r
- questions = Question.objects.filter(deleted=False, author=user).order_by('-added_at')\r
-\r
- answered_questions = Question.objects.filter(deleted=False, answers__author=user).distinct()\r
-\r
- """answered_questions = Question.objects.extra(\r
- select={\r
- 'vote_up_count' : 'answer.vote_up_count',\r
- 'vote_down_count' : 'answer.vote_down_count',\r
- 'answer_id' : 'answer.id',\r
- 'accepted' : 'answer.accepted',\r
- 'vote_count' : 'answer.score',\r
- 'comment_count' : 'answer.comment_count'\r
- },\r
- tables=['question', 'answer'],\r
- where=['NOT answer.deleted AND NOT question.deleted AND answer.author_id=%s AND answer.question_id=question.id'],\r
- params=[user_id],\r
- order_by=['-vote_count', '-answer_id'],\r
- select_params=[user_id]\r
- ).distinct().values('comment_count',\r
- 'id',\r
- 'answer_id',\r
- 'title',\r
- 'author_id',\r
- 'accepted',\r
- 'vote_count',\r
- 'answer_count',\r
- 'vote_up_count',\r
- 'vote_down_count')[:100]"""\r
+ questions = user.questions.filter(deleted=False).order_by('-added_at')\r
+ answers = user.answers.filter(deleted=False).order_by('-added_at')\r
\r
up_votes = user.get_up_vote_count()\r
down_votes = user.get_down_vote_count()\r
votes_today = user.get_vote_count_today()\r
votes_total = int(settings.MAX_VOTES_PER_DAY)\r
\r
- #question_id_set = set(map(lambda v: v['id'], list(questions))) \\r
- # | set(map(lambda v: v['id'], list(answered_questions)))\r
+ user_tags = Tag.objects.filter(Q(questions__author=user) | Q(questions__answers__author=user)) \\r
+ .annotate(user_tag_usage_count=Count('name')).order_by('-user_tag_usage_count')\r
\r
- user_tags = Tag.objects.filter(questions__author=user)\r
- try:\r
- from django.db.models import Count\r
- awards = Award.objects.extra(\r
- select={'id': 'badge.id', \r
- 'name':'badge.name', \r
- 'description': 'badge.description', \r
- 'type': 'badge.type'},\r
- tables=['award', 'badge'],\r
- order_by=['-awarded_at'],\r
- where=['user_id=%s AND badge_id=badge.id'],\r
- params=[user.id]\r
- ).values('id', 'name', 'description', 'type')\r
- total_awards = awards.count()\r
- awards = awards.annotate(count = Count('badge__id'))\r
- user_tags = user_tags.annotate(user_tag_usage_count=Count('name'))\r
-\r
- except ImportError:\r
- awards = Award.objects.extra(\r
- select={'id': 'badge.id', \r
- 'count': 'count(badge_id)', \r
- 'name':'badge.name', \r
- 'description': 'badge.description', \r
- 'type': 'badge.type'},\r
- tables=['award', 'badge'],\r
- order_by=['-awarded_at'],\r
- where=['user_id=%s AND badge_id=badge.id'],\r
- params=[user.id]\r
- ).values('id', 'count', 'name', 'description', 'type')\r
- total_awards = awards.count()\r
- awards.query.group_by = ['badge_id']\r
-\r
- user_tags = user_tags.extra(\r
- select={'user_tag_usage_count': 'COUNT(1)',},\r
- order_by=['-user_tag_usage_count'],\r
- )\r
- user_tags.query.group_by = ['name']\r
+ awards = Badge.objects.filter(award_badge__user=user).annotate(count=Count('name')).order_by('-count')\r
\r
if request.user.is_superuser:\r
moderate_user_form = ModerateUserForm(instance=user)\r
"page_title" : user_view.page_title,\r
"view_user" : user,\r
"questions" : questions,\r
- "answered_questions" : answered_questions,\r
+ "answers" : answers,\r
"up_votes" : up_votes,\r
"down_votes" : down_votes,\r
"total_votes": up_votes + down_votes,\r
"votes_total_per_day": votes_total,\r
"user_tags" : user_tags[:50],\r
"awards": awards,\r
- "total_awards" : total_awards,\r
+ "total_awards" : awards.count(),\r
}, context_instance=RequestContext(request))\r
\r
def user_recent(request, user_id, user_view):\r
def __init__(self, type, title, question_id, answer_id, time, username, user_id, content):\r
self.type = type\r
self.title = title\r
- self.titlelink = reverse('question', args=[question_id]) + u'%s#%s' % (slugify(title), answer_id)\r
+ self.titlelink = reverse('question', kwargs={'id': question_id, 'slug': slugify(title)}) +u'#%s' % answer_id\r
self.time = time\r
self.userlink = reverse('users') + u'%s/%s/' % (user_id, username)\r
self.username = username\r