class BatchEnrollmentForm(BaseForm): csv = TextAreaField('Email, Name, SID, Course Login, Section') role = SelectField('Role', default=STUDENT_ROLE, choices=ROLE_DISPLAY_NAMES.items()) def validate(self): check_validate = super(BatchEnrollmentForm, self).validate() # if our validators do not pass if not check_validate: return False try: rows = self.csv.data.splitlines() self.csv.parsed = list(csv.reader(rows)) except csv.Error as e: logging.error(e) self.csv.errors.append(['The CSV could not be parsed']) return False for row in self.csv.parsed: if len(row) != 5: err = "{0} did not have 5 columns".format(row) self.csv.errors.append(err) return False if not row[0]: err = "{0} did not have an email".format(row) self.csv.errors.append(err) return False elif "@" not in row[0]: # TODO : Better email check. err = "{0} is not a valid email".format(row[0]) self.csv.errors.append(err) return False return True
class BatchEnrollmentForm(BaseForm): csv = TextAreaField('Email, Name, SID, Course Login, Section') role = SelectField('Role', default=STUDENT_ROLE, choices=ROLE_DISPLAY_NAMES.items()) def validate(self): check_validate = super(BatchEnrollmentForm, self).validate() # if our validators do not pass if not check_validate: return False try: rows = self.csv.data.splitlines() self.csv.parsed = list(csv.reader(rows)) except csv.Error as e: logging.error(e) self.csv.errors.append(['The CSV could not be parsed']) return False for row in self.csv.parsed: if len(row) != 5: err = "{0} did not have 5 columns".format(row) self.csv.errors.append(err) return False if not row[0]: err = "{0} did not have an email".format(row) self.csv.errors.append(err) return False elif not re.match(r"[^@]+@[^@]+\.[^@]+", row[0]): # checking for email # https://stackoverflow.com/questions/8022530/python-check-for-valid-email-address err = "{0} is not a valid email".format(row[0]) self.csv.errors.append(err) return False return True
class EnrollmentExportForm(BaseForm): roles = MultiCheckboxField('Roles', choices=ROLE_DISPLAY_NAMES.items(), validators=[validators.required()]) def validate(self): if not super().validate(): return False return all(role in ROLE_DISPLAY_NAMES.keys() for role in self.roles.data)
class EnrollmentForm(BaseForm): name = StringField('Name', validators=[validators.required()]) email = EmailField('Email', validators=[validators.required(), validators.email()]) sid = StringField('SID', validators=[validators.optional()]) secondary = StringField('Secondary Auth (e.g Username)', validators=[validators.optional()]) section = StringField('Section', validators=[validators.optional()]) role = SelectField('Role', default=STUDENT_ROLE, choices=ROLE_DISPLAY_NAMES.items())
class SectionAssignmentForm(BaseForm): name = StringField('Name', validators=[validators.optional()]) email = EmailField('Email', validators=[validators.required(), validators.email()]) sid = StringField('SID', validators=[validators.optional()]) secondary = StringField('Secondary Auth (e.g Username)', validators=[validators.optional()]) section = IntegerField('Section', validators=[validators.required(), validators.NumberRange(min=0)]) role = SelectField('Role', default=STUDENT_ROLE, choices=list(ROLE_DISPLAY_NAMES.items()))
def validate(self): if not super().validate(): return False return all(role in ROLE_DISPLAY_NAMES.keys() for role in self.roles.data)