コード例 #1
0
ファイル: forms.py プロジェクト: oggnik/acm-hscc
    def validate(self):
        """Validate the form"""
        if not Form.validate(self):
            return False

        # Make sure the team doesn't already exist
        self.team = Team.query.filter(Team.name.ilike(self.team_name.data)).first()
        if self.team:
            self.team_name.errors.append('Sorry, that team name is already registered')
            return False

        self.team = Team.get_or_create(self.team_name.data, current_user.school)
        current_user.team = self.team
        return True
コード例 #2
0
ファイル: forms.py プロジェクト: oggnik/acm-hscc
    def validate(self):
        """Validate the form"""
        if not Form.validate(self):
            return False

        school = None
        if self.school_id.data and self.school_id.data.isdigit():
            school = School.query.get(int(self.school_id.data))

        if not school:
            school = School.get_or_create(
                name=self.school_name.data.upper(),
                state=self.school_state.data,
            )

        self.user = User.query.filter_by(email=self.email.data).first()
        if self.user:
            self.email.errors.append('An account with that email address has already registered')
            return False

        if self.allergies_text.data:
            self.allergies = Allergies(text=self.allergies_text.data)
        else:
            self.allergies = Allergies(text='')

        language = Language.get_or_create(self.language.data)

        team = Team.get_or_create(self.team_name.data, school)
        if team.school.id != school.id:
            self.team_name.errors.append('Sorry, that team name is already registered at another school')
            return False
        elif len(team.users) == 2:
            self.team_name.errors.append('Sorry, that team is already full (limit of 2 students per team)')
            return False

        self.user = User(
            name=self.name.data,
            email=self.email.data,
            password=self.password.data,
            grade=self.grade.data,
            shirt_size=self.shirt_size.data,
            language=language,
            allergies=self.allergies,
            school=school,
            team=team,
        )

        return True
コード例 #3
0
ファイル: forms.py プロジェクト: oggnik/acm-hscc
    def validate(self):
        """Validate the form"""
        if not Form.validate(self):
            return False

        school = None
        if self.school_id.data and self.school_id.data.isdigit():
            school = School.query.get(int(self.school_id.data))

        if not school:
            school = School.get_or_create(
                name=self.school_name.data.upper(),
                state=self.school_state.data,
            )

        self.user = User.query.filter_by(email=self.email.data).first()
        if self.user:
            self.email.errors.append('An account with that email address has already registered')
            return False

        if self.allergies_text.data:
            self.allergies = Allergies(text=self.allergies_text.data)
        else:
            self.allergies = Allergies(text='')

        language = Language.get_or_create(self.language.data)

        team = Team.get_or_create(self.team_name.data, school)
        if team.school.id != school.id:
            self.team_name.errors.append('Sorry, that team name is already registered at another school')
            return False
        elif len(team.users) == 2:
            self.team_name.errors.append('Sorry, that team is already full (limit of 2 students per team)')
            return False

        self.user = User(
            name=self.first_name.data + ' ' + self.last_name.data,
            email=self.email.data,
            password=self.password.data,
            grade=self.grade.data,
            shirt_size=self.shirt_size.data,
            language=language,
            allergies=self.allergies,
            school=school,
            team=team,
        )

        return True
コード例 #4
0
ファイル: forms.py プロジェクト: oggnik/acm-hscc
    def validate(self):
        """Validate the form"""
        if not Form.validate(self):
            return False

        # Make sure the team doesn't already exist
        self.team = Team.query.filter(Team.name.ilike(
            self.team_name.data)).first()
        if self.team:
            self.team_name.errors.append(
                'Sorry, that team name is already registered')
            return False

        self.team = Team.get_or_create(self.team_name.data,
                                       current_user.school)
        current_user.team = self.team
        return True