浏览代码

Handle case where no reset yet

Victor Quach 9 年之前
父节点
当前提交
f1ff61530f
共有 2 个文件被更改,包括 5 次插入4 次删除
  1. 1 1
      counter/templates/homeTemplate.html
  2. 4 3
      counter/views.py

+ 1 - 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" data-toggle="tooltip" data-placement="top" title="{{ myCounter.likersString }}">
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 %}

+ 4 - 3
counter/views.py

@@ -55,9 +55,10 @@ def home(request):
55 55
             likesMe = Like.objects.filter(
56 56
                 reset=myCounter.lastReset)
57 57
             myCounter.likeCount = likesMe.count()
58
-            myCounter.likersString = functools.reduce(
59
-                        lambda a,b: a + ", " +  b,
60
-                        [like.liker.trigramme for like in likesMe])
58
+            if myCounter.likeCount:
59
+                myCounter.likersString = functools.reduce(
60
+                            lambda a,b: a + ", " +  b,
61
+                            [like.liker.trigramme for like in likesMe])
61 62
         myCounter.lastReset.formatted_delta = format_timedelta(
62 63
             myCounter.lastReset.delta, locale='fr', threshold=1)
63 64
     except Counter.DoesNotExist: