Example #1
0
class EditUserForm(Form):
    major = SelectField(u'major',
                        choices=[(m['name'], m['name'])
                                 for m in Major.get_all(include_none=True)],
                        coerce=_coerce_unicode)
    year = SelectField(u'year',
                       choices=[(y['year'], y['name'])
                                for y in Year.get_all(include_none=True)],
                       coerce=lambda x: int(x) if x else None)

    def validate(self):
        # validating with SelectField is hard?
        # if not super(EditUserForm, self).validate():
        #     return False
        return True
Example #2
0
def add_users():
    names = [
        'andrew', 'brian', 'connor', 'david', 'elise', 'francis', 'gerald',
        'hillary', 'isabela', 'jennifer', 'kelly', 'lisa', 'mona', 'natalie',
        'oswald', 'peter', 'quincy', 'richard', 'sarah', 'timothy', 'uma',
        'valerie', 'wally', 'xavier', 'yamini', 'zachary'
    ]
    years = [year['year'] for year in Year.get_all()]
    majors = [major['name'] for major in Major.get_all()]
    remaining_with_majors = 20
    for name in names:
        email = '{}@gatech.edu'.format(name)
        year = years[randint(0, len(years) - 1)]
        major = None if remaining_with_majors <= 0 else majors[randint(
            0,
            len(majors) - 1)]
        remaining_with_majors -= 1
        new_user = User(username=name,
                        password=name,
                        email=email,
                        year=year,
                        major=major)
        new_user.save()