Browse Source

wrap up work on polls

Rafał Pitoń 8 years ago
parent
commit
d441e7a2b6

+ 14 - 10
misago/templates/misago/thread/posts/post/footer.html

@@ -1,23 +1,27 @@
-{% load i18n %}
+{% load i18n misago_poststags %}
 {% if post.acl.can_reply or post.acl.can_edit or post.acl.can_see_likes or post.acl.can_like %}
   <div class="panel-footer post-footer">
-    {% if post.acl.can_see_likes %}
-      <button type="button" class="btn btn-likes pull-left" disabled="disabled">
-        Likes
-      </button>
-    {% endif %}
     {% if post.acl.can_like %}
-      <button type="button" class="btn btn-like pull-left" disabled="disabled">
-        {% trans "Like" %}
+      <button type="button" class="btn btn-default pull-left" disabled="disabled">
+        {% if post.is_liked %}
+          {% trans "Unlike" %}
+        {% else %}
+          {% trans "Like" %}
+        {% endif %}
       </button>
     {% endif %}
+    {% if post.acl.can_see_likes and post.last_likes %}
+      <p class="pull-left">
+        {% likes_label post %}
+      </p>
+    {% endif %}
     {% if post.acl.can_reply %}
-      <button type="button" class="btn btn-reply pull-right" disabled="disabled">
+      <button type="button" class="btn btn-default pull-right" disabled="disabled">
         {% trans "Reply" %}
       </button>
     {% endif %}
     {% if post.acl.can_edit %}
-      <button type="button" class="btn btn-edit pull-right" disabled="disabled">
+      <button type="button" class="btn btn-default pull-right" disabled="disabled">
         {% trans "Edit" %}
       </button>
     {% endif %}

+ 0 - 0
misago/threads/templatetags/__init__.py


+ 47 - 0
misago/threads/templatetags/misago_poststags.py

@@ -0,0 +1,47 @@
+from __future__ import unicode_literals
+
+from django import template
+from django.utils.translation import gettext as _, ngettext
+
+from misago.conf import settings
+
+
+register = template.Library()
+
+
+@register.simple_tag
+def likes_label(post):
+    last_likes = post.last_likes or []
+
+    usernames = []
+    for like in last_likes[:3]:
+        usernames.append(like['username'])
+
+    if len(usernames) == 1:
+        return _("%(user)s likes this.") % {'user': usernames[0]}
+
+    hidden_likes = post.likes - len(usernames)
+    usernames_string = humanize_usernames_list(usernames)
+
+    if not hidden_likes:
+        return _("%(users)s like this.") % {'users': usernames_string}
+
+    formats = {
+        'users': usernames_string,
+        'likes': hidden_likes
+    }
+
+    return ngettext(
+        "%(users)s and %(likes)s other user like this.",
+        "%(users)s and %(likes)s other users like this.",
+        hidden_likes
+    ) % formats
+
+
+def humanize_usernames_list(usernames):
+    formats = {
+        'users': ', '.join(usernames[:-1]),
+        'last_user': usernames[-1]
+    }
+
+    return _("%(users)s and %(last_user)s") % formats