Exemplo n.º 1
0
 def get(self, request, contract_id):
     try:
         import pdb;
         pdb.set_trace();
         document = Document.objects.get(content_type__model__iexact="Contract", object_id=contract_id)
         serializer = document_serializer.DocumentSerializer(document)
         return JsonResponse(
             {'document': 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
         )
Exemplo n.º 2
0
 def post(self, request, task_id):
     payload = json.loads(request.body)
     try:
         document = task_service.task_document(task_id, payload)
         serializer = document_serializer.DocumentSerializer(document)
         return JsonResponse({'document': serializer.data},
                             safe=False,
                             status=status.HTTP_201_CREATED)
     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)