mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 21:52:21 +01:00
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from datetime import datetime, timedelta
|
|
|
|
from django.core.cache import caches
|
|
from django.shortcuts import render
|
|
|
|
|
|
def stats(request):
|
|
stats = caches['default'].get('stats')
|
|
status = 503
|
|
current_age = None
|
|
current_age_text = None
|
|
|
|
if stats:
|
|
status = 200
|
|
if 'last_updated' in stats:
|
|
current_age = datetime.now() - stats['last_updated']
|
|
if current_age < timedelta(minutes=1):
|
|
current_age_text = 'Stats were updated less than a minute ago.'
|
|
elif current_age < timedelta(minutes=2):
|
|
current_age_text = 'Stats were updated one minute ago.'
|
|
elif current_age < timedelta(minutes=60):
|
|
minutes = current_age.seconds / 60
|
|
current_age_text = 'Stats were updated {:.0f} minutes ago.'.format(minutes)
|
|
else:
|
|
current_age_text = 'Stats were updated more than an hour ago'
|
|
|
|
data = {'stats': stats, 'current_age': current_age, 'current_age_text': current_age_text}
|
|
return render(request, 'stats/stats.html', data, status=status)
|