spradio-server-django/savepointradio/core/dynamic_preferences_registry.py

93 lines
2.8 KiB
Python
Raw Normal View History

from django.forms import ValidationError
from dynamic_preferences.types import FloatPreference, IntegerPreference
from dynamic_preferences.preferences import Section
from dynamic_preferences.registries import global_preferences_registry
general = Section('general')
replay = Section('replay')
@global_preferences_registry.register
class MaxSongRequests(IntegerPreference):
section = general
name = 'max_song_requests'
help_text = (
'The maximum amount of requests a user can have queued at any given '
'time. This restriction does not apply to users who are designated '
'as staff.'
)
default = 5
required = True
def validate(self, value):
if value < 0:
raise ValidationError('Must be greater than 0.')
@global_preferences_registry.register
class SongsPerJingle(IntegerPreference):
section = general
name = 'songs_per_jingle'
help_text = 'The amount of songs that will be played between jingles.'
default = 30
required = True
def validate(self, value):
if value < 0:
raise ValidationError('Must be greater than 0.')
@global_preferences_registry.register
class ReplayRatio(FloatPreference):
section = replay
name = 'replay_ratio'
help_text = (
'This defines how long before a song can be played/requested again '
'once it\'s been played. The ratio is based on the total song length '
'of all the enabled, requestable songs in the radio playlist.\n\n'
'Example: If the total song length of the radio playlist is 432000 '
'seconds (5 days), then a ratio of 0.75 will mean that a song cannot '
'be played again for 324000 seconds '
'(0.75 * 432000 = 324000 seconds = 3 days, 18 hours).'
)
default = float(0.75)
required = True
def validate(self, value):
if value < 0.0 or value > 1.0:
raise ValidationError('Must be between 0.0 and 1.0, inclusive.')
@global_preferences_registry.register
class MinRatingsForVariance(IntegerPreference):
section = replay
name = 'min_ratings_for_variance'
help_text = (
'The minimum amount of ratings for the rating variance to take effect '
'on the replay ratios.'
)
default = 5
required = True
def validate(self, value):
if value < 0:
raise ValidationError('Must be greater than 0.')
@global_preferences_registry.register
class RatingVarianceRatio(FloatPreference):
section = replay
name = 'rating_variance_ratio'
help_text = (
'The range in which the replay ratio can be adjusted due to profile '
'ratings.'
)
default = float(0.20)
required = True
def validate(self, value):
if value < 0.0 or value > 1.0:
raise ValidationError('Must be between 0.0 and 1.0, inclusive.')