def __init__(self, num, database_id=0, lastfirst=",", email="", title="", schoolid="", staffstatus="", status="", **kwargs): self.num = num self.ID = num self.powerschool_id = num self.idnumber = self.num self.database_id = database_id self.family_id = self.ID[:4] + 'P' self.lastfirst = lastfirst self.email = email if email.strip() else None self.email_address = self.email self.last, self.first = self.lastfirst.split(',') self.first = self.first.strip() self.last = self.last.strip() self.fullname = self.first + ' ' + self.last if not self.email: self.email = "{}@ssis-suzhou.net".format(re.sub(r'[^a-z]', '', "{}{}".format(self.first, self.last).lower())) self.preferred_name =self.first + " " + self.last self.profile_bool_deails = title if email: self.username = no_whitespace_all_lower(self.email.split('@')[0]) else: self.username = no_whitespace_all_lower(self.preferred_name) self.grade = None # Teachers don't have grades, but keep this here for comparison reaasons self.title = title self._courses = [] self._students = [] self._teachers = [] self._groups = [] self._parents = [] self._departments = [] self._timetable= defaultdict(lambda : defaultdict(dict)) self._enrollments = defaultdict(list) self.is_primary = False self.is_secondary = False self.is_support = False self.homeroom = None self.profile_bool_iselemteacher = False self.profile_bool_issecteacher = False self.profile_bool_issupport = False self.custom_profile_schoolid = schoolid if schoolid == str(PRIMARYSCHOOLID): self.is_primary = True self.profile_bool_iselemteacher = True elif schoolid == str(SECONDARYSCHOOLID): self.is_secondary = True self.profile_bool_issecteacher = True elif schoolid == str(NOSCHOOLID): self.is_support = True self.profile_bool_issupport = True self.status = status self.profile_extra_isteacher = True self._cohorts = self.derive_cohorts()
def determine_username_email(self): """ DETERMINES THIS USERNAME TAKING INTO ACCOUNT EXISTING USERNAMES """ first_half = no_whitespace_all_lower(self.first + self.last)[:20] second_half = str(get_year_of_graduation(self.grade)) self.username = first_half + second_half times_through = 1 report = False while self.username in _taken_usernames: self.logger.warning("Username {} already taken, looking for new name".format(self.username)) report = True self.username = first_half + ('_' * times_through) + second_half if report: self.logger.warning("Using new username {}".format(self.username)) self.email = self.username + '@student.ssis-suzhou.net'