Ejemplo n.º 1
0
 def get(self, request, save_id):
     try:
         consumer = lticonsumer.objects.get(
             Q(model_schematic__save_id=save_id) |
             Q(initial_schematic__save_id=save_id))
     except lticonsumer.DoesNotExist:
         return Response(data={"error": "LTIConsumer Not found"},
                         status=status.HTTP_404_NOT_FOUND)
     host = request.get_host()
     save_id = str(save_id)
     init_sch_serialized = StateSaveSerializer(
         instance=consumer.initial_schematic)
     model_sch_serialized = StateSaveSerializer(
         instance=consumer.model_schematic)
     config_url = "http://" + host + "/api/lti/auth/" + save_id + "/"
     response_data = {
         "consumer_key": consumer.consumer_key,
         "secret_key": consumer.secret_key,
         "config_url": config_url,
         "score": consumer.score,
         "initial_schematic": init_sch_serialized.data,
         "model_schematic": model_sch_serialized.data,
         "test_case": consumer.test_case.id if consumer.test_case else None,
         "scored": consumer.scored,
         "id": consumer.id
     }
     return Response(response_data,
                     status=status.HTTP_200_OK)
Ejemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     logger.info('Got POST for state save ')
     serializer = StateSaveSerializer(data=request.data,
                                      context={'request': self.request})
     if serializer.is_valid():
         serializer.save(owner=self.request.user)
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 3
0
    def get(self, request, save_id):

        if isinstance(save_id, uuid.UUID):
            # Check for permissions and sharing settings here
            try:
                saved_state = StateSave.objects.get(save_id=save_id)
            except StateSave.DoesNotExist:
                return Response({'error': 'Does not Exist'},
                                status=status.HTTP_404_NOT_FOUND)

            # Verifies owner
            if self.request.user != saved_state.owner and not saved_state.shared:  # noqa
                return Response({'error': 'not the owner and not shared'},
                                status=status.HTTP_401_UNAUTHORIZED)
            try:
                serialized = StateSaveSerializer(saved_state,
                                                 context={'request': request})
                User = get_user_model()
                owner_name = User.objects.get(id=serialized.data.get('owner'))
                data = {}
                data.update(serialized.data)
                data['owner'] = owner_name.username
                return Response(data)
            except Exception:
                traceback.print_exc()
                return Response({'error': 'Not Able To Serialize'},
                                status=status.HTTP_400_BAD_REQUEST)
        else:
            return Response({'error': 'Invalid sharing state'},
                            status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 4
0
    def post(self, request, save_id, sharing):

        if isinstance(save_id, uuid.UUID):
            # Check for permissions and sharing settings here
            try:
                saved_state = StateSave.objects.get(save_id=save_id)
            except StateSave.DoesNotExist:
                return Response({'error': 'Does not Exist'},
                                status=status.HTTP_404_NOT_FOUND)

            # Verifies owner
            if self.request.user != saved_state.owner:  # noqa
                return Response({'error': 'Not the owner'},
                                status=status.HTTP_401_UNAUTHORIZED)
            try:
                if sharing == 'on':
                    saved_state.shared = True
                elif sharing == 'off':
                    saved_state.shared = False
                else:
                    return Response({'error': 'Invalid sharing state'},
                                    status=status.HTTP_400_BAD_REQUEST)
                saved_state.save()
                serialized = StateSaveSerializer(saved_state)
                return Response(serialized.data)
            except Exception:
                return Response(serialized.error)
        else:
            return Response({'error': 'Invalid sharing state'},
                            status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 5
0
    def post(self, request, save_id):
        if isinstance(save_id, uuid.UUID):
            # Check for permissions and sharing settings here
            try:
                saved_state = StateSave.objects.get(save_id=save_id)
            except StateSave.DoesNotExist:
                return Response({'error': 'Does not Exist'},
                                status=status.HTTP_404_NOT_FOUND)

            # Verifies owner
            if self.request.user != saved_state.owner:  # noqa
                return Response({'error': 'not the owner and not shared'},
                                status=status.HTTP_401_UNAUTHORIZED)

            if not request.data['data_dump'] and not request.data['shared']:
                return Response({'error': 'not a valid PUT request'},
                                status=status.HTTP_406_NOT_ACCEPTABLE)

            try:
                if 'data_dump' in request.data:
                    saved_state.data_dump = request.data['data_dump']
                print(request.data)
                if 'shared' in request.data:
                    saved_state.shared = bool(request.data['shared'])
                saved_state.save()
                serialized = StateSaveSerializer(saved_state)
                return Response(serialized.data)
            except Exception:
                return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': 'Invalid sharing state'},
                            status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 6
0
 def get(self, request):
     saved_state = StateSave.objects.filter(owner=self.request.user)
     try:
         serialized = StateSaveSerializer(saved_state, many=True)
         return Response(serialized.data)
     except Exception:
         return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 7
0
 def get(self, request):
     saved_state = StateSave.objects.filter(
         owner=self.request.user, is_arduino=False).order_by('-save_time')
     # try:
     serialized = StateSaveSerializer(saved_state, many=True)
     return Response(serialized.data)
     # except Exception:
     return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 8
0
 def post(self, request, *args, **kwargs):
     logger.info('Got POST for state save ')
     esim_libraries = None
     if request.data.get('esim_libraries'):
         esim_libraries = json.loads(request.data.get('esim_libraries'))
     img = Base64ImageField(max_length=None, use_url=True)
     filename, content = img.update(request.data['base64_image'])
     state_save = StateSave(
         data_dump=request.data.get('data_dump'),
         description=request.data.get('description'),
         name=request.data.get('name'),
         owner=request.user,
         is_arduino=True if esim_libraries is None else False,
     )
     state_save.base64_image.save(filename, content)
     if esim_libraries:
         state_save.esim_libraries.set(esim_libraries)
     try:
         state_save.save()
         return Response(StateSaveSerializer(state_save).data)
     except Exception:
         return Response(status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 9
0
 def get_active_save(self, obj):
     return StateSaveSerializer(
         obj.statesave_set.get(save_id=obj.statesave_set.first().save_id,
                               branch=obj.active_branch,
                               version=obj.active_version)).data