示例#1
0
def to_team_from_rosebotics(rosebotics_team, get_members=True):
    team = Team()
    team.name = rosebotics_team.name
    team.leader = rosebotics_team.leader
    team.team_key = rosebotics_team.key
    team.courses = rosebotics_team.courses or [c.prefix for c in COURSE_LIST if not c.coming_soon]
    if get_members:
        members = RoseboticsTeamMember.query(ancestor=rosebotics_team.key)
        team.members = [member for member in members]  # iterate through them to get them all
    return team
示例#2
0
 def get_teams(self, empty):
     """ Gets the teams that you are a member or leader of """
     user_email = get_user_email()
     response = Teams()
     query = RoseboticsTeamMember.query(RoseboticsTeamMember.email == user_email)
     teams = [m.key.parent().get() for m in query if m.visibility != TeamVisibility.NOT_CHOSEN]
     query = RoseboticsTeam.query(RoseboticsTeam.leader == user_email)
     teams += [team for team in query]
     teams = remove_model_duplicates(teams)
     response.teams = [to_team_from_rosebotics(team_key, get_members=False) for team_key in teams]
     return response
示例#3
0
def to_team_from_rosebotics(rosebotics_team, get_members=True):
    team = Team()
    team.name = rosebotics_team.name
    team.leader = rosebotics_team.leader
    team.team_key = rosebotics_team.key
    team.courses = rosebotics_team.courses or [
        c.prefix for c in COURSE_LIST if not c.coming_soon
    ]
    if get_members:
        members = RoseboticsTeamMember.query(ancestor=rosebotics_team.key)
        team.members = [member for member in members
                        ]  # iterate through them to get them all
    return team
示例#4
0
 def delete_team(self, team):
     """ Deletes a team that you own """
     user_email = get_user_email()
     team = team.team_key.get()
     if team.leader != user_email:
         raise endpoints.BadRequestException("You are not the leader of this team!")
         return
     members = RoseboticsTeamMember.query(ancestor=team.key)
     for member in members:
         member.key.delete()
     for sweep in AutoSweep.query(AutoSweep.team_key == team.key):
         sweep.key.delete()
     team.key.delete()
     return Team(name="deleted")
示例#5
0
 def delete_team(self, team):
     """ Deletes a team that you own """
     user_email = get_user_email()
     team = team.team_key.get()
     if team.leader != user_email:
         raise endpoints.BadRequestException(
             'You are not the leader of this team!')
         return
     members = RoseboticsTeamMember.query(ancestor=team.key)
     for member in members:
         member.key.delete()
     for sweep in AutoSweep.query(AutoSweep.team_key == team.key):
         sweep.key.delete()
     team.key.delete()
     return Team(name='deleted')
示例#6
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()
示例#7
0
 def get_team_invites(self, empty):
     """ Get all of the invites to teams that you have """
     user_email = get_user_email()
     response = TeamInvites()
     query = RoseboticsTeamMember.query(RoseboticsTeamMember.email == user_email)
     for team_member in query:
         team = team_member.key.parent().get()
         invite = TeamInvite()
         team_leader = RoseboticsStudent.get_by_id(team.leader)
         invite.team_leader_name = team_leader.name
         invite.team_key = team.key
         invite.team_name = team.name
         invite.response = team_member.visibility
         response.invites.append(invite)
     return response
示例#8
0
 def get_team_invites(self, empty):
     """ Get all of the invites to teams that you have """
     user_email = get_user_email()
     response = TeamInvites()
     query = RoseboticsTeamMember.query(
         RoseboticsTeamMember.email == user_email)
     for team_member in query:
         team = team_member.key.parent().get()
         invite = TeamInvite()
         team_leader = RoseboticsStudent.get_by_id(team.leader)
         invite.team_leader_name = team_leader.name
         invite.team_key = team.key
         invite.team_name = team.name
         invite.response = team_member.visibility
         response.invites.append(invite)
     return response
示例#9
0
 def get_teams(self, empty):
     """ Gets the teams that you are a member or leader of """
     user_email = get_user_email()
     response = Teams()
     query = RoseboticsTeamMember.query(
         RoseboticsTeamMember.email == user_email)
     teams = [
         m.key.parent().get() for m in query
         if m.visibility != TeamVisibility.NOT_CHOSEN
     ]
     query = RoseboticsTeam.query(RoseboticsTeam.leader == user_email)
     teams += [team for team in query]
     teams = remove_model_duplicates(teams)
     response.teams = [
         to_team_from_rosebotics(team_key, get_members=False)
         for team_key in teams
     ]
     return response
示例#10
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()
示例#11
0
 def get_total_progress(self, team_progress):
     """ Gets total ROSEbotics progress for everyone in a team """
     user_email = get_user_email()
     rosebotics_team = team_progress.team_key.get()
     team_progress.name = rosebotics_team.name
     # change to filter by visibility?
     members = RoseboticsTeamMember.query(ancestor=team_progress.team_key)
     members_progress = []
     allowed_visibilies = [TeamVisibility.ALL_MEMBERS]
     if rosebotics_team.leader == user_email:
         allowed_visibilies.append(TeamVisibility.TEAM_LEADER)
     else:
         is_user_not_in_team = True
         for member in members:
             if member.email == user_email:
                 is_user_not_in_team = False
                 break
         if is_user_not_in_team:
             raise endpoints.BadRequestException(
                 "You are not allowed to view this team!")
     courses = rosebotics_team.courses
     for member in members:
         if member.visibility in allowed_visibilies or member.email == user_email:
             mp = MemberProgress()
             student = RoseboticsStudent.get_by_id(member.email.lower())
             if student is None:
                 logging.info(member.email + " being thrown out of sweep!")
                 continue
             mp.display_name = student.name
             mp.username = student.username
             for course in courses:
                 course = get_course(course)
                 if course.coming_soon:
                     continue
                 progress = get_total_progress_for_course(
                     member.email, course.prefix)
                 mp.course_progress.append(
                     create_course_progress(course.short_title, progress,
                                            course.prefix))
             members_progress.append(mp)
     team_progress.members_progress = members_progress
     return team_progress
示例#12
0
 def get_total_progress(self, team_progress):
     """ Gets total ROSEbotics progress for everyone in a team """
     user_email = get_user_email()
     rosebotics_team = team_progress.team_key.get()
     team_progress.name = rosebotics_team.name
     # change to filter by visibility?
     members = RoseboticsTeamMember.query(ancestor=team_progress.team_key)
     members_progress = []
     allowed_visibilies = [TeamVisibility.ALL_MEMBERS]
     if rosebotics_team.leader == user_email:
         allowed_visibilies.append(TeamVisibility.TEAM_LEADER)
     else:
         is_user_not_in_team = True
         for member in members:
             if member.email == user_email:
                 is_user_not_in_team = False
                 break
         if is_user_not_in_team:
             raise endpoints.BadRequestException("You are not allowed to view this team!")
     courses = rosebotics_team.courses
     for member in members:
         if member.visibility in allowed_visibilies or member.email == user_email:
             mp = MemberProgress()
             student = RoseboticsStudent.get_by_id(member.email.lower())
             if student is None:
                 logging.info(member.email + " being thrown out of sweep!")
                 continue
             mp.display_name = student.name
             mp.username = student.username
             for course in courses:
                 course = get_course(course)
                 if course.coming_soon:
                     continue
                 progress = get_total_progress_for_course(member.email, course.prefix)
                 mp.course_progress.append(create_course_progress(course.short_title, progress, course.prefix))
             members_progress.append(mp)
     team_progress.members_progress = members_progress
     return team_progress
示例#13
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
示例#14
0
def get_csv_export_lists(rosebotics_student, team_urlsafe, export_student_name,
                         export_rose_username, unit_points, ppu, ppt,
                         export_course_progress, export_track_progress,
                         timezone):
    table_data = []
    header_row = []
    table_data.append(header_row)
    # Student Header
    if export_student_name:
        header_row.append("Full Name")
    if export_rose_username:
        header_row.append("Username")
    if timezone:
        header_row.append("Timestamp")
    team = ndb.Key(urlsafe=team_urlsafe).get()
    if team is None:
        return []
    members = RoseboticsTeamMember.query(ancestor=team.key)
    allowed_visibilies = [TeamVisibility.ALL_MEMBERS]
    if team.leader == rosebotics_student.key.string_id():
        allowed_visibilies.append(TeamVisibility.TEAM_LEADER)
    else:
        is_user_not_in_team = True
        for member in members:
            if member.email == rosebotics_student.key.string_id():
                is_user_not_in_team = False
                break
        if is_user_not_in_team:
            return []
    is_first_student = True
    for member in members:
        if member.visibility not in allowed_visibilies:
            continue
        student = RoseboticsStudent.get_by_id(member.email)
        if student is None:
            continue
        table_row = []
        if export_student_name:
            table_row.append(student.name)
        if export_rose_username:
            table_row.append(student.username)
        if timezone:
            table_row.append(_tz_now(timezone))
        for course in team.courses:
            course_progress = get_total_progress_for_course(
                member.email,
                course,
                as_percent=unit_points,
                get_total_tasks=True)
            course_added = False
            for track in course_progress['tracks']:
                track_progress = track['track']
                track_data = track['units']
                track_added = False
                extract_key = lambda pair: int(pair[0].split(":")[0])
                unit_tuples = sorted(track_data.items(), key=extract_key)
                for unit_id, unit_progress in unit_tuples:
                    if unit_id.endswith('-total'):
                        continue
                    unit_name = unit_id.split(':')[1]
                    if export_course_progress and not course_added:
                        table_row.append(course_progress['course'])
                        if is_first_student:
                            header_row.append(course)
                        course_added = True
                    if export_track_progress and not track_added:
                        table_row.append(track_progress)
                        if is_first_student:
                            header_row.append(track['name'])
                        track_added = True
                    if unit_points:
                        table_row.append(unit_progress * ppu)
                        unit_total = ppu
                    else:
                        table_row.append(unit_progress * ppt)
                        unit_total = track_data[unit_id + '-total'] * ppt
                    if is_first_student:
                        header_row.append(unit_name + " (out of " +
                                          str(unit_total) + ")")
        is_first_student = False
        table_data.append(table_row)
    return table_data
示例#15
0
def get_csv_export_lists(
    rosebotics_student,
    team_urlsafe,
    export_student_name,
    export_rose_username,
    unit_points,
    ppu,
    ppt,
    export_course_progress,
    export_track_progress,
    timezone,
):
    table_data = []
    header_row = []
    table_data.append(header_row)
    # Student Header
    if export_student_name:
        header_row.append("Full Name")
    if export_rose_username:
        header_row.append("Username")
    if timezone:
        header_row.append("Timestamp")
    team = ndb.Key(urlsafe=team_urlsafe).get()
    if team is None:
        return []
    members = RoseboticsTeamMember.query(ancestor=team.key)
    allowed_visibilies = [TeamVisibility.ALL_MEMBERS]
    if team.leader == rosebotics_student.key.string_id():
        allowed_visibilies.append(TeamVisibility.TEAM_LEADER)
    else:
        is_user_not_in_team = True
        for member in members:
            if member.email == rosebotics_student.key.string_id():
                is_user_not_in_team = False
                break
        if is_user_not_in_team:
            return []
    is_first_student = True
    for member in members:
        if member.visibility not in allowed_visibilies:
            continue
        student = RoseboticsStudent.get_by_id(member.email)
        if student is None:
            continue
        table_row = []
        if export_student_name:
            table_row.append(student.name)
        if export_rose_username:
            table_row.append(student.username)
        if timezone:
            table_row.append(_tz_now(timezone))
        for course in team.courses:
            course_progress = get_total_progress_for_course(
                member.email, course, as_percent=unit_points, get_total_tasks=True
            )
            course_added = False
            for track in course_progress["tracks"]:
                track_progress = track["track"]
                track_data = track["units"]
                track_added = False
                extract_key = lambda pair: int(pair[0].split(":")[0])
                unit_tuples = sorted(track_data.items(), key=extract_key)
                for unit_id, unit_progress in unit_tuples:
                    if unit_id.endswith("-total"):
                        continue
                    unit_name = unit_id.split(":")[1]
                    if export_course_progress and not course_added:
                        table_row.append(course_progress["course"])
                        if is_first_student:
                            header_row.append(course)
                        course_added = True
                    if export_track_progress and not track_added:
                        table_row.append(track_progress)
                        if is_first_student:
                            header_row.append(track["name"])
                        track_added = True
                    if unit_points:
                        table_row.append(unit_progress * ppu)
                        unit_total = ppu
                    else:
                        table_row.append(unit_progress * ppt)
                        unit_total = track_data[unit_id + "-total"] * ppt
                    if is_first_student:
                        header_row.append(unit_name + " (out of " + str(unit_total) + ")")
        is_first_student = False
        table_data.append(table_row)
    return table_data
示例#16
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