Selaa lähdekoodia

Added likes in tooltip for everyone

Denis Merigoux 9 vuotta sitten
vanhempi
commit
b830e71800

+ 2 - 2
counter/templates/counterTemplate.html

@@ -19,11 +19,11 @@
19 19
                 </a>
20 20
                 {% if not counter.lastReset.noSeum %}
21 21
                 {% if counter.alreadyLiked %}
22
-                <span class="pull-right badge">
22
+                <span class="pull-right badge" {% if counter.likeCount > 0 %} data-toggle="tooltip" data-placement="top" title="{{ counter.likersString }}" {% endif %}>
23 23
                     <span class="glyphicon glyphicon-ok"></span>&emsp;{{ counter.likeCount }}
24 24
                 </span>
25 25
                 {% elif counter.id == myCounter.id or counter.lastReset.who.id == myCounter.id %}
26
-                <span class="pull-right badge">
26
+                <span class="pull-right badge" {% if counter.likeCount > 0 %} data-toggle="tooltip" data-placement="top" title="{{ counter.likersString }}" {% endif %}>
27 27
                     <span class="glyphicon glyphicon-fire"></span>&emsp;{{ counter.likeCount }}
28 28
                 </span>
29 29
                 {% else %}

+ 2 - 2
counter/templates/homeTemplate.html

@@ -101,11 +101,11 @@
101 101
 							</a>
102 102
 							{% if not counter.lastReset.noSeum %}
103 103
 							{% if counter.alreadyLiked %}
104
-							<span class="pull-right badge">
104
+							<span class="pull-right badge" {% if counter.likeCount > 0 %} data-toggle="tooltip" data-placement="top" title="{{ counter.likersString }}" {% endif %}>
105 105
 								<span class="glyphicon glyphicon-ok"></span>&emsp;{{ counter.likeCount }}
106 106
 							</span>
107 107
 							{% elif counter.id == myCounter.id or counter.lastReset.who.id == myCounter.id %}
108
-			                <span class="pull-right badge">
108
+			                <span class="pull-right badge" {% if counter.likeCount > 0 %} data-toggle="tooltip" data-placement="top" title="{{ counter.likersString }}" {% endif %}>
109 109
 			                    <span class="glyphicon glyphicon-fire"></span>&emsp;{{ counter.likeCount }}
110 110
 			                </span>
111 111
 							{% else %}

+ 14 - 4
counter/views.py

@@ -109,10 +109,15 @@ def home(request):
109 109
             else:
110 110
                 counter.CSSclass = 'default'
111 111
             # Computing the total number of likes for this counter
112
-            counter.likeCount = Like.objects.filter(
113
-                reset=counter.lastReset).count()
112
+            likesMe = Like.objects.filter(
113
+                reset=counter.lastReset)
114
+            counter.likeCount = likesMe.count()
114 115
             counter.alreadyLiked = (Like.objects.filter(
115 116
                 reset=counter.lastReset, liker=myCounter).exists())
117
+            if counter.likeCount > 0:
118
+                counter.likersString = functools.reduce(
119
+                    lambda a, b: a + ", " + b,
120
+                    [like.liker.trigramme for like in likesMe])
116 121
 
117 122
         counter.lastReset.formatted_delta = format_timedelta(
118 123
             counter.lastReset.delta, locale='fr', threshold=1)
@@ -347,8 +352,13 @@ def counter(request, id_counter):
347 352
             counter.seumCount, locale='fr', threshold=1)
348 353
         counter.alreadyLiked = (Like.objects.filter(
349 354
             reset=counter.lastReset, liker=myCounter).exists())
350
-        counter.likeCount = Like.objects.filter(
351
-            reset=counter.lastReset).count()
355
+        likesMe = Like.objects.filter(
356
+            reset=counter.lastReset)
357
+        counter.likeCount = likesMe.count()
358
+        if counter.likeCount > 0:
359
+            counter.likersString = functools.reduce(
360
+                lambda a, b: a + ", " + b,
361
+                [like.liker.trigramme for like in likesMe])
352 362
 
353 363
     for reset in resets:
354 364
         if (reset.who is None or