Пример #1
0
 def put(self, request, expense_id):
     payload = json.loads(request.body)
     try:
         expense = expense_service.update_expense(expense_id, payload)
         serializer = expense_serializer.ExpenseSerializer(expense)
         return JsonResponse({'expense': 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, expense_id):
     try:
         expense = Expense.objects.filter(id=expense_id)
         expense = expense[0]
         serializer = expense_serializer.ExpenseSerializer(expense)
         return JsonResponse({'expense': 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)