Fakultas Ilmu Komputer UI

Commit 63200373 authored by rayhan muzakki's avatar rayhan muzakki
Browse files

fixed get_serializer in views so that url will get the update

parent 9e458e95
......@@ -662,40 +662,39 @@ class ProductDetail(generics.RetrieveUpdateDestroyAPIView):
# leave this intact
serializer_class = self.get_serializer_class()
kwargs["context"] = self.get_serializer_context()
instance=self.get_object()
"""
Intercept the request and see if it needs tweaking
"""
if (self.request.data.get("price") != None) and (self.request.data.get("modal") != None):
draft_request_data = self.request.data.copy()
profit= int(self.request.data['price'])-int(self.request.data['modal'])
new_profit={'profit': profit}
draft_request_data.update(new_profit)
kwargs["data"] = draft_request_data
return serializer_class(*args, **kwargs)
else:
if (self.request.data.get("price") != None):
#
# Copy and manipulate the request
draft_request_data = self.request.data.copy()
profit= int(self.request.data['price'])-int(instance.modal)
new_profit={'profit': profit}
draft_request_data.update(new_profit)
kwargs["data"] = draft_request_data
return serializer_class(*args, **kwargs)
elif (self.request.data.get("modal") != None):
if (self.request != None):
if (self.request.data.get("price") != None) and (self.request.data.get("modal") != None):
instance=self.get_object()
draft_request_data = self.request.data.copy()
profit= int(instance.price)-int(self.request.data['modal'])
profit= int(self.request.data['price'])-int(self.request.data['modal'])
new_profit={'profit': profit}
draft_request_data.update(new_profit)
kwargs["data"] = draft_request_data
return serializer_class(*args, **kwargs)
"""
If not mind your own business and move on
"""
else:
if (self.request.data.get("price") != None):
instance=self.get_object()
draft_request_data = self.request.data.copy()
profit= int(self.request.data['price'])-int(instance.modal)
new_profit={'profit': profit}
draft_request_data.update(new_profit)
kwargs["data"] = draft_request_data
return serializer_class(*args, **kwargs)
elif (self.request.data.get("modal") != None):
instance=self.get_object()
draft_request_data = self.request.data.copy()
profit= int(instance.price)-int(self.request.data['modal'])
new_profit={'profit': profit}
draft_request_data.update(new_profit)
kwargs["data"] = draft_request_data
return serializer_class(*args, **kwargs)
return serializer_class(*args, **kwargs)
def partial_update(self, request, *args, **kwargs):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment