def change_rider(rider_name, new_rider_name): """ Changes the riders name. :param rider_name: Current name of rider. :type rider_name: str :param new_rider_name: New unique name of rider. :type new_rider_name: str :authorization: Administrators. :broadcast: Administrators, riders and spectators. :returns: Details of changed rider. :rtype: Instance of :class:`laptimer.models.ApiResult`. """ method = "change_rider" try: check = api_utils.check_if_found(Rider, method, new_rider_name) if check != True: return check check = api_utils.check_if_not_found(Rider, method, rider_name) if check != True: return check rider = Rider.objects.get(name=rider_name) rider.name = new_rider_name rider.save() logger.info("%s: %s" % (method, rider.name)) result = ApiResult(method, ok=True, data=rider) # TODO: Broadcast result return result except Exception as e: logger.error("Exception caught in %s: %s" % (method, e)) error = type(e).__name__ return ApiResult(method, ok=False, data=error)
def change_rider(rider_name, new_rider_name): ''' Changes the riders name. :param rider_name: Current name of rider. :type rider_name: str :param new_rider_name: New unique name of rider. :type new_rider_name: str :authorization: Administrators. :broadcast: Administrators, riders and spectators. :returns: Details of changed rider. :rtype: Instance of :class:`laptimer.models.ApiResult`. ''' method = 'change_rider' try: check = api_utils.check_if_found(Rider, method, new_rider_name) if check != True: return check check = api_utils.check_if_not_found(Rider, method, rider_name) if check != True: return check rider = Rider.objects.get(name=rider_name) rider.name = new_rider_name rider.save() logger.info('%s: %s' % (method, rider.name)) result = ApiResult(method, ok=True, data=rider) # TODO: Broadcast result return result except Exception as e: logger.error('Exception caught in %s: %s' % (method, e)) error = type(e).__name__ return ApiResult(method, ok=False, data=error)
def add_rider(rider_name): """ Adds a new rider. :param rider_name: Unique name of rider to be added. :type rider_name: str :authorization: Administrators. :broadcast: Administrators, riders and spectators. :returns: Details of added rider. :rtype: Instance of :class:`laptimer.models.ApiResult`. """ method = "add_rider" try: check = api_utils.check_if_found(Rider, method, rider_name) if check != True: return check rider = Rider.objects.create(name=rider_name) # TODO: Add rider as Django user in rider group logger.info("%s: %s" % (method, rider.name)) result = ApiResult(method, ok=True, data=rider) # TODO: Broadcast result return result except Exception as e: logger.error("Exception caught in %s: %s" % (method, e)) error = type(e).__name__ return ApiResult(method, ok=False, data=error)
def add_rider(rider_name): ''' Adds a new rider. :param rider_name: Unique name of rider to be added. :type rider_name: str :authorization: Administrators. :broadcast: Administrators, riders and spectators. :returns: Details of added rider. :rtype: Instance of :class:`laptimer.models.ApiResult`. ''' method = 'add_rider' try: check = api_utils.check_if_found(Rider, method, rider_name) if check != True: return check rider = Rider.objects.create(name=rider_name) # TODO: Add rider as Django user in rider group logger.info('%s: %s' % (method, rider.name)) result = ApiResult(method, ok=True, data=rider) # TODO: Broadcast result return result except Exception as e: logger.error('Exception caught in %s: %s' % (method, e)) error = type(e).__name__ return ApiResult(method, ok=False, data=error)
def change_track(track_name, new_track_name=None, new_track_distance=None, new_lap_timeout=None, new_unit_of_measurement=None): ''' Changes track details. :param track_name: Current name of track. :type track_name: str :param new_track_name: New unique name of track. :type new_track_name: str :param new_track_distance: Total track distance. :type new_track_distance: float :param new_lap_timeout: Maximum number of seconds before a lap times out.. :type new_lap_timeout: integer :param new_unit_of_measurement: Unit of measurement, either Metric or Imperial. :type new_unit_of_measurement: str :authorization: Administrators. :broadcast: Administrators, riders and spectators. :returns: Details of changed track. :rtype: Instance of :class:`laptimer.models.ApiResult`. ''' method = 'change_track' try: check = api_utils.check_if_not_found(Track, method, track_name) if check != True: return check if new_track_name == None and new_track_distance == None \ and new_lap_timeout == None and new_unit_of_measurement == None: error = 'At least one new track detail is required' # TODO: i18n return ApiResult(method, ok=False, data=error) if new_unit_of_measurement != None \ and new_unit_of_measurement not in dict(settings.UNIT_OF_MEASUREMENT): error = 'Invalid unit of measurement' # TODO: i18n return ApiResult(method, ok=False, data=error) if new_track_name != None: check = api_utils.check_if_found(Track, method, new_track_name) if check != True: return check track = Track.objects.get(name=track_name) if new_track_name != None: track.name = new_track_name if new_track_distance != None: track.distance = new_track_distance if new_lap_timeout != None: track.timeout = new_lap_timeout if new_unit_of_measurement != None: track.unit_of_measurement = new_unit_of_measurement track.save() logger.info('%s: %s' % (method, track.name)) result = ApiResult(method, ok=True, data=track) # TODO: Broadcast result return result except Exception as e: logger.error('Exception caught in %s: %s' % (method, e)) error = type(e).__name__ return ApiResult(method, ok=False, data=error)
def add_track(track_name, track_distance, lap_timeout, unit_of_measurement): ''' Add a new track. :param track_name: Unique name of track. :type track_name: str :param track_distance: Total track distance. :type track_distance: float :param lap_timeout: Maximum number of seconds before a lap times out. :type lap_timeout: integer :param unit_of_measurement: Unit of measurement, either Metric or Imperial. :type unit_of_measurement: str :authorization: Administrators. :broadcast: Administrators, riders and spectators. :returns: Details of new track. :rtype: Instance of :class:`laptimer.models.ApiResult`. ''' # TODO: Role enforcement - admins only method = 'add_track' try: check = api_utils.check_if_found(Track, method, track_name) if check != True: return check if unit_of_measurement not in dict(settings.UNIT_OF_MEASUREMENT): error = 'Invalid unit of measurement' # TODO: i18n return ApiResult(method, ok=False, data=error) track = Track.objects.create(name=track_name, distance=track_distance, timeout=lap_timeout, unit_of_measurement=unit_of_measurement) logger.info('%s: %s' % (method, track.name)) result = ApiResult(method, ok=True, data=track) # TODO: Broadcast result return result except Exception as e: logger.error('Exception caught in %s: %s' % (method, e)) error = type(e).__name__ return ApiResult(method, ok=False, data=error)