adding KFET_FORCE_CLOSE in cache

This commit is contained in:
Qwann 2017-03-06 02:25:18 +01:00
parent 8e462134c7
commit b7040d5867
3 changed files with 17 additions and 6 deletions

View file

@ -5,7 +5,7 @@ from __future__ import (absolute_import, division,
from builtins import *
from django.contrib.auth.context_processors import PermWrapper
from .views import KFET_OPEN
from .views import KFET_OPEN, KFET_FORCE_CLOSE
def auth(request):
@ -19,7 +19,9 @@ def auth(request):
def kfet_open(resquest):
(kfet_open, kfet_open_date) = KFET_OPEN()
kfet_force_close = KFET_FORCE_CLOSE()
return {
'kfet_open': kfet_open,
'kfet_open_date': kfet_open_date,
'kfet_force_close': kfet_force_close,
}

View file

@ -204,6 +204,11 @@ urlpatterns = [
permission_required('kfet.change_settings')
(views.SettingsUpdate.as_view()),
name='kfet.settings.update'),
# -----
# K-Fêt Open urls
# -----
url('^settings/kfet_open/$',
views.UpdateKfetOpen.as_view(),
name='kfet.settings.kfet_open'),

View file

@ -13,7 +13,7 @@ from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.models import User, Permission, Group
from django.http import JsonResponse, Http404
from django.http import JsonResponse, Http404, HttpResponse
from django.forms import formset_factory
from django.db import transaction
from django.db.models import F, Sum, Prefetch, Count
@ -67,7 +67,6 @@ class Home(TemplateView):
return super(TemplateView, self).dispatch(*args, **kwargs)
def KFET_OPEN():
kfet_open_date = cache.get('KFET_OPEN_DATE')
kfet_open = cache.get('KFET_OPEN')
@ -80,22 +79,27 @@ def KFET_OPEN():
return (kfet_open, kfet_open_date)
def KFET_FORCE_CLOSE():
kfet_force_close = cache.get('KFET_FORCE_CLOSE')
if not kfet_force_close:
kfet_force_close = False
cache.set('KFET_FORCE_CLOSE', kfet_force_close)
return kfet_force_close
class UpdateKfetOpen(View):
def get(self, request, *args, **kwargs):
is_open = "open" in request.GET
cache.set('KFET_OPEN', is_open)
cache.set('KFET_OPEN_DATE', timezone.now())
# <debug, delete me ?>
# Websocket
websocket_data = {}
websocket_data['kfet_open'] = is_open
websocket_data['kfet_open_date'] = timezone.now()
print(timezone.now())
consumers.KfetOpen.group_send('kfet.is_open', websocket_data)
(is_open_get, time) = KFET_OPEN()
# </debug, delete me?>
return HttpResponse("%r at %s" % (is_open_get, time.isoformat()))