예제 #1
0
def get_student_list(coach, list_key):
    student_list = StudentList.get(list_key)
    if student_list is None:
        raise Exception("No list found with list_key='%s'." % list_key)
    if coach.key() not in student_list.coaches:
        raise Exception("Not your list!")
    return student_list
예제 #2
0
def get_student_list(coach, list_key):
    student_list = StudentList.get(list_key)
    if student_list is None:
        raise Exception("No list found with list_key='%s'." % list_key)
    if coach.key() not in student_list.coaches:
        raise Exception("Not your list!")
    return student_list
예제 #3
0
    def get(self):
        coach = UserData.current()

        user_override = self.request_user_data("coach_email")
        if user_override and user_override.are_students_visible_to(coach):
            # Only allow looking at a student list other than your own
            # if you are a dev, admin, or coworker.
            coach = user_override

        student_lists = StudentList.get_for_coach(coach.key())

        student_lists_list = [{
            'key': 'allstudents',
            'name': 'All students',
        }]
        for student_list in student_lists:
            student_lists_list.append({
                'key': str(student_list.key()),
                'name': student_list.name,
            })

        list_id, _ = get_last_student_list(self, student_lists,
                                           coach == UserData.current())
        current_list = None
        for student_list in student_lists_list:
            if student_list['key'] == list_id:
                current_list = student_list

        selected_graph_type = self.request_string(
            "selected_graph_type") or ClassProgressReportGraph.GRAPH_TYPE
        if selected_graph_type == 'progressreport' or selected_graph_type == 'goals':  # TomY This is temporary until all the graphs are API calls
            initial_graph_url = "/api/v1/user/students/%s?coach_email=%s&%s" % (
                selected_graph_type, urllib.quote(coach.email),
                urllib.unquote(
                    self.request_string("graph_query_params", default="")))
        else:
            initial_graph_url = "/profile/graph/%s?coach_email=%s&%s" % (
                selected_graph_type, urllib.quote(coach.email),
                urllib.unquote(
                    self.request_string("graph_query_params", default="")))
        initial_graph_url += 'list_id=%s' % list_id

        template_values = {
            'user_data_coach': coach,
            'coach_email': coach.email,
            'list_id': list_id,
            'student_list': current_list,
            'student_lists': student_lists_list,
            'student_lists_json': json.dumps(student_lists_list),
            'coach_nickname': coach.nickname,
            'selected_graph_type': selected_graph_type,
            'initial_graph_url': initial_graph_url,
            'exercises': exercise_models.Exercise.get_all_use_cache(),
            'is_profile_empty': not coach.has_students(),
            'selected_nav_link': 'coach',
            "view": self.request_string("view", default=""),
            'stats_charts_class': 'coach-view',
        }
        self.render_jinja2_template('viewclassprofile.html', template_values)
예제 #4
0
    def get(self):
        user_data = UserData.current()
        user_data_override = self.request_user_data("coach_email")
        if user_util.is_current_user_developer() and user_data_override:
            user_data = user_data_override

        invalid_student = self.request_bool("invalid_student", default=False)

        coach_requests = [req.student_requested_identifier
                          for req in CoachRequest.get_for_coach(user_data)
                          if req.student_requested_data]

        student_lists_models = StudentList.get_for_coach(user_data.key())
        student_lists_list = []
        for student_list in student_lists_models:
            student_lists_list.append({
                'key': str(student_list.key()),
                'name': student_list.name,
            })
        student_lists_dict = dict((g['key'], g) for g in student_lists_list)

        def student_to_dict(s):
            """Convert the UserData s to a dictionary for rendering."""
            return {
                'key': str(s.key()),
                'email': s.email,
                'username': s.username,
                # Note that child users don't have an email.
                'identifier': s.username or s.email,
                'nickname': s.nickname,
                'profile_root': s.profile_root,
                'can_modify_coaches': s.can_modify_coaches(),
                'studentLists':
                        [l for l in [student_lists_dict.get(str(list_id))
                           for list_id in s.student_lists] if l],
            }

        students_data = user_data.get_students_data()
        students = map(student_to_dict, students_data)
        students.sort(key=lambda s: s['nickname'])

        child_accounts = map(student_to_dict, user_data.get_child_users())
        template_values = {
            'students': students,
            'child_accounts': child_accounts,
            'child_account_keyset': set([c['key'] for c in child_accounts]),
            'students_json': json.dumps(students),
            'student_lists': student_lists_list,
            'student_lists_json': json.dumps(student_lists_list),
            'invalid_student': invalid_student,
            'coach_requests': coach_requests,
            'coach_requests_json': json.dumps(coach_requests),
            'selected_nav_link': 'coach',
            'email': user_data.email,
        }
        self.render_jinja2_template('viewstudentlists.html', template_values)
예제 #5
0
    def get(self):
        coach = UserData.current()

        user_override = self.request_user_data("coach_email")
        if user_override and user_override.are_students_visible_to(coach):
            # Only allow looking at a student list other than your own
            # if you are a dev, admin, or coworker.
            coach = user_override

        student_lists = StudentList.get_for_coach(coach.key())

        student_lists_list = [{
            'key': 'allstudents',
            'name': 'All students',
        }];
        for student_list in student_lists:
            student_lists_list.append({
                'key': str(student_list.key()),
                'name': student_list.name,
            })

        list_id, _ = get_last_student_list(self, student_lists, coach==UserData.current())
        current_list = None
        for student_list in student_lists_list:
            if student_list['key'] == list_id:
                current_list = student_list

        selected_graph_type = self.request_string("selected_graph_type") or ClassProgressReportGraph.GRAPH_TYPE
        if selected_graph_type == 'progressreport' or selected_graph_type == 'goals': # TomY This is temporary until all the graphs are API calls
            initial_graph_url = "/api/v1/user/students/%s?coach_email=%s&%s" % (selected_graph_type, urllib.quote(coach.email), urllib.unquote(self.request_string("graph_query_params", default="")))
        else:
            initial_graph_url = "/profile/graph/%s?coach_email=%s&%s" % (selected_graph_type, urllib.quote(coach.email), urllib.unquote(self.request_string("graph_query_params", default="")))
        initial_graph_url += 'list_id=%s' % list_id

        template_values = {
                'user_data_coach': coach,
                'coach_email': coach.email,
                'list_id': list_id,
                'student_list': current_list,
                'student_lists': student_lists_list,
                'student_lists_json': json.dumps(student_lists_list),
                'coach_nickname': coach.nickname,
                'selected_graph_type': selected_graph_type,
                'initial_graph_url': initial_graph_url,
                'exercises': exercise_models.Exercise.get_all_use_cache(),
                'is_profile_empty': not coach.has_students(),
                'selected_nav_link': 'coach',
                "view": self.request_string("view", default=""),
                'stats_charts_class': 'coach-view',
                }
        self.render_jinja2_template('viewclassprofile.html', template_values)
예제 #6
0
    def remove_student_from_coach(student, coach):
        if student.student_lists:
            actual_lists = StudentList.get(student.student_lists)
            student.student_lists = [l.key() for l in actual_lists
                                     if coach.key() not in l.coaches]

        try:
            student.remove_coach(coach.key_email)
        except ValueError:
            pass

        try:
            student.remove_coach(coach.key_email.lower())
        except ValueError:
            pass
예제 #7
0
    def remove_student_from_coach(student, coach):
        if student.student_lists:
            actual_lists = StudentList.get(student.student_lists)
            student.student_lists = [
                l.key() for l in actual_lists if coach.key() not in l.coaches
            ]

        try:
            student.remove_coach(coach.key_email)
        except ValueError:
            pass

        try:
            student.remove_coach(coach.key_email.lower())
        except ValueError:
            pass
예제 #8
0
    def get(self):
        user_data = UserData.current()
        user_data_override = self.request_user_data("coach_email")
        if user_util.is_current_user_developer() and user_data_override:
            user_data = user_data_override

        invalid_student = self.request_bool("invalid_student", default = False)

        coach_requests = [x.student_requested_data.email for x in CoachRequest.get_for_coach(user_data) if x.student_requested_data]

        student_lists_models = StudentList.get_for_coach(user_data.key())
        student_lists_list = [];
        for student_list in student_lists_models:
            student_lists_list.append({
                'key': str(student_list.key()),
                'name': student_list.name,
            })
        student_lists_dict = dict((g['key'], g) for g in student_lists_list)

        students_data = user_data.get_students_data()
        students = map(lambda s: {
            'key': str(s.key()),
            'email': s.email,
            'nickname': s.nickname,
            'profile_root': s.profile_root,
            'studentLists': [l for l in [student_lists_dict.get(str(list_id)) for list_id in s.student_lists] if l],
        }, students_data)
        students.sort(key=lambda s: s['nickname'])

        template_values = {
            'students': students,
            'students_json': json.dumps(students),
            'student_lists': student_lists_list,
            'student_lists_json': json.dumps(student_lists_list),
            'invalid_student': invalid_student,
            'coach_requests': coach_requests,
            'coach_requests_json': json.dumps(coach_requests),
            'selected_nav_link': 'coach',
            'email': user_data.email,
        }
        self.render_jinja2_template('viewstudentlists.html', template_values)
예제 #9
0
 def get_student_list(self, coach):
     student_lists = StudentList.get_for_coach(coach.key())
     current_user_is_coach = (coach.key() == UserData.current().key())
     _, actual_list = util_profile.get_last_student_list(self,
             student_lists, current_user_is_coach)
     return actual_list
예제 #10
0
    def get(self):
        user_data = UserData.current()
        user_data_override = self.request_user_data("coach_email")
        if user_util.is_current_user_developer() and user_data_override:
            user_data = user_data_override

        invalid_student = self.request_bool("invalid_student", default=False)

        coach_requests = [
            req.student_requested_identifier
            for req in CoachRequest.get_for_coach(user_data)
            if req.student_requested_data
        ]

        student_lists_models = StudentList.get_for_coach(user_data.key())
        student_lists_list = []
        for student_list in student_lists_models:
            student_lists_list.append({
                'key': str(student_list.key()),
                'name': student_list.name,
            })
        student_lists_dict = dict((g['key'], g) for g in student_lists_list)

        def student_to_dict(s):
            """Convert the UserData s to a dictionary for rendering."""
            return {
                'key':
                str(s.key()),
                'email':
                s.email,
                'username':
                s.username,
                # Note that child users don't have an email.
                'identifier':
                s.username or s.email,
                'nickname':
                s.nickname,
                'profile_root':
                s.profile_root,
                'can_modify_coaches':
                s.can_modify_coaches(),
                'studentLists': [
                    l for l in [
                        student_lists_dict.get(str(list_id))
                        for list_id in s.student_lists
                    ] if l
                ],
            }

        students_data = user_data.get_students_data()
        students = map(student_to_dict, students_data)
        students.sort(key=lambda s: s['nickname'])

        child_accounts = map(student_to_dict, user_data.get_child_users())
        template_values = {
            'students': students,
            'child_accounts': child_accounts,
            'child_account_keyset': set([c['key'] for c in child_accounts]),
            'students_json': json.dumps(students),
            'student_lists': student_lists_list,
            'student_lists_json': json.dumps(student_lists_list),
            'invalid_student': invalid_student,
            'coach_requests': coach_requests,
            'coach_requests_json': json.dumps(coach_requests),
            'selected_nav_link': 'coach',
            'email': user_data.email,
        }
        self.render_jinja2_template('viewstudentlists.html', template_values)
예제 #11
0
 def get_student_list(self, coach):
     student_lists = StudentList.get_for_coach(coach.key())
     _, actual_list = get_last_student_list(
         self, student_lists,
         coach.key() == UserData.current().key())
     return actual_list
예제 #12
-1
 def get_student_list(self, coach):
     student_lists = StudentList.get_for_coach(coach.key())
     _, actual_list = get_last_student_list(self, student_lists, coach.key()==UserData.current().key())
     return actual_list