Пример #1
0
 def put(self, request, invoice_id):
     payload = json.loads(request.body)
     try:
         invoice = invoice_service.update_invoice(invoice_id, payload)
         serializer = invoice_serializer.InvoiceSerializer(invoice)
         return JsonResponse({'invoice': serializer.data},
                             safe=False,
                             status=status.HTTP_200_OK)
     except ObjectDoesNotExist:
         message = Message.objects.get(code=404)
         return JsonResponse({'error': message.message_en},
                             safe=False,
                             status=status.HTTP_404_NOT_FOUND)
     except Exception:
         message = Message.objects.get(code=500)
         return JsonResponse({'error': message.message_en},
                             safe=False,
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #2
0
 def get(self, request, invoice_id):
     try:
         invoice = Invoice.objects.filter(id=invoice_id)
         invoice = invoice[0]
         serializer = invoice_serializer.InvoiceSerializer(invoice)
         return JsonResponse({'invoice': serializer.data},
                             safe=False,
                             status=status.HTTP_200_OK)
     except ObjectDoesNotExist:
         message = Message.objects.get(code=404)
         return JsonResponse({'error': message.message_en},
                             safe=False,
                             status=status.HTTP_404_NOT_FOUND)
     except Exception:
         message = Message.objects.get(code=500)
         return JsonResponse({'error': message.message_en},
                             safe=False,
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)