|
|
@@ -1,6 +1,6 @@
|
|
1
|
1
|
from django.shortcuts import render
|
|
2
|
2
|
from counter.models import Counter,Reset
|
|
3
|
|
-from babel.dates import format_timedelta
|
|
|
3
|
+from babel.dates import format_timedelta, format_datetime
|
|
4
|
4
|
from datetime import datetime,timedelta
|
|
5
|
5
|
from django import forms
|
|
6
|
6
|
from django.http import HttpResponseRedirect
|
|
|
@@ -83,22 +83,24 @@ def resetCounter(request):
|
|
83
|
83
|
def counter(request, id_counter):
|
|
84
|
84
|
|
|
85
|
85
|
counter = Counter.objects.get(pk=id_counter)
|
|
86
|
|
- resets = Reset.objects.filter(counter=counter)
|
|
87
|
|
- lastReset = resets.order_by('-timestamp')
|
|
|
86
|
+ resets = Reset.objects.filter(counter=counter).order_by('-timestamp')
|
|
88
|
87
|
#Display
|
|
89
|
|
- if (lastReset.count() == 0):
|
|
|
88
|
+ if (resets.count() == 0):
|
|
90
|
89
|
counter.lastReset = Reset()
|
|
91
|
90
|
counter.lastReset.delta = timezero
|
|
92
|
91
|
counter.lastReset.noSeum = True
|
|
93
|
92
|
else:
|
|
94
|
|
- counter.lastReset = lastReset[0]
|
|
|
93
|
+ counter.lastReset = resets[0]
|
|
95
|
94
|
counter.lastReset.noSeum = False
|
|
96
|
95
|
counter.lastReset.delta = datetime.now()-counter.lastReset.timestamp.replace(tzinfo=None)
|
|
97
|
96
|
counter.lastReset.formatted_delta = format_timedelta(counter.lastReset.delta,locale='fr',threshold=1)
|
|
98
|
97
|
|
|
|
98
|
+ for reset in resets:
|
|
|
99
|
+ reset.date = format_datetime(reset.timestamp,locale='fr',format="EEEE dd MMMM Y 'à' HH:mm:ss").capitalize()
|
|
99
|
100
|
###Timeline graph
|
|
100
|
101
|
#Data pre-processing
|
|
101
|
|
- for reset in resets:
|
|
|
102
|
+ resets_graph=resets
|
|
|
103
|
+ for reset in resets_graph:
|
|
102
|
104
|
reset.timestamp={'v' : reset.timestamp.timestamp(), 'f' : "Il y a "+format_timedelta(datetime.now()-reset.timestamp.replace(tzinfo=None),locale='fr',threshold=1) }
|
|
103
|
105
|
reset.Seum={'v' : 0, 'f' : reset.reason}
|
|
104
|
106
|
#Drawing the graph
|
|
|
@@ -113,4 +115,4 @@ def counter(request, id_counter):
|
|
113
|
115
|
'height' : 90
|
|
114
|
116
|
})
|
|
115
|
117
|
|
|
116
|
|
- return render(request,'counterTemplate.html', { 'counter' : counter, 'chart' : chart})
|
|
|
118
|
+ return render(request,'counterTemplate.html', { 'counter' : counter, 'chart' : chart, 'resets' : resets })
|