apiviews.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #REST API ---------------------------
  2. from .serializer import *
  3. from rest_framework import viewsets, permissions, exceptions
  4. from rest_framework.authentication import TokenAuthentication
  5. from rest_framework.decorators import action
  6. from SharixAdmin.models import *
  7. from rest_framework.views import APIView
  8. from rest_framework.response import Response
  9. from xmpp import cli
  10. class SharixUserMVS(viewsets.ModelViewSet):
  11. queryset = SharixUser.objects.all()
  12. serializer_class = UserSerializer
  13. #permission_classes = [IsOwnerOrReadOnly]
  14. permission_classes = [permissions.IsAuthenticated]
  15. class GroupMVS(viewsets.ModelViewSet):
  16. queryset = Group.objects.all()
  17. serializer_class = GroupSerializer
  18. permission_classes = [permissions.IsAuthenticated]
  19. def update(self, request, *args, **kwargs):
  20. #print(self.request.user.pk)
  21. return super().update(request, *args, **kwargs)
  22. #def get_queryset(self):
  23. #owner_req = self.queryset.filter(wallet=self.request.user.pk)
  24. #return owner_req
  25. def partial_update(self, request, *args, **kwargs):
  26. return super().partial_update(request, *args, **kwargs)
  27. class PhoneSender(APIView):
  28. permission_classes = [permissions.IsAdminUser, permissions.IsAuthenticated]
  29. def get(self, request, format=None):
  30. return Response({"message": "Для отправки сообщения используйте POST-запрос"})
  31. def post(self, request, format=None):
  32. cli.send_message("sender", "password", "getter", request.data)
  33. return Response({"message": "Сообщение успешно отправлено!"})