コード例 #1
0
ファイル: port_view.py プロジェクト: mskcc/beagle
 def update(self, request, *args, **kwargs):
     try:
         port = Port.objects.get(id=kwargs.get("pk"))
     except Port.DoesNotExist:
         return Response({"details": "Not Found"},
                         status=status.HTTP_404_NOT_FOUND)
     value = request.data
     if isinstance(port.schema.get("type"), dict):
         if port.schema.get("type").get("type") == "array":
             if port.schema.get("type").get("items") != "File":
                 port.value = {"inputs": value.get("values")}
             else:
                 input_ids = []
                 files = []
                 for val in value.get("values"):
                     try:
                         file = FileRepository.get(id=val)
                     except FileNotFoundException:
                         return Response({"details": "Not Found"},
                                         status=status.HTTP_404_NOT_FOUND)
                     input_ids.append(val)
                     file_val = self._create_file(
                         file, port.schema.get("secondaryFiles"))
                     files.append(file_val)
                 port.value = {"refs": input_ids, "inputs": files}
     else:
         if port.schema.get("type") != "File":
             port.value = {"inputs": value.get("values")}
         else:
             try:
                 file = FileRepository.get(pk=value.get("values")[0])
             except FileNotFoundException:
                 return Response({"details": "Not Found"},
                                 status=status.HTTP_404_NOT_FOUND)
             port.value = {
                 "inputs":
                 self._create_file(file, port.schema.get("secondaryFiles")),
                 "refs":
                 str(file.id),
             }
     port.save()
     response = PortSerializer(port)
     return Response(response.data, status=status.HTTP_200_OK)
コード例 #2
0
ファイル: port_view.py プロジェクト: utkarsh-stark/beagle
 def update(self, request, *args, **kwargs):
     try:
         port = Port.objects.get(id=kwargs.get('pk'))
     except Port.DoesNotExist:
         return Response({'details': 'Not Found'},
                         status=status.HTTP_404_NOT_FOUND)
     value = request.data
     if isinstance(port.schema.get('type'), dict):
         if port.schema.get('type').get('type') == 'array':
             if port.schema.get('type').get('items') != 'File':
                 port.value = {"inputs": value.get('values')}
             else:
                 input_ids = []
                 files = []
                 for val in value.get('values'):
                     try:
                         file = FileRepository.get(id=val)
                     except FileNotFoundException:
                         return Response({'details': 'Not Found'},
                                         status=status.HTTP_404_NOT_FOUND)
                     input_ids.append(val)
                     file_val = self._create_file(
                         file, port.schema.get('secondaryFiles'))
                     files.append(file_val)
                 port.value = {"refs": input_ids, "inputs": files}
     else:
         if port.schema.get('type') != 'File':
             port.value = {"inputs": value.get('values')}
         else:
             try:
                 file = FileRepository.get(pk=value.get('values')[0])
             except FileNotFoundException:
                 return Response({'details': 'Not Found'},
                                 status=status.HTTP_404_NOT_FOUND)
             port.value = {
                 "inputs":
                 self._create_file(file, port.schema.get('secondaryFiles')),
                 "refs":
                 str(file.id)
             }
     port.save()
     response = PortSerializer(port)
     return Response(response.data, status=status.HTTP_200_OK)