Ejemplo n.º 1
0
 def put(self, request, format=None):
     put_params = QueryDict(request.body)
     post_office = self.get_object(put_params['id'])
     serializer = PostOfficeSerializer(post_office, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 2
0
 def get(self, request, format=None):
     offices = PostOffice.objects.all()
     serializer = PostOfficeSerializer(offices, many=True)
     office_numbers = [
         serializer.data[office]['number']
         for office in range(len(serializer.data))
     ]
     return Response(office_numbers)
Ejemplo n.º 3
0
 def get(self, request, format=None):
     try:
         office_id = request.GET.get("id")
         post_office = PostOffice.objects.get(id=office_id)
         serializer = PostOfficeSerializer(post_office)
         return Response(serializer.data)
     except PostOffice.DoesNotExist:
         raise Http404
Ejemplo n.º 4
0
 def get(self, request, format=None):
     paper_price = request.GET.get("price")
     newspapers = Newspaper.objects.filter(price__gt=paper_price) \
                                   .values_list('id', flat=True)
     office_ids = set(InStock.objects.filter(newspaper_id__in=newspapers) \
                                     .values_list('post_office_id', flat=True))
     post_offices = PostOffice.objects.filter(id__in=office_ids)
     serializer = PostOfficeSerializer(post_offices, many=True)
     if office_ids:
         return Response(serializer.data)
     raise Http404
Ejemplo n.º 5
0
    def get(self, request, format=None):
        name = request.GET.get("name")
        address = request.GET.get("address")

        printhouse = PrintingHouse.objects.get(address=address)
        newspaper = Newspaper.objects.get(name=name)
        office_ids = set(InStock.objects.filter(newspaper_id=newspaper.id) \
                                        .filter(printing_house_id=printhouse.id)
                                        .values_list('post_office_id', flat=True))
        post_offices = PostOffice.objects.filter(id__in=office_ids)
        serializer = PostOfficeSerializer(post_offices, many=True)
        if office_ids:
            return Response(serializer.data)
        raise Http404
Ejemplo n.º 6
0
 def get(self, request, format=None):
     print_run = request.GET.get("print_run")
     response = {'data': []}
     paper_ids = InStock.objects.filter(print_run__lt=print_run) \
                                .values_list('newspaper_id', flat=True)
     office_ids = InStock.objects.filter(print_run__lt=print_run) \
                                 .values_list('post_office_id', flat=True)
     for i in range(len(paper_ids)):
         newspaper = NewspaperSerializer(
             Newspaper.objects.get(id=paper_ids[i])).data['name']
         post_office = PostOfficeSerializer(
             PostOffice.objects.get(id=office_ids[i])).data['number']
         response['data'].append({
             'newspaper': newspaper,
             'post_office': post_office
         })
     if office_ids and paper_ids:
         return Response(response)
     raise Http404
Ejemplo n.º 7
0
 def post(self, request, format=None):
     serializer = PostOfficeSerializer(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)
Ejemplo n.º 8
0
 def get(self, request, format=None):
     post_offices = PostOffice.objects.all()
     serializer = PostOfficeSerializer(post_offices, many=True)
     return Response(serializer.data)