2022-06-27 15:34:24 +02:00
|
|
|
from asgiref.sync import async_to_sync
|
2017-06-22 15:48:45 +02:00
|
|
|
from django.conf import settings
|
2017-06-21 07:08:28 +02:00
|
|
|
from django.contrib.auth.decorators import permission_required
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.core.exceptions import PermissionDenied
|
2017-06-21 07:08:28 +02:00
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from django.views.decorators.http import require_POST
|
|
|
|
|
|
|
|
from .open import kfet_open
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
TRUE_STR = ["1", "True", "true"]
|
2017-06-21 07:08:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@require_POST
|
|
|
|
def raw_open(request):
|
2018-10-06 12:35:49 +02:00
|
|
|
token = request.POST.get("token")
|
2017-06-22 15:48:45 +02:00
|
|
|
if token != settings.KFETOPEN_TOKEN:
|
|
|
|
raise PermissionDenied
|
2018-10-06 12:35:49 +02:00
|
|
|
raw_open = request.POST.get("raw_open") in TRUE_STR
|
2017-06-21 07:08:28 +02:00
|
|
|
kfet_open.raw_open = raw_open
|
2022-06-27 15:34:24 +02:00
|
|
|
async_to_sync(kfet_open.send_ws)()
|
2017-06-21 07:08:28 +02:00
|
|
|
return HttpResponse()
|
|
|
|
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
@permission_required("kfet.can_force_close", raise_exception=True)
|
2017-06-21 07:08:28 +02:00
|
|
|
@require_POST
|
|
|
|
def force_close(request):
|
2018-10-06 12:35:49 +02:00
|
|
|
force_close = request.POST.get("force_close") in TRUE_STR
|
2017-06-21 07:08:28 +02:00
|
|
|
kfet_open.force_close = force_close
|
2022-06-27 15:34:24 +02:00
|
|
|
async_to_sync(kfet_open.send_ws)()
|
2017-06-21 07:08:28 +02:00
|
|
|
return HttpResponse()
|