def put(self, request, pk, format=None): import pdb;pdb.set_trace() rule = get_object(pk) serializer = RuleSerializer(data=request.data) if serializer.is_valid(): serializer.save() filelocation = serializer.instance.datafile.path serializer.instance.filelocation=filelocation serializer.instance.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): import pdb pdb.set_trace() rule = get_object(pk) serializer = RuleSerializer(data=request.data) if serializer.is_valid(): serializer.save() filelocation = serializer.instance.datafile.path serializer.instance.filelocation = filelocation serializer.instance.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def create(self, request, format=None): datafile = request.FILES.get("datafile") if not datafile: return Response(status=404) # request.data.pop("datafile") serializer = RuleSerializer(data=request.data) if serializer.is_valid(): serializer.save() filelocation = serializer.instance.datafile.path serializer.instance.filelocation = filelocation serializer.instance.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def create(self, request, format=None): datafile = request.FILES.get('datafile') if not datafile: return Response(status=404) #request.data.pop("datafile") serializer = RuleSerializer(data=request.data) if serializer.is_valid(): serializer.save() filelocation = serializer.instance.datafile.path serializer.instance.filelocation=filelocation serializer.instance.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, pk, format=None): cluster = Cluster.objects.get(pk=pk) rules = Rule.objects.filter(cluster=cluster) data = request.data data['cluster'] = pk data['step1'] = Crush.objects.get(crush_id=data['step1'], cluster=cluster).id for rule in rules: if rule.rule_id == request.data['rule_id']: serializer = RuleSerializer(rule, data=data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) serializer = RuleSerializer(data=data) if serializer.is_valid(): serializer.save() return Response(serializer.data) print serializer.errors return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, pk, format=None): cluster = Cluster.objects.get(pk=pk) rules = Rule.objects.filter(cluster=cluster) serializer = RuleSerializer(rules, many=True) return Response(serializer.data, status=status.HTTP_200_OK)
def get(self, request, pk, format=None): rule = get_object(pk) serializer = RuleSerializer(rule) return Response(serializer.data)