|
|
|
@ -1,13 +1,14 @@
|
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
# |
|
|
|
|
|
|
|
|
|
from rest_framework.generics import ListCreateAPIView |
|
|
|
|
from rest_framework.generics import ListCreateAPIView, CreateAPIView |
|
|
|
|
from rest_framework.views import APIView, Response |
|
|
|
|
from rest_framework.permissions import AllowAny |
|
|
|
|
|
|
|
|
|
from common.utils import unsign, get_object_or_none |
|
|
|
|
from .models import Terminal |
|
|
|
|
from .serializers import TerminalSerializer |
|
|
|
|
from .models import Terminal, TerminalHeatbeat |
|
|
|
|
from .serializers import TerminalSerializer, TerminalHeatbeatSerializer |
|
|
|
|
from .hands import IsSuperUserOrTerminalUser |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TerminalApi(ListCreateAPIView): |
|
|
|
@ -21,7 +22,7 @@ class TerminalApi(ListCreateAPIView):
|
|
|
|
|
terminal = get_object_or_none(Terminal, name=name) |
|
|
|
|
if terminal: |
|
|
|
|
if terminal.is_accepted and terminal.is_active: |
|
|
|
|
return Response(data={'data': {'name': name, 'ip': terminal.ip}, |
|
|
|
|
return Response(data={'data': {'name': name, 'id': terminal.id}, |
|
|
|
|
'msg': 'Success'}, |
|
|
|
|
status=200) |
|
|
|
|
else: |
|
|
|
@ -36,20 +37,10 @@ class TerminalApi(ListCreateAPIView):
|
|
|
|
|
'msg': 'Need admin accept or active it'}, |
|
|
|
|
status=204) |
|
|
|
|
else: |
|
|
|
|
return Response(data={'error': 'Secrete key invalid'}, status=401) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# class TerminalRegister(APIView): |
|
|
|
|
# def post(self, request, format='json'): |
|
|
|
|
# return Response(data={'hello': request.META.get('REMOTE_ADDR')}) |
|
|
|
|
# name = unsign(request.data.get('name', '')) |
|
|
|
|
# if name: |
|
|
|
|
# terminal = get_object_or_none(Terminal, name=name) |
|
|
|
|
# if terminal: |
|
|
|
|
# return Response(data={'name': name, 'ip': terminal.ip}, status=200) |
|
|
|
|
# else: |
|
|
|
|
# ip = request.Meta.get('X-Real-IP') |
|
|
|
|
# Terminal.objects.create(name=name, ip=request.META.host) |
|
|
|
|
|
|
|
|
|
return Response(data={'msg': 'Secrete key invalid'}, status=401) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TerminalHeatbeatApi(CreateAPIView): |
|
|
|
|
model = TerminalHeatbeat |
|
|
|
|
serializer_class = TerminalHeatbeatSerializer |
|
|
|
|
permission_classes = (IsSuperUserOrTerminalUser,) |
|
|
|
|