Beispiel #1
0
 def create(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         try:
             obj_replaced = BillSegment.objects.get(id=request.data['replaced'])
             obj = BillSegment()
             obj.bill_id = request.data['bill']
             obj.author = request.user
             obj.original = False
             obj.content = request.data['content']
             obj.replaced = obj_replaced
             obj.parent = obj_replaced.parent
             obj.number = obj_replaced.number
             obj.type = obj_replaced.type
             obj.save()
             return Response(status=201)
         except Exception as e:
             return Response(status=403, data=e.message)
     elif request.data['token']:
         token = Token.objects.get(key=request.data['token'])
         obj_replaced = BillSegment.objects.get(id=request.data['replaced'])
         obj = BillSegment()
         obj.bill_id = request.data['bill']
         obj.author = token.user
         obj.original = False
         obj.content = request.data['content']
         obj.replaced = obj_replaced
         obj.parent = obj_replaced.parent
         obj.number = obj_replaced.number
         obj.type = obj_replaced.type
         obj.save()
         serializer = SegmentSerializer(obj)
         return JSONResponse(serializer.data, status=201)
     else:
         return Response(serializer._errors, status=status.HTTP_400_BAD_REQUEST)
 def create(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         try:
             obj_replaced = BillSegment.objects.get(
                 id=request.data['replaced'])
             obj = BillSegment()
             obj.bill_id = request.data['bill']
             obj.author = request.user
             obj.original = False
             obj.content = request.data['content']
             obj.replaced = obj_replaced
             obj.parent = obj_replaced.parent
             obj.number = obj_replaced.number
             obj.type = obj_replaced.type
             obj.save()
             return Response(status=201)
         except Exception as e:
             return Response(status=403, data=e.message)
     elif request.data['token']:
         token = Token.objects.get(key=request.data['token'])
         obj_replaced = BillSegment.objects.get(id=request.data['replaced'])
         obj = BillSegment()
         obj.bill_id = request.data['bill']
         obj.author = token.user
         obj.original = False
         obj.content = request.data['content']
         obj.replaced = obj_replaced
         obj.parent = obj_replaced.parent
         obj.number = obj_replaced.number
         obj.type = obj_replaced.type
         obj.save()
         serializer = SegmentSerializer(obj)
         return JSONResponse(serializer.data, status=201)
     else:
         return Response(serializer._errors,
                         status=status.HTTP_400_BAD_REQUEST)
Beispiel #3
0
 def create(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         try:
             obj_replaced = BillSegment.objects.get(id=request.data['replaced'])
             obj = BillSegment()
             obj.bill_id = request.data['bill']
             obj.author = request.user
             obj.original = False
             obj.content = request.data['content']
             obj.replaced = obj_replaced
             obj.parent = obj_replaced.parent
             obj.number = obj_replaced.number
             obj.type = obj_replaced.type
             obj.save()
             return Response(status=201)
         except Exception as e:
             return Response(status=403, data=e.message)
     else:
         return Response(status=403)