def refreshPlaylist(request): params = None if (request.method == 'GET'): params = request.GET elif request.method == 'POST': params = request.POST location_service = LocationService() consumer_service = ConsumerService() user_id = params.get('user_id', None) api_token = params.get('api_key', None) location_id = params.get('location_id', None) if not location_id: raise InvalidLocationError(location_id) consumer = consumer_service.isValidUser(user_id, api_token) if not consumer: raise InvalidUserError(user_id) if not location_service.isActive(location_id): response_data = {} location_service.checkOut(consumer) response_data['message'] = 'Location is not active' response_data['checked_out'] = True response_data['status'] = 200 return HttpResponse(HttpResponse(json.dumps(response_data), mimetype='application/json')) location_map = location_service.getLocationMap(consumer) if not location_map: logger.warn("user with user_id" + str(user_id) + " not checked in") if location_map and str(location_map.location.pk) != location_id: logger.warn("user with user_id" + str(user_id) + " not checked in to correct location: " + location_id) logger.info("Incoming request- refresh playlist with parameters device_id " + str(user_id) + ", location_id " + str(location_id)) # Use location id to fetch current playlist return __refreshPlaylistHelper__(consumer, location_id)