def validator(self): majlst = [] for maj in Major.objects.all(): majlst.append(maj.key) users = [] for ln in str(self.body.data).splitlines(True): user = User() # clean up and strip the list pts = [x.strip() for x in ln.split(',')] # lowercase specific parts pts[2] = pts[2].lower() pts[4] = pts[4].lower() pts[5] = pts[5].lower().capitalize() if pts[2] not in ["alum", "senior", "vol", "other"]: self.body.add_error({'message': pts[1] + ' type is invalid.'}) else: if pts[2] == "alum": user._type = 2 elif pts[2] == "senior": user._type = 1 elif pts[2] == "vol": user._type = 0 else: user._type = 3 if pts[4].lower() not in majlst: self.body.add_error({'message': pts[1] + ' major is invalid.'}) else: user.major = Major.objects.get(key=pts[4]) if not EmailValidator().valid(pts[3]): self.body.add_error({'message': pts[1] + ' email is invalid.'}) else: user.email = pts[3] try: Team.objects.get(text=pts[5]) except Team.DoesNotExist: self.start.add_error( {'message': pts[1] + '\'s team ' + pts[5] + ' does not exist!', 'type': 'warn', 'block': False}) user.team_txt = pts[5] user.name = pts[1] user.username = pts[0] users.append(user) setattr(self.body, 'valid_data', users)