1
0

apiviews.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. from drf_yasg.views import get_schema_view
  11. from drf_yasg import openapi
  12. from drf_yasg.utils import swagger_auto_schema
  13. schema_view = get_schema_view(
  14. openapi.Info(
  15. title="ShariX Admin Open API",
  16. default_version='v1',
  17. description="REST API Documentation",
  18. #terms_of_service="https://www.google.com/policies/terms/",
  19. #contact=openapi.Contact(email="contact@snippets.local"),
  20. #license=openapi.License(name="BSD License"),
  21. ),
  22. public=False,
  23. permission_classes=[permissions.IsAuthenticated],
  24. )
  25. class SharixUserMVS(viewsets.ModelViewSet):
  26. queryset = SharixUser.objects.all()
  27. serializer_class = UserSerializer
  28. #permission_classes = [IsOwnerOrReadOnly]
  29. permission_classes = [permissions.IsAuthenticated]
  30. class GroupMVS(viewsets.ModelViewSet):
  31. queryset = Group.objects.all()
  32. serializer_class = GroupSerializer
  33. permission_classes = [permissions.IsAuthenticated]
  34. def update(self, request, *args, **kwargs):
  35. #print(self.request.user.pk)
  36. return super().update(request, *args, **kwargs)
  37. #def get_queryset(self):
  38. #owner_req = self.queryset.filter(wallet=self.request.user.pk)
  39. #return owner_req
  40. def partial_update(self, request, *args, **kwargs):
  41. return super().partial_update(request, *args, **kwargs)
  42. class PhoneSender(APIView):
  43. """
  44. Test description one
  45. """
  46. permission_classes = [permissions.IsAdminUser, permissions.IsAuthenticated]
  47. @swagger_auto_schema(operation_description="Test description two")
  48. def get(self, request, format=None):
  49. return Response({"message": "Для отправки сообщения используйте POST-запрос"})
  50. @swagger_auto_schema(operation_description="Test description three")
  51. def post(self, request, format=None):
  52. cli.send_message("sender", "password", "getter", request.data)
  53. return Response({"message": "Сообщение успешно отправлено!"})