forked from DGNum/gestioCOF
adding KFET_FORCE_CLOSE in cache
This commit is contained in:
parent
8e462134c7
commit
b7040d5867
3 changed files with 17 additions and 6 deletions
|
@ -5,7 +5,7 @@ from __future__ import (absolute_import, division,
|
||||||
from builtins import *
|
from builtins import *
|
||||||
|
|
||||||
from django.contrib.auth.context_processors import PermWrapper
|
from django.contrib.auth.context_processors import PermWrapper
|
||||||
from .views import KFET_OPEN
|
from .views import KFET_OPEN, KFET_FORCE_CLOSE
|
||||||
|
|
||||||
|
|
||||||
def auth(request):
|
def auth(request):
|
||||||
|
@ -19,7 +19,9 @@ def auth(request):
|
||||||
|
|
||||||
def kfet_open(resquest):
|
def kfet_open(resquest):
|
||||||
(kfet_open, kfet_open_date) = KFET_OPEN()
|
(kfet_open, kfet_open_date) = KFET_OPEN()
|
||||||
|
kfet_force_close = KFET_FORCE_CLOSE()
|
||||||
return {
|
return {
|
||||||
'kfet_open': kfet_open,
|
'kfet_open': kfet_open,
|
||||||
'kfet_open_date': kfet_open_date,
|
'kfet_open_date': kfet_open_date,
|
||||||
|
'kfet_force_close': kfet_force_close,
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,11 @@ urlpatterns = [
|
||||||
permission_required('kfet.change_settings')
|
permission_required('kfet.change_settings')
|
||||||
(views.SettingsUpdate.as_view()),
|
(views.SettingsUpdate.as_view()),
|
||||||
name='kfet.settings.update'),
|
name='kfet.settings.update'),
|
||||||
|
|
||||||
|
# -----
|
||||||
|
# K-Fêt Open urls
|
||||||
|
# -----
|
||||||
|
|
||||||
url('^settings/kfet_open/$',
|
url('^settings/kfet_open/$',
|
||||||
views.UpdateKfetOpen.as_view(),
|
views.UpdateKfetOpen.as_view(),
|
||||||
name='kfet.settings.kfet_open'),
|
name='kfet.settings.kfet_open'),
|
||||||
|
|
|
@ -13,7 +13,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.contrib.auth.models import User, Permission, Group
|
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.forms import formset_factory
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import F, Sum, Prefetch, Count
|
from django.db.models import F, Sum, Prefetch, Count
|
||||||
|
@ -67,7 +67,6 @@ class Home(TemplateView):
|
||||||
return super(TemplateView, self).dispatch(*args, **kwargs)
|
return super(TemplateView, self).dispatch(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def KFET_OPEN():
|
def KFET_OPEN():
|
||||||
kfet_open_date = cache.get('KFET_OPEN_DATE')
|
kfet_open_date = cache.get('KFET_OPEN_DATE')
|
||||||
kfet_open = cache.get('KFET_OPEN')
|
kfet_open = cache.get('KFET_OPEN')
|
||||||
|
@ -80,22 +79,27 @@ def KFET_OPEN():
|
||||||
return (kfet_open, kfet_open_date)
|
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):
|
class UpdateKfetOpen(View):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
is_open = "open" in request.GET
|
is_open = "open" in request.GET
|
||||||
cache.set('KFET_OPEN', is_open)
|
cache.set('KFET_OPEN', is_open)
|
||||||
cache.set('KFET_OPEN_DATE', timezone.now())
|
cache.set('KFET_OPEN_DATE', timezone.now())
|
||||||
# <debug, delete me ?>
|
|
||||||
|
|
||||||
# Websocket
|
# Websocket
|
||||||
websocket_data = {}
|
websocket_data = {}
|
||||||
websocket_data['kfet_open'] = is_open
|
websocket_data['kfet_open'] = is_open
|
||||||
websocket_data['kfet_open_date'] = timezone.now()
|
websocket_data['kfet_open_date'] = timezone.now()
|
||||||
print(timezone.now())
|
|
||||||
consumers.KfetOpen.group_send('kfet.is_open', websocket_data)
|
consumers.KfetOpen.group_send('kfet.is_open', websocket_data)
|
||||||
|
|
||||||
(is_open_get, time) = KFET_OPEN()
|
(is_open_get, time) = KFET_OPEN()
|
||||||
# </debug, delete me?>
|
|
||||||
return HttpResponse("%r at %s" % (is_open_get, time.isoformat()))
|
return HttpResponse("%r at %s" % (is_open_get, time.isoformat()))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue