def get(self, request, id=None, format=None): if id is not None: person = self.get_object(id) serializer = PersonSerializer(person) else: persons = Person.objects.all() serializer = PersonSerializer(persons, many=True) return Response(serializer.data)
def regist_member(request): if not decode_check_token(request.POST["identify"]): return Response(status=status.HTTP_401_UNAUTHORIZED) serializer = PersonSerializer(data=request.data) if serializer.is_valid(): serializer.save(password=hashlib.md5(request.POST["password"]).hexdigest()) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(status=status.HTTP_201_CREATED)
def regist_member(request): if not decode_check_token(request.POST['identify']): return Response(status=status.HTTP_401_UNAUTHORIZED) serializer = PersonSerializer(data=request.data) if serializer.is_valid(): serializer.save( password=hashlib.md5(request.POST["password"]).hexdigest()) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(status=status.HTTP_201_CREATED)
class WorkflowCompleteSerializer(serializers.ModelSerializer): api_url = serializers.HyperlinkedIdentityField(view_name='workflow-detail', format='html') person = PersonSerializer(many=False, read_only=True) process = ProcessSerializer(many=False, read_only=True) workflow_activites = WorkflowActivitySerializer(many=True, read_only=True) class Meta: model = Workflow fields = ( "api_url", "id", "process", "person", "workflow_activites", "status", ) @staticmethod def setup_eager_loading(queryset): """ Perform necessary eager loading of data. """ queryset = queryset.select_related('person') queryset = queryset.select_related('process') queryset = queryset.prefetch_related( 'workflow_activites', 'workflow_activites__workflow_tasks', 'person__services') return queryset
def get_member(request): try: obj = Person.objects.get( phone_number=request.GET.get('phone_number', '')) except Person.DoesNotExist: return Response(data={'detail': 'person does not exist'}, status=status.HTTP_400_BAD_REQUEST) person = PersonSerializer(obj) data = person.data.copy() del data['token'] del data['password'] return Response(data=data)
def post(self, request, format=None): serializer = PersonSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def person(request, pk=None, search=None, order=None): if request.method == 'GET' and pk==None: """ Returns a JSON response with a listing of person objects """ search = request.query_params.get('search') order = request.query_params.get('order') if (search==None): search = ''; if (order == None or order == ''): order = 'name' people = Person.objects.filter(name__istartswith=search).order_by(order).all() paginator = PageNumberPagination() # From the docs: # The paginate_queryset method is passed the initial queryset # and should return an iterable object that contains only the # data in the requested page. result_page = paginator.paginate_queryset(people, request) # Now we just have to serialize the data serializer = PersonSerializer(result_page, many=True) # From the docs: # The get_paginated_response method is passed the serialized page # data and should return a Response instance. return paginator.get_paginated_response(serializer.data) elif request.method == 'POST': serializer = PersonSerializer(data=request.data) if serializer.is_valid(): serializer.save(photo = get_gravatar_url(serializer.data['email'], size=150)) return Response(serializer.data, status=status.HTTP_201_CREATED) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: person = Person.objects.get(pk=pk) except Person.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = PersonSerializer(person) return Response(serializer.data) elif request.method == 'PUT': serializer = PersonSerializer(person, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) else: return Response(serilizer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': person.delete() serializer = PersonSerializer(person) return Response(serializer.data)
def get(self, request, pk): person = get_object_or_404(Person, pk=pk) data = PersonSerializer(person).data return Response(data)
def get(self, request): people = Person.objects.all()[:20] data = PersonSerializer(people, many=True).data return Response(data)
def person(request): if request.method == 'GET': id = request.GET.get('id') person = Person.objects.filter(pk=id) serializer = PersonSerializer(person, many=True) return Response(data=serializer.data, status=status.HTTP_200_OK)
def persons(): queryset = Person.objects.all() persons = PersonSerializer(queryset, many=True) return persons.data