mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 20:52:20 +01:00
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.views.generic import TemplateView
|
|
from django.core.cache import caches
|
|
from django.shortcuts import render
|
|
|
|
from stats.services import age_text
|
|
|
|
|
|
class StatsView(LoginRequiredMixin, TemplateView):
|
|
template_name = "stats/stats.html"
|
|
|
|
def get(self, request, **kwargs):
|
|
stats_data = caches["default"].get("stats")
|
|
status = 503
|
|
current_age = None
|
|
current_age_text = None
|
|
|
|
if stats_data:
|
|
status = 200
|
|
current_age_text = age_text(stats_data["last_updated"])
|
|
|
|
data = {"stats": stats_data, "current_age": current_age, "current_age_text": current_age_text}
|
|
return render(request, self.template_name, data, status=status)
|
|
|
|
|
|
class UserStatsView(LoginRequiredMixin, TemplateView):
|
|
template_name = "stats/user.html"
|
|
|
|
def get(self, request, **kwargs):
|
|
stats_data = caches["default"].get("userstats_{}".format(request.user.id))
|
|
status = 503
|
|
current_age = None
|
|
current_age_text = None
|
|
|
|
if stats_data:
|
|
status = 200
|
|
current_age_text = age_text(stats_data["last_updated"])
|
|
|
|
data = {"stats": stats_data, "current_age": current_age, "current_age_text": current_age_text}
|
|
return render(request, self.template_name, data, status=status)
|