示例#1
0
 def test(self, request, *args, **kwargs):
     assert issubclass(self.get_serializer_class(),
                       serializers.EmptySerializer)
     response = request.session.get(0, "OK")
     request.session[0] = "OK"
     request.session.save()
     return responses.HTTP_200_OK(response)
示例#2
0
 def update(self, request: drf_request.Request, *args, **kwargs):
     partial = kwargs.pop('partial', False)
     instance = self.get_object()
     serializer = self.get_serializer(instance, data=request.data, partial=partial)
     serializer.is_valid(raise_exception=True)
     self.perform_update(serializer)
     return responses.HTTP_200_OK(serializer.data)
示例#3
0
    def _settings(self, request: drf_request.Request, *args, **kwargs):
        instance, _ = UserSettings.objects.get_or_create(
            user=self.get_object(),
            defaults=SimpleLazyObject(lambda: {'value': self.get_serializer({}).data})  # type: ignore
        )

        if request.method.upper() == 'PUT':  # type: ignore
            serializer = self.get_serializer(instance.value, data=request.data)
            serializer.is_valid(raise_exception=True)
            instance.value = serializer.save()
            instance.save()
        else:
            serializer = self.get_serializer(instance.value)

        return responses.HTTP_200_OK(serializer.data)
示例#4
0
    def twofa(self, request: drf_request.Request, *args, **kwargs):
        user: User = self.get_object()  # type: ignore
        instance = getattr(user, 'twofa', None)

        if request.method.upper() == 'PUT':  # type: ignore
            serializer = self.get_serializer(instance, data=request.data)
            serializer.is_valid(raise_exception=True)
            serializer.save(user=user)
            request.session['2fa'] = True
        else:
            serializer = self.get_serializer(
                instance or
                SimpleLazyObject(lambda: TwoFactor(user=user))
            )

        return responses.HTTP_200_OK(serializer.data)
示例#5
0
文件: views.py 项目: Lesiuk/vstutils
 def list(self, request):
     start_time = time.time()
     headers = request._request.META
     # Don't send wsgi.* headers
     headers = {
         k: v
         for k, v in headers.items() if not k.startswith('wsgi.')
     }
     serializer = DataSerializer(data=json.dumps(
         dict(headers=headers,
              query=request.query_params,
              user_id=request.user.id)))
     serializer.is_valid(raise_exception=True)
     request._request.is_bulk = False
     return responses.HTTP_200_OK(
         serializer.data,
         timings=dict(req=(
             i for i in ['test case', time.time() - start_time]),
                      miss=None))
示例#6
0
文件: hosts.py 项目: Lesiuk/vstutils
 def test(self, request, *args, **kwargs):
     return responses.HTTP_200_OK('OK')
示例#7
0
文件: views.py 项目: Lesiuk/vstutils
 def new_action_detail(self, request, *args, **kwargs):
     return responses.HTTP_200_OK('OK')  # nocv
示例#8
0
文件: views.py 项目: Lesiuk/vstutils
 def test_bulk_perf(self, request, *args, **kwargs):
     time.sleep(0.001)
     return responses.HTTP_200_OK({'id': request.user.id})
示例#9
0
文件: views.py 项目: Lesiuk/vstutils
    def put(self, request):
        data = request.data

        return responses.HTTP_200_OK(data)