137 lines
4 KiB
Python
137 lines
4 KiB
Python
from django.forms import ValidationError
|
|
from django.utils import timezone
|
|
|
|
from dynamic_preferences.types import (
|
|
BooleanPreference, ChoicePreference, DurationPreference,
|
|
FloatPreference, IntegerPreference
|
|
)
|
|
from dynamic_preferences.preferences import Section
|
|
from dynamic_preferences.registries import global_preferences_registry
|
|
|
|
|
|
general = Section('general')
|
|
jingles = Section('jingles')
|
|
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 JinglesEnabled(BooleanPreference):
|
|
section = jingles
|
|
name = 'jingles_enabled'
|
|
help_text = 'Enable jingle functionality for the radio.'
|
|
default = False
|
|
required = False
|
|
|
|
|
|
@global_preferences_registry.register
|
|
class JinglesFunction(ChoicePreference):
|
|
section = jingles
|
|
name = 'jingles_function'
|
|
help_text = 'The function to determine when jingles are played.'
|
|
choices = [
|
|
('after_songs', 'After so many songs are played'),
|
|
('after_time', 'After so much time has passed'),
|
|
]
|
|
default = 'after_songs'
|
|
required = True
|
|
|
|
|
|
@global_preferences_registry.register
|
|
class SongsPerJingle(IntegerPreference):
|
|
section = jingles
|
|
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 TimeBeforeJingle(DurationPreference):
|
|
section = jingles
|
|
name = 'time_before_jingle'
|
|
help_text = 'The amount of time before a jingle is played.'
|
|
default = timezone.timedelta(hours=1)
|
|
required = True
|
|
|
|
|
|
@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 VarianceEnabled(BooleanPreference):
|
|
section = replay
|
|
name = 'variance_enabled'
|
|
help_text = 'Enable variance to replay time based on user ratings.'
|
|
default = False
|
|
required = False
|
|
|
|
|
|
@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.')
|