Quellcode durchsuchen

Merge pull request #3 from Varal7/feature/show-likes

Show who liked your reset
Denis Merigoux vor 9 Jahren
Ursprung
Commit
5dcde18c83
3 geänderte Dateien mit 16 neuen und 4 gelöschten Zeilen
  1. 1 1
      counter/templates/baseTemplate.html
  2. 7 1
      counter/templates/homeTemplate.html
  3. 8 2
      counter/views.py

+ 1 - 1
counter/templates/baseTemplate.html

@@ -10,7 +10,7 @@
10 10
 	<link rel="shortcut icon" type="image/png" href="{{STATIC_URL}}/favicon.ico" />
11 11
 	<title>SeumBook™ – {% block title %}{% endblock %}</title>
12 12
 
13
-	{# Load the tag library #} {% load bootstrap3 %} {# Load CSS and JavaScript #} {% bootstrap_css %} {# Display django.contrib.messages as Bootstrap alerts #} {% bootstrap_messages %}
13
+	{# Load the tag library #} {% load bootstrap3 %} {# Load CSS and JavaScript #} {% bootstrap_css %} {% bootstrap_javascript jquery=True %} {# Display django.contrib.messages as Bootstrap alerts #} {% bootstrap_messages %}
14 14
 
15 15
 	<style>
16 16
 		body {

+ 7 - 1
counter/templates/homeTemplate.html

@@ -12,7 +12,7 @@
12 12
 							<b>{{ myCounter.trigramme }}</b> <small>{{ myCounter.name }}</small>
13 13
 						</a>
14 14
 						{% if not myCounter.lastReset.noSeum %}
15
-							<span class="pull-right badge">
15
+							<span class="pull-right badge" {% if myCounter.likeCount %} data-toggle="tooltip" data-placement="top" title="{{ myCounter.likersString }}" {% endif %}>
16 16
 								<span class="glyphicon glyphicon-fire"></span>&emsp;{{ myCounter.likeCount }}
17 17
 							</span>
18 18
 						{% endif %}
@@ -212,4 +212,10 @@
212 212
 		{% endif %}
213 213
 	</a>
214 214
 </div>
215
+
216
+<script>
217
+$(function () {
218
+  $('[data-toggle="tooltip"]').tooltip()
219
+})
220
+</script>
215 221
 {% endblock %}

+ 8 - 2
counter/views.py

@@ -16,6 +16,7 @@ from graphos.sources.model import ModelDataSource
16 16
 import random
17 17
 import math
18 18
 import copy
19
+import functools
19 20
 from django.utils import timezone
20 21
 
21 22
 # JSS above this limit will not be displayed on the home page col graph
@@ -51,8 +52,13 @@ def home(request):
51 52
                 myCounter.lastReset.selfSeum = False
52 53
             myCounter.lastReset.delta = datetime.now(
53 54
             ) - myCounter.lastReset.timestamp.replace(tzinfo=None)
54
-            myCounter.likeCount = Like.objects.filter(
55
-                reset=myCounter.lastReset).count()
55
+            likesMe = Like.objects.filter(
56
+                reset=myCounter.lastReset)
57
+            myCounter.likeCount = likesMe.count()
58
+            if myCounter.likeCount:
59
+                myCounter.likersString = functools.reduce(
60
+                            lambda a,b: a + ", " +  b,
61
+                            [like.liker.trigramme for like in likesMe])
56 62
         myCounter.lastReset.formatted_delta = format_timedelta(
57 63
             myCounter.lastReset.delta, locale='fr', threshold=1)
58 64
     except Counter.DoesNotExist: