Пример #1
0
    def get(self):
        user_data = UserData.current()

        if not user_data:
            self.redirect(util.create_login_url(self.request.uri))
            return

        accept_coach = self.request_bool("accept", default = False)
        user_data_coach = self.request_user_data("coach_email")
        user_data_student = self.request_user_data('student_email')

        if bool(user_data_coach) == bool(user_data_student):
            raise Exception('must provide coach_email xor student_email')

        if user_data_coach:
            user_data_student = user_data
        elif user_data_student:
            user_data_coach = user_data

        if user_data_coach and not user_data_student.is_coached_by(user_data_coach):
            coach_request = CoachRequest.get_for(user_data_coach, user_data_student)
            if coach_request:
                coach_request.delete()

                if user_data.key_email == user_data_student.key_email and accept_coach:
                    user_data_student.coaches.append(user_data_coach.key_email)
                    user_data_student.put()

        if not self.is_ajax_request():
            self.redirect("/coaches")
Пример #2
0
    def get(self):
        user_data = UserData.current()

        if not user_data:
            self.redirect(util.create_login_url(self.request.uri))
            return

        accept_coach = self.request_bool("accept", default = False)
        user_data_coach = self.request_user_data("coach_email")
        user_data_student = self.request_user_data('student_email')

        if bool(user_data_coach) == bool(user_data_student):
            raise Exception('must provide coach_email xor student_email')

        if user_data_coach:
            user_data_student = user_data
        elif user_data_student:
            user_data_coach = user_data

        if user_data_coach and not user_data_student.is_coached_by(user_data_coach):
            coach_request = CoachRequest.get_for(user_data_coach, user_data_student)
            if coach_request:
                coach_request.delete()

                if user_data.key_email == user_data_student.key_email and accept_coach:
                    user_data_student.coaches.append(user_data_coach.key_email)
                    user_data_student.put()

        if not self.is_ajax_request():
            self.redirect("/coaches")
Пример #3
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))
Пример #4
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))
Пример #5
0
    def get(self):
        user_data = UserData.current()

        if user_data:
            invalid_coach = self.request_bool("invalid_coach", default = False)

            coach_requests = CoachRequest.get_for_student(user_data).fetch(1000)

            template_values = {
                        "coach_emails": user_data.coach_emails(),
                        "invalid_coach": invalid_coach,
                        "coach_requests": coach_requests,
                        "student_id": user_data.email,
                        'selected_nav_link': 'coach'
                    }

            self.render_jinja2_template('viewcoaches.html', template_values)
        else:
            self.redirect(util.create_login_url(self.request.uri))
Пример #6
0
    def post(self):
        user_data = UserData.current()

        if not user_data:
            self.redirect(util.create_login_url(self.request.uri))
            return
        user_data_student = self.request_user_data("student_email")
        if user_data_student:
            if not user_data_student.is_coached_by(user_data):
                coach_request = CoachRequest.get_or_insert_for(user_data, user_data_student)
                if coach_request:
                    if not self.is_ajax_request():
                        self.redirect("/students")
                    return

        if self.is_ajax_request():
            self.response.set_status(404)
        else:
            self.redirect("/students?invalid_student=1")
Пример #7
0
    def get(self):
        user_data = UserData.current()

        if user_data:
            invalid_coach = self.request_bool("invalid_coach", default = False)

            coach_requests = CoachRequest.get_for_student(user_data).fetch(1000)

            template_values = {
                        "coach_emails": user_data.coach_emails(),
                        "invalid_coach": invalid_coach,
                        "coach_requests": coach_requests,
                        "student_id": user_data.email,
                        'selected_nav_link': 'coach'
                    }

            self.render_jinja2_template('viewcoaches.html', template_values)
        else:
            self.redirect(util.create_login_url(self.request.uri))
Пример #8
0
    def post(self):
        user_data = UserData.current()

        if not user_data:
            self.redirect(util.create_login_url(self.request.uri))
            return
        user_data_student = self.request_user_data("student_email")
        if user_data_student:
            if not user_data_student.is_coached_by(user_data):
                coach_request = CoachRequest.get_or_insert_for(user_data, user_data_student)
                if coach_request:
                    if not self.is_ajax_request():
                        self.redirect("/students")
                    return

        if self.is_ajax_request():
            self.response.set_status(404)
        else:
            self.redirect("/students?invalid_student=1")