Explorar o código

Added likes in tooltip for everyone

Denis Merigoux %!s(int64=9) %!d(string=hai) anos
pai
achega
b830e71800

+ 2 - 2
counter/templates/counterTemplate.html

19
                 </a>
19
                 </a>
20
                 {% if not counter.lastReset.noSeum %}
20
                 {% if not counter.lastReset.noSeum %}
21
                 {% if counter.alreadyLiked %}
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
                     <span class="glyphicon glyphicon-ok"></span>&emsp;{{ counter.likeCount }}
23
                     <span class="glyphicon glyphicon-ok"></span>&emsp;{{ counter.likeCount }}
24
                 </span>
24
                 </span>
25
                 {% elif counter.id == myCounter.id or counter.lastReset.who.id == myCounter.id %}
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
                     <span class="glyphicon glyphicon-fire"></span>&emsp;{{ counter.likeCount }}
27
                     <span class="glyphicon glyphicon-fire"></span>&emsp;{{ counter.likeCount }}
28
                 </span>
28
                 </span>
29
                 {% else %}
29
                 {% else %}

+ 2 - 2
counter/templates/homeTemplate.html

101
 							</a>
101
 							</a>
102
 							{% if not counter.lastReset.noSeum %}
102
 							{% if not counter.lastReset.noSeum %}
103
 							{% if counter.alreadyLiked %}
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
 								<span class="glyphicon glyphicon-ok"></span>&emsp;{{ counter.likeCount }}
105
 								<span class="glyphicon glyphicon-ok"></span>&emsp;{{ counter.likeCount }}
106
 							</span>
106
 							</span>
107
 							{% elif counter.id == myCounter.id or counter.lastReset.who.id == myCounter.id %}
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
 			                    <span class="glyphicon glyphicon-fire"></span>&emsp;{{ counter.likeCount }}
109
 			                    <span class="glyphicon glyphicon-fire"></span>&emsp;{{ counter.likeCount }}
110
 			                </span>
110
 			                </span>
111
 							{% else %}
111
 							{% else %}

+ 14 - 4
counter/views.py

109
             else:
109
             else:
110
                 counter.CSSclass = 'default'
110
                 counter.CSSclass = 'default'
111
             # Computing the total number of likes for this counter
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
             counter.alreadyLiked = (Like.objects.filter(
115
             counter.alreadyLiked = (Like.objects.filter(
115
                 reset=counter.lastReset, liker=myCounter).exists())
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
         counter.lastReset.formatted_delta = format_timedelta(
122
         counter.lastReset.formatted_delta = format_timedelta(
118
             counter.lastReset.delta, locale='fr', threshold=1)
123
             counter.lastReset.delta, locale='fr', threshold=1)
347
             counter.seumCount, locale='fr', threshold=1)
352
             counter.seumCount, locale='fr', threshold=1)
348
         counter.alreadyLiked = (Like.objects.filter(
353
         counter.alreadyLiked = (Like.objects.filter(
349
             reset=counter.lastReset, liker=myCounter).exists())
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
     for reset in resets:
363
     for reset in resets:
354
         if (reset.who is None or
364
         if (reset.who is None or