]> git.openstreetmap.org Git - osqa.git/commitdiff
several fixes in users profile
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 12 Apr 2010 14:04:05 +0000 (14:04 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 12 Apr 2010 14:04:05 +0000 (14:04 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@29 0cfe37f9-358a-4d5e-be75-b63607b5c754

12 files changed:
forum/skins/default/media/style/style.css
forum/skins/default/templates/question_list/item.html
forum/skins/default/templates/question_list/item_extended.html [deleted file]
forum/skins/default/templates/questions.html
forum/skins/default/templates/user_stats.html
forum/skins/default/templates/users/info_small_full.html [deleted file]
forum/skins/default/templates/users/info_small_lite.html [deleted file]
forum/skins/default/templates/users/signature.html [new file with mode: 0644]
forum/templatetags/__init__.py
forum/templatetags/question_list_tags.py
forum/templatetags/user_tags.py
forum/views/users.py

index c7142cf7c73f639785982ca0ecd91a74ebc08823..7c651e6804cd43aa56334169fcb48c1574db08a1 100644 (file)
@@ -530,6 +530,12 @@ blockquote {
     color: #666666;
 }
 
+.short-summary .favorites {
+    width: 24px;
+    float: left;
+    text-align: center;
+}
+
 #question-table {
     margin-bottom: 10px;
 }
@@ -1163,7 +1169,7 @@ div.comments-container, div.comments-container-accepted, div.comments-container-
     color: #314362;
 }
 
-.answered-accepted {
+.answer-votes.answered-accepted {
     background: none repeat scroll 0 0 #E6F8DD;
     color: #3A6231;
 }
@@ -1847,6 +1853,7 @@ div.started .reputation-score {
     color: #333333;
     font-size: 110%;
     font-weight: bold;
+    margin-left: 3px;
 }
 
 .footerLinks {
@@ -2296,7 +2303,7 @@ a.sidebar_button:hover {
     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;
@@ -2335,11 +2342,11 @@ a.accept-answer.on, a.accept-answer:hover {
     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;
 }
 
index ccaca9210be9fe58f70157263ddf3f053abc0dcb..e57391415ca4bfaab31db9ada2afdfbaa5c96055 100644 (file)
@@ -1,7 +1,11 @@
 {% 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
diff --git a/forum/skins/default/templates/question_list/item_extended.html b/forum/skins/default/templates/question_list/item_extended.html
deleted file mode 100644 (file)
index 934c45d..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-{% 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
index ef7df5898610c2113354579d98f23f4b5c2e2842..31644e7e5c24e79cbfc1b2df41f660ecf83ffa27 100644 (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
index bcb67e283747da871ae00c8de43a620543c78492..96a1f36d17723a57b500ce098baf08becd422e53 100644 (file)
         {% 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
diff --git a/forum/skins/default/templates/users/info_small_full.html b/forum/skins/default/templates/users/info_small_full.html
deleted file mode 100644 (file)
index f941d52..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-{% 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">&#9679;</span>\r
-        <span class="badgecount">{{ gold }}</span>\r
-    </span>\r
-    {% endif %}\r
-    {% if silver %}\r
-    <span title="{{ silver }} {% trans "badges" %}">\r
-        <span class="silver">&#9679;</span>\r
-        <span class="badgecount">{{ silver }}</span>\r
-    </span>\r
-    {% endif %}\r
-    {% if bronze %}\r
-    <span title="{{ bronze }} {% trans "badges" %}">\r
-        <span class="bronze">&#9679;</span>\r
-        <span class="badgecount">{{ bronze }}</span>\r
-    </span>\r
-    {% endif %}\r
-{% endspaceless %}
\ No newline at end of file
diff --git a/forum/skins/default/templates/users/info_small_lite.html b/forum/skins/default/templates/users/info_small_lite.html
deleted file mode 100644 (file)
index b54094c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{% load i18n %}<a href="{{ url }}">{{ name }}</a> <span class="score" title="{{ reputation }} {% trans "reputation" %}">{{ reputation }}</span>
\ No newline at end of file
diff --git a/forum/skins/default/templates/users/signature.html b/forum/skins/default/templates/users/signature.html
new file mode 100644 (file)
index 0000000..a34893e
--- /dev/null
@@ -0,0 +1,28 @@
+{% 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">&#9679;</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">&#9679;</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">&#9679;</span>\r
+            <span class="badgecount">{{ user.bronze }}</span>\r
+        </span>\r
+        {% endif %}\r
+    {% endifequal %}\r
+{% endifequal %}\r
+{% endspaceless %}
\ No newline at end of file
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..56a0b8b634c75969412bcaf378551fd7150302f3 100644 (file)
@@ -0,0 +1,7 @@
+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
index 6238bcea6d28ba290dff84e183b97d5dc9659799..72f888b14730d155f726d549fefeded8209112ba 100644 (file)
@@ -2,16 +2,29 @@ from django import template
 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
index 59e86d09c6ca7d6ccdab81e5ea8618d840345521..c880c231d36e7a0e0641a126f117d3f37b573b78 100644 (file)
@@ -2,23 +2,24 @@ from django import template
 \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
index 162ba2d214f8c484e3f5faca54de980dc7812e81..e3dcc08f2e6ca0110d0e01d58a1d00ec1d1d8faa 100644 (file)
@@ -1,5 +1,6 @@
 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
@@ -146,80 +147,18 @@ def edit_user(request, id):
 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
@@ -233,7 +172,7 @@ def user_stats(request, user_id, user_view):
                                 "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
@@ -241,7 +180,7 @@ def user_stats(request, user_id, user_view):
                                 "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
@@ -507,7 +446,7 @@ def user_responses(request, user_id, user_view):
         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