Skip to content

Commit

Permalink
feat: Add playlist validation to ExperimentForm clean method
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed May 28, 2024
1 parent 9b3b855 commit e9d967e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions backend/experiment/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ def __init__(self, *args, **kwargs):
required=False
)

def clean(self):

# Validat the rules' playlist
rule_id = self.cleaned_data['rules']
cl = EXPERIMENT_RULES[rule_id]
rules = cl()

playlists = self.cleaned_data['playlists']
playlist_errors = []

# Validate playlists
for playlist in playlists:
errors = rules.validate_playlist(playlist)

for error in errors:
playlist_errors.append(f"Playlist {playlist.name}: {error}")

if playlist_errors:
self.add_error('playlists', playlist_errors)

class Meta:
model = Experiment
fields = ['name', 'slug', 'active', 'rules',
Expand Down

0 comments on commit e9d967e

Please sign in to comment.