diff --git a/update/urls.py b/update/urls.py index 6cc5324..25c8312 100644 --- a/update/urls.py +++ b/update/urls.py @@ -26,6 +26,7 @@ router.register('user', views.CinemaUserViewSet, 'cinema_user') urlpatterns = [ # path('cinema/search/', views.CinemaSearchAPIView.as_view()), path('', include(router.urls)), + path('update_user/', update_user), path('get_git_version/', get_git_version), path('get_operation_cmd/', get_operation_cmd), # re_path(r'^cinema/search/ip/(?P[0-9.]*?)/version/(?P[\S]*?)/$', views.CinemaSearchAPIView.as_view()) diff --git a/update/views.py b/update/views.py index e7f4c96..ec3f0f9 100644 --- a/update/views.py +++ b/update/views.py @@ -1,3 +1,5 @@ +import json + from django.http import JsonResponse from django.db.models import Q from rest_framework import viewsets, permissions, status, filters @@ -10,6 +12,7 @@ from rest_framework.response import Response from rest_framework_extensions.cache.mixins import CacheResponseMixin from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_page +from django.views.decorators.csrf import csrf_exempt from django_filters.rest_framework import DjangoFilterBackend from django.core.cache import cache from update.utils.get_version import GetVersion @@ -32,7 +35,7 @@ class CinemaViewSet(CacheResponseMixin, viewsets.ModelViewSet): """ queryset = Cinema.objects.all() serializer_class = CinemaSerializer - permission_classes = (permissions.IsAuthenticated,) + # permission_classes = (permissions.IsAuthenticated,) filter_backends = (filters.SearchFilter, DjangoFilterBackend, OrderingFilter) ordering_fields = ('ip',) search_fields = ('sys_ver',) @@ -64,6 +67,14 @@ class CinemaUserViewSet(CacheResponseMixin, viewsets.ModelViewSet): # serializer = CinemaSerializer(instance=query_data, many=True) # return Response(serializer.data, status=status.HTTP_200_OK) +@csrf_exempt +def update_user(request, *args, **kwargs): + cinema_id = request.GET.dict().get('id') + user = json.loads(request.body).get('user', '暂无') + result = Cinema.objects.filter(id=cinema_id).update(user=user) + return JsonResponse({'result': 'success'} if result == 1 else {'result': 'fail'}) + + def get_git_version(request): git_util = GitUtil() git_ver = git_util.get_short_version() @@ -154,4 +165,4 @@ def update_cine(request): # 传输客户端 client_release = ClientUtil() client_release.client_process(cinema_ip, short_release) - return JsonResponse({'result': 'success'}) \ No newline at end of file + return JsonResponse({'result': 'success'})