Esempio n. 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
Esempio n. 2
0
    def get(self):
        user_data = UserData.current()

        if user_data:

            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,
                    'student_lists': [
                        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'
            }
            self.render_jinja2_template('viewstudentlists.html',
                                        template_values)
        else:
            self.redirect(util.create_login_url(self.request.uri))
Esempio n. 3
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
Esempio n. 4
0
def get_list(coach, request_handler):
    list_id = request_handler.request_string('list_id')
    student_list = StudentList.get(list_id)
    if student_list is None:
        raise Exception("No list found with list_id='%s'." % list_id)
    if coach.key() not in student_list.coaches:
        raise Exception("Not your list!")
    return student_list
Esempio n. 5
0
def get_list(coach, request_handler):
    list_id = request_handler.request_string("list_id")
    student_list = StudentList.get(list_id)
    if student_list is None:
        raise Exception("No list found with list_id='%s'." % list_id)
    if coach.key() not in student_list.coaches:
        raise Exception("Not your list!")
    return student_list
Esempio n. 6
0
    def get(self):
        coach = UserData.current()

        if coach:

            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': 'כל התלמידים'.decode("utf8"),
            }];
            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
            
            exercises = models.Exercise.get_all_use_cache()
            exercises.sort(key=lambda ex: ex.display_name)

            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': exercises,
                    '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)
        else:
            self.redirect(util.create_login_url(self.request.uri))
Esempio n. 7
0
    def get(self):
        coach = UserData.current()

        if coach:

            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
            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': simplejson.dumps(student_lists_list),
                'coach_nickname': coach.nickname,
                'selected_graph_type': selected_graph_type,
                'initial_graph_url': initial_graph_url,
                'exercises': models.Exercise.get_all_use_cache(),
                'is_profile_empty': not coach.has_students(),
                'selected_nav_link': 'coach',
                "view": self.request_string("view", default=""),
            }
            self.render_jinja2_template('viewclassprofile.html',
                                        template_values)
        else:
            self.redirect(util.create_login_url(self.request.uri))
Esempio n. 8
0
    def post(self):
        coach_data = UserData.current()

        if not coach_data:
            return

        list_name = self.request_string('list_name')
        if not list_name:
            raise Exception('Invalid list name')

        student_list = StudentList(coaches=[coach_data.key()], name=list_name)
        student_list.put()

        student_list_json = {
            'name': student_list.name,
            'key': str(student_list.key())
        }

        self.render_json(student_list_json)
Esempio n. 9
0
    def post(self):
        coach_data = UserData.current()

        if not coach_data:
            return

        list_name = self.request_string('list_name')
        if not list_name:
            raise Exception('Invalid list name')

        student_list = StudentList(coaches=[coach_data.key()], name=list_name)
        student_list.put()

        student_list_json = {
            'name': student_list.name,
            'key': str(student_list.key())
        }

        self.render_json(student_list_json)
Esempio n. 10
0
    def get(self):
        coach = UserData.current()

        if coach:

            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
            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": simplejson.dumps(student_lists_list),
                "coach_nickname": coach.nickname,
                "selected_graph_type": selected_graph_type,
                "initial_graph_url": initial_graph_url,
                "exercises": models.Exercise.get_all_use_cache(),
                "is_profile_empty": not coach.has_students(),
                "selected_nav_link": "coach",
                "view": self.request_string("view", default=""),
            }
            self.render_jinja2_template("viewclassprofile.html", template_values)
        else:
            self.redirect(util.create_login_url(self.request.uri))
Esempio n. 11
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.coaches.remove(coach.key_email)
        except ValueError:
            pass

        try:
            student.coaches.remove(coach.key_email.lower())
        except ValueError:
            pass

        student.put()
Esempio n. 12
0
def user_studentlists():
    user_data = models.UserData.current()

    if user_data:
        user_data_student = get_visible_user_data_from_request()
        if user_data_student:
            student_lists_model = StudentList.get_for_coach(user_data_student.key())
            student_lists = []
            for student_list in student_lists_model:
                student_lists.append({
                    'key': str(student_list.key()),
                    'name': student_list.name,
                })
            return student_lists

    return None
Esempio n. 13
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.coaches.remove(coach.key_email)
        except ValueError:
            pass

        try:
            student.coaches.remove(coach.key_email.lower())
        except ValueError:
            pass

        student.put()
Esempio n. 14
0
    def get(self):
        user_data = UserData.current()

        if user_data:

            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'
            }
            self.render_jinja2_template('viewstudentlists.html', template_values)
        else:
            self.redirect(util.create_login_url(self.request.uri))
Esempio n. 15
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
Esempio n. 16
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