def put(self,request,user_id): status=200 userSer=UserSerializer(data=request.DATA) try: userOb=UserDB.objects.get(id=user_id) if userSer.is_valid(): userDict=userSer.data userOb.email=userDict.get('email') userOb.password=userDict.get('password') userOb.firstName=userDict.get('firstName') userOb.lastName=userDict.get('lastName') userOb.save() except Exception,err: detail=str(err) status=500 return Response(data=detail,status=status,content_type='application/json')
def post(self,request): status=200 detail='Registration failure' userSer=UserSerializer(data=request.DATA) try: if userSer.is_valid(): userDict=userSer.data user=UserDB(email=userDict.get('email'),password=userDict.get('password'),firstName=userDict.get('firstName'),lastName=userDict.get('lastName')) user.save() return Response(data=UserSerializer(user).data,status=status,content_type='application/json') else: return Response(data=detail,status=400,content_type='application/json') except Exception,err: status=500 detail='Internal Error' return Response(data=detail,status=status,content_type='application/json')