Beispiel #1
0
    def clean_num_participants(self):

        lcm = get_lcm(self.session_config)
        num_participants = self.cleaned_data['num_participants']
        if num_participants % lcm:
            raise forms.ValidationError(
                'Number of participants must be a multiple of {}'.format(lcm))
        return num_participants
Beispiel #2
0
    def clean(self):
        super().clean()
        if self.errors:
            return
        session_config_name = self.cleaned_data['session_config']

        config = SESSION_CONFIGS_DICT[session_config_name]
        lcm = config.get_lcm()
        num_participants = self.cleaned_data.get('num_participants')
        if num_participants is None or num_participants % lcm:
            raise forms.ValidationError('Please enter a valid number of participants.')
    def clean(self):
        super().clean()
        if self.errors:
            return
        session_config_name = self.cleaned_data['session_config']

        config = SESSION_CONFIGS_DICT[session_config_name]
        lcm = config.get_lcm()
        num_participants = self.cleaned_data.get('num_participants')
        if num_participants is None or num_participants % lcm:
            raise forms.ValidationError('Venligst indtast en valid antal af spillere.')
Beispiel #4
0
    def clean_num_participants(self):
        session_config_name = self.cleaned_data.get('session_config')

        # We must check for an empty string in case validation is not run
        if session_config_name != '':
            lcm = SESSION_CONFIGS_DICT[session_config_name].get_lcm()
            num_participants = self.cleaned_data['num_participants']
            if num_participants % lcm:
                raise forms.ValidationError(
                    'Please enter a valid number of participants.')
            return num_participants
Beispiel #5
0
    def clean_round_number(self):
        app_name = self.cleaned_data['app_name']
        round_number = self.cleaned_data['round_number']

        if round_number and app_name:
            num_rounds = self.rounds_per_app[app_name]
            if round_number > num_rounds:
                self.cleaned_data['round_number'] = None
                raise forms.ValidationError(
                    'Invalid round number (max is {})'.format(num_rounds))
        return round_number
Beispiel #6
0
    def clean_num_participants(self):
        session_config_name = self.cleaned_data.get('session_config')

        # I think when this is checked, it's possible that basic validation
        # for session_config_name was not done yet.
        # when I tested it was None
        # but maybe it could also be the empty string because that's what's
        # explicitly put above.
        if session_config_name:
            lcm = SESSION_CONFIGS_DICT[session_config_name].get_lcm()
            num_participants = self.cleaned_data['num_participants']
            if num_participants % lcm:
                raise forms.ValidationError(
                    'Please enter a valid number of participants.')
            return num_participants