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
    def get(self, subpath=None):
        """Render class profile.

        Keyword arguments:
        subpath -- matches the grouping in /class_profile/(.*) and is ignored
        server-side, but is used to route client-side
        """
        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, _ = util_profile.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)
        # TomY This is temporary until all the graphs are API calls
        if (selected_graph_type == 'progressreport' or
                selected_graph_type == 'goals'):
            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)