Add /stats/ API route with defaults

This commit is contained in:
Tanner Collin 2020-02-07 09:25:50 +00:00
parent 5d4ef292d6
commit f75b782afd
3 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,12 @@
import time
DEFAULTS = {
'last_card_change': time.time(),
'next_meeting': None,
'next_clean': None,
'member_count': None,
'due_members': None,
'old_members': None,
'bay_108_temp': None,
'bay_110_temp': None,
}

View File

@ -16,7 +16,7 @@ import datetime
import requests import requests
from . import models, serializers, utils, utils_paypal from . import models, serializers, utils, utils_paypal, utils_stats
from .permissions import ( from .permissions import (
is_admin_director, is_admin_director,
AllowMetadata, AllowMetadata,
@ -312,6 +312,16 @@ class IpnView(views.APIView):
class StatsView(views.APIView):
def get(self, request):
stats_keys = utils_stats.DEFAULTS.keys()
cached_stats = cache.get_many(stats_keys)
stats = utils_stats.DEFAULTS.copy()
stats.update(cached_stats)
return Response(stats)
class RegistrationView(RegisterView): class RegistrationView(RegisterView):
serializer_class = serializers.RegistrationSerializer serializer_class = serializers.RegistrationSerializer

View File

@ -30,5 +30,6 @@ urlpatterns = [
url(r'^password/change/', views.PasswordChangeView.as_view(), name='rest_password_change'), url(r'^password/change/', views.PasswordChangeView.as_view(), name='rest_password_change'),
url(r'^user/', views.UserView.as_view(), name='user'), url(r'^user/', views.UserView.as_view(), name='user'),
url(r'^ping/', views.PingView.as_view(), name='ping'), url(r'^ping/', views.PingView.as_view(), name='ping'),
url(r'^stats/', views.StatsView.as_view(), name='stats'),
url(IPN_ROUTE, views.IpnView.as_view(), name='ipn'), url(IPN_ROUTE, views.IpnView.as_view(), name='ipn'),
] ]