Python rest_framework.viewsets.GenericViewSet() Examples
The following are 3
code examples of rest_framework.viewsets.GenericViewSet().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.viewsets
, or try the search function
.
Example #1
Source File: views.py From CTF_AWD_Platform with MIT License | 6 votes |
def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) mobile = serializer.validated_data['mobile'] list = [] list.append(mobile) code = self.generate_code() SendCode.SendMail.delay(code, list) code_record = VerifyCode(code=code, mobile=mobile, type='email') code_record.save() return Response({ "mobile": mobile }, status=status.HTTP_201_CREATED) # class UserLogViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
Example #2
Source File: initialize.py From cmdb with GNU Lesser General Public License v3.0 | 6 votes |
def add_viewset(table): data_index = table.name record_data_index = "{}.".format(table.name) deleted_data_index = "{}..".format(table.name) def retrieve(self, request, *args, **kwargs): try: res = es.search(index=record_data_index, doc_type="record-data", body={"query": {"term": {"S-data-id": kwargs["pk"]}}}, sort="S-update-time:desc") except NotFoundError as exc: raise exceptions.NotFound("Document {} was not found in Type data of Index {}".format(kwargs["pk"], record_data_index)) except TransportError as exc: return Response([]) return Response(res["hits"]) viewset = type(table.name, (mixins.RetrieveModelMixin, viewsets.GenericViewSet), dict( permission_classes=(permissions.IsAuthenticated, ), retrieve=retrieve)) setattr(views, table.name, viewset) return viewset
Example #3
Source File: initialize.py From cmdb with GNU Lesser General Public License v3.0 | 6 votes |
def add_viewset(table): data_index = table.name record_data_index = "{}.".format(table.name) deleted_data_index = "{}..".format(table.name) def list(self, request, *args, **kwargs): page = int(request.query_params.get("page", 1)) page_size = int(request.query_params.get("page_size", 10)) try: res = es.search(index=deleted_data_index, doc_type="deleted-data", size=page_size, from_=(page-1)*page_size) except Exception as exc: raise exceptions.APIException("内部错误,错误类型: {}".format(type(exc))) return Response(res["hits"]) def retrieve(self, request, *args, **kwargs): try: res = es.get(index=deleted_data_index, doc_type="data", id=kwargs["pk"]) except NotFoundError as exc: raise exceptions.NotFound("Document {} was not found in Type {} of Index {}".format(kwargs["pk"], "data", table.name)) viewset = type(table.name, (mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet), dict(permission_classes=(c_permissions.TableLevelPermission, ), list=list, retrieve=retrieve)) setattr(views, table.name, viewset) return viewset