def post(self, request, format=None): try: data = request.data logger.debug('[RiderAPI:Register] Attempting to find rider with id: '+str(data[u'id'])) rider_exists = Rider.objects.filter(id=data[u'id']).exists() if rider_exists: logger.debug('[API:Register] Rider' + str(data[u'id']) + 'was already registered.') else: logger.debug('[RiderAPI:Register] Rider with id: ' + str(data[u'id'] + ' was not found. Registering...')) serializer = riderSerializer(data=data) if not serializer.is_valid(): return Response( serializer.errors, status=status.HTTP_400_BAD_REQUEST ) rider_data = serializer.save() rider_data.save() logger.debug('[RiderAPI:Register] Rider' + str(rider_data.id) + 'has been registered.') return Response( {settings.JSON_KEYS['RIDER_ID']: data[u'id']}, status=status.HTTP_201_CREATED ) except Exception as ex: return Response( {settings.JSON_KEYS['BAD_REQ']: ex.message}, status=status.HTTP_400_BAD_REQUEST )
def post(self, request, format=None): try: data = request.data logger.debug( '[RiderAPI:Register] Attempting to find rider with id: ' + str(data[u'id'])) rider_exists = Rider.objects.filter(id=data[u'id']).exists() if rider_exists: logger.debug('[API:Register] Rider' + str(data[u'id']) + 'was already registered.') else: logger.debug('[RiderAPI:Register] Rider with id: ' + str(data[u'id'] + ' was not found. Registering...')) serializer = riderSerializer(data=data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) rider_data = serializer.save() rider_data.save() logger.debug('[RiderAPI:Register] Rider' + str(rider_data.id) + 'has been registered.') return Response({settings.JSON_KEYS['RIDER_ID']: data[u'id']}, status=status.HTTP_201_CREATED) except Exception as ex: return Response({settings.JSON_KEYS['BAD_REQ']: ex.message}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): try: logger.debug('trying') data = request.DATA serializer = riderSerializer(data=data) if serializer.is_valid(): serializer.save() rider_uuid = create_uuid(serializer.object.pk) return Response( {settings.JSON_KEYS['RIDER_ID']: rider_uuid}, status=status.HTTP_201_CREATED ) return Response( serializer.errors, status=status.HTTP_400_BAD_REQUEST ) except Exception as ex: return Response( {settings.JSON_KEYS['BAD_REQ']: ex.message}, status=status.HTTP_400_BAD_REQUEST )