Example #1
0
 def fill_in_team_members(self, rosebotics_student):
   if rosebotics_student.username is None or rosebotics_student.username == "":
     return
   rose_email = rosebotics_student.username + "@rose-hulman.edu"
   query = RoseboticsTeamMember.query(RoseboticsTeamMember.email == rose_email)
   for team_member_key in query.iter(keys_only=True):
     team_key = team_member_key.parent()
     team_member_key.delete()
     team_member_key = ndb.Key(RoseboticsTeamMember, rosebotics_student.key.string_id(), parent=team_key)
     team_member = RoseboticsTeamMember(key=team_member_key)
     team_member.email = rosebotics_student.key.string_id()
     leader_email = team_key.get().leader
     if leader_email in ADMIN_LIST:
       team_member.visibility = TeamVisibility.TEAM_LEADER
     team_member.put()
Example #2
0
 def fill_in_team_members(self, rosebotics_student):
     if rosebotics_student.username is None or rosebotics_student.username == "":
         return
     rose_email = rosebotics_student.username + "@rose-hulman.edu"
     query = RoseboticsTeamMember.query(
         RoseboticsTeamMember.email == rose_email)
     for team_member_key in query.iter(keys_only=True):
         team_key = team_member_key.parent()
         team_member_key.delete()
         team_member_key = ndb.Key(RoseboticsTeamMember,
                                   rosebotics_student.key.string_id(),
                                   parent=team_key)
         team_member = RoseboticsTeamMember(key=team_member_key)
         team_member.email = rosebotics_student.key.string_id()
         leader_email = team_key.get().leader
         if leader_email in ADMIN_LIST:
             team_member.visibility = TeamVisibility.TEAM_LEADER
         team_member.put()
Example #3
0
 def insert_team(self, team):
     """ Creates or updates a team that you own """
     user_email = get_user_email()
     if team.team_key:
         old_team = team.team_key.get()
     else:
         old_team = None
     if old_team is not None:
         old_team.name = team.name
         old_team.courses = team.courses
         old_team.put()
         old_members = RoseboticsTeamMember.query(ancestor=team.team_key)
         new_emails = []
         old_emails = [member.email for member in old_members]
         # if new email is NOT in old_members: add new email
         for member in team.members:
             if "@rose-hulman.edu" in member.email:
                 username = member.email.split("@")[0]
                 student = RoseboticsStudent.query(
                     RoseboticsStudent.username == username).get()
                 if student is not None:
                     member.email = student.key.string_id()
                 else:
                     send_rose_invite_email(member.email)
             new_emails.append(member.email)
             if member.email not in old_emails:
                 member_key = get_member_key(team.team_key, member.email)
                 new_member = RoseboticsTeamMember(key=member_key)
                 new_member.email = member.email
                 if new_member.email == user_email:
                     new_member.visibility = TeamVisibility.ALL_MEMBERS
                 elif is_admin_user(
                         user_email
                 ) and "@rose-hulman.edu" not in new_member.email:
                     new_member.visibility = TeamVisibility.TEAM_LEADER
                 else:
                     send_invite_email(member.email)
                 new_member.put()
         # if old username is NOT in new_members remove old member
         for old_member in old_members:
             if old_member.email not in new_emails:
                 old_member.key.delete()
     else:
         new_team = RoseboticsTeam(leader=user_email,
                                   name=team.name,
                                   courses=team.courses)
         team.team_key = new_team.put()
         emails = [member.email for member in team.members]
         for email in emails:
             student_email = email
             if "@rose-hulman.edu" in student_email:
                 username = student_email.split("@")[0]
                 student = RoseboticsStudent.query(
                     RoseboticsStudent.username == username).get()
                 if student is not None:
                     student_email = student.key.string_id()
                 else:
                     send_rose_invite_email(student_email)
             member_key = get_member_key(team.team_key, student_email)
             new_member = RoseboticsTeamMember(key=member_key)
             new_member.email = student_email
             if new_member.email == user_email:
                 new_member.visibility = TeamVisibility.ALL_MEMBERS
             elif is_admin_user(
                     user_email
             ) and "@rose-hulman.edu" not in student_email:
                 new_member.visibility = TeamVisibility.TEAM_LEADER
             else:
                 send_invite_email(email)
             new_member.put()
     return team
Example #4
0
 def insert_team(self, team):
     """ Creates or updates a team that you own """
     user_email = get_user_email()
     if team.team_key:
         old_team = team.team_key.get()
     else:
         old_team = None
     if old_team is not None:
         old_team.name = team.name
         old_team.courses = team.courses
         old_team.put()
         old_members = RoseboticsTeamMember.query(ancestor=team.team_key)
         new_emails = []
         old_emails = [member.email for member in old_members]
         # if new email is NOT in old_members: add new email
         for member in team.members:
             if "@rose-hulman.edu" in member.email:
                 username = member.email.split("@")[0]
                 student = RoseboticsStudent.query(RoseboticsStudent.username == username).get()
                 if student is not None:
                     member.email = student.key.string_id()
                 else:
                     send_rose_invite_email(member.email)
             new_emails.append(member.email)
             if member.email not in old_emails:
                 member_key = get_member_key(team.team_key, member.email)
                 new_member = RoseboticsTeamMember(key=member_key)
                 new_member.email = member.email
                 if new_member.email == user_email:
                     new_member.visibility = TeamVisibility.ALL_MEMBERS
                 elif is_admin_user(user_email) and "@rose-hulman.edu" not in new_member.email:
                     new_member.visibility = TeamVisibility.TEAM_LEADER
                 else:
                     send_invite_email(member.email)
                 new_member.put()
         # if old username is NOT in new_members remove old member
         for old_member in old_members:
             if old_member.email not in new_emails:
                 old_member.key.delete()
     else:
         new_team = RoseboticsTeam(leader=user_email, name=team.name, courses=team.courses)
         team.team_key = new_team.put()
         emails = [member.email for member in team.members]
         for email in emails:
             student_email = email
             if "@rose-hulman.edu" in student_email:
                 username = student_email.split("@")[0]
                 student = RoseboticsStudent.query(RoseboticsStudent.username == username).get()
                 if student is not None:
                     student_email = student.key.string_id()
                 else:
                     send_rose_invite_email(student_email)
             member_key = get_member_key(team.team_key, student_email)
             new_member = RoseboticsTeamMember(key=member_key)
             new_member.email = student_email
             if new_member.email == user_email:
                 new_member.visibility = TeamVisibility.ALL_MEMBERS
             elif is_admin_user(user_email) and "@rose-hulman.edu" not in student_email:
                 new_member.visibility = TeamVisibility.TEAM_LEADER
             else:
                 send_invite_email(email)
             new_member.put()
     return team