Ejemplo n.º 1
0
    def get(self):
	template_values = {}
	oauth_util = OAuthUtil()
	access_token_key = self.request.cookies.get('access_key')
	token = self.request.get('oauth_token')

	if access_token_key:
	    access_token_secret = self.request.cookies.get('access_secret')
	    oauth_util.set_access_token(access_token_key, access_token_secret)
	    template_values = self.authenticated_response(oauth_util)

        elif token:
            oauth_util.get_access_token(self)
	    template_values = self.authenticated_response(oauth_util)
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_key",oauth_util.access_token.key,max_age=2629743))
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_secret",oauth_util.access_token.secret,max_age=2629743))

	else:
	    oauth_url = oauth_util.get_request_token_url(self.request.url)

            template_values = {
	        "callback" : False,
	        "done" : False,
	        "login_url" : oauth_url
	    }

        self.response.out.write(template.render('default.html', template_values))
Ejemplo n.º 2
0
    def get(self):
	oauth_util = OAuthUtil()
        token = self.request.get('oauth_token')
        proxy_coach_email = self.request.get('proxy_coach_email')

        if proxy_coach_email:
	    oauth_util.set_access_token(self.request.get('access_token_key'),
			                self.request.get('access_token_secret'))
	    user = json.loads(oauth_util.access_resource("/api/v1/user?email=%s" % (proxy_coach_email)))
	    if user is None or user['email'] != proxy_coach_email:
		self.response.set_status(401)
                self.response.out.write('Not Authorized')
		return

            proxy_coach_key_email = user['key_email']
            query = UserGoals.all()
	    query.filter('coaches =', proxy_coach_key_email)
	    user_goals = query.fetch(1000)

            class_goals_report = "Student,Goal 1,Goal 2,Goal 3,Goal 4,Goal 5,Goal 6\n"
	    for goals in user_goals:
                class_goals_report += goals.user
		for goal in goals.goals:
		    class_goals_report += ",%s" % goal
		class_goals_report += "\n"

            self.response.headers['Content-Type'] = "text/csv"
	    self.response.headers['Content-Disposition'] = "attachment; filename=class_goals.csv"

	    self.response.out.write(class_goals_report)

	elif token:
            oauth_util.get_access_token(self)
	    template_values = self.authenticated_response(oauth_util)
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_key",oauth_util.access_token.key,max_age=2629743))
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_secret",oauth_util.access_token.secret,max_age=2629743))

            self.response.out.write(template.render('goalsreportadmin.html', template_values))

	else:
	    access_token_key = self.request.cookies.get('access_key')
	    access_token_secret = self.request.cookies.get('access_secret')
	    if access_token_key:
	        oauth_util.set_access_token(access_token_key, access_token_secret)
	        template_values = self.authenticated_response(oauth_util)

            else:
	        oauth_url = oauth_util.get_request_token_url(self.request.url)

                template_values = {
	            "callback" : False,
		    "done" : False,
	            "login_url" : oauth_url
	        }

            self.response.out.write(template.render('goalsreportadmin.html', template_values))
Ejemplo n.º 3
0
    def get(self):
	oauth_util = OAuthUtil()
	token = self.request.get('oauth_token')
	coach_email = self.request.get('coach_email')

        if coach_email:
	    template_values = {
	        "username" : coach_email,
		"logged_in" : True,
		"logout_url" : "/logout",
		"done" : True,
		"coach_email" : coach_email
	    }

        elif token:
	    oauth_util.get_access_token(self)
	    template_values = self.authenticated_response(oauth_util)
	    self.response.headers.add_header('Set-Cookie',
	        cookie_util.set_cookie_value("access_key",oauth_util.access_token.key,max_age=2629743))
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_secret",oauth_util.access_token.secret,max_age=2629743))

	else:
	    access_token_key = self.request.cookies.get('access_key')
	    access_token_secret = self.request.cookies.get('access_secret')
	    if access_token_key:
	        oauth_util.set_access_token(access_token_key, access_token_secret)
	        template_values = self.authenticated_response(oauth_util)

	    else:
	        oauth_url = oauth_util.get_request_token_url(self.request.url)

	        template_values = {
	            "callback" : False,
		    "done" : False,
		    "login_url" : oauth_url
                }

	self.response.out.write(template.render('uploadfile.html', template_values))
Ejemplo n.º 4
0
    def get(self):
	oauth_util = OAuthUtil()
        token = self.request.get('oauth_token')
        coach_email = self.request.get('coach_email')

        if coach_email:
	    oauth_util.set_access_token(self.request.get('access_token_key'),
			                self.request.get('access_token_secret'))
            class_data = ClassData()
	    class_data.coach = coach_email
	    class_data.mailto = coach_email
	    class_data.unique_key = ''.join(random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") for x in range(10))

            activity_log = self.request.get('activity_log')
	    if activity_log == '1':
                class_data.activity_log = True

            goals_data = self.request.get('goals_data')
            if goals_data == '1':
                class_data.generate_goals_dashboard = True

                user = json.loads(oauth_util.access_resource("/api/v1/user?email=%s" % coach_email))
		if user is None or user['email'] != coach_email:
                    self.response.set_status(401)
	            self.response.out.write("Not Authorized")
	            return

                coach_suggested_goals = self.request.get('coach_suggested_goals')
		coach_key_email = user['key_email']
                if coach_suggested_goals == '1':
                    list_id = self.request.get('list_id')
                    if not list_id or list_id == "allstudents":
                        students = json.loads(oauth_util.access_resource(
                                              "/api/v1/user/students?email=%s" % coach_email))
                        list_id = "allstudents"
                    else:
                        students = json.loads(oauth_util.access_resource(
                                              "/api/v1/user/students?email=%s&list_id=%s" %
                                              (coach_email, list_id)))

                    query = CoachSuggestions.all()
	            query.filter('coach =', coach_key_email)
	            query.filter('list_id =', list_id)
	            coach_suggestions = query.get()

                    class_data.student_goals = "Student,"
                    for i in range(0,len(coach_suggestions.suggestions)):
                        class_data.student_goals += "Goal %d," % (i+1)
                    class_data.student_goals += "\n"

                    for student in students:
                        class_data.student_goals += student['email']
                        if len(coach_suggestions.suggestions) > 0:
                            for suggestion in coach_suggestions.suggestions:
                                class_data.student_goals += ",%s" % suggestion
                            class_data.student_goals += "\n"
                else:
                    query = UserGoals.all()
	            query.filter('coaches =', coach_key_email)
	            user_goals = query.fetch(1000)

                    class_data.student_goals = "Student,Goal 1,Goal 2,Goal 3,Goal 4,Goal 5,Goal 6\n"
	            for goals in user_goals:
                        class_data.student_goals += goals.user
		        for goal in goals.goals:
		            class_data.student_goals += ",%s" % goal
		        class_data.student_goals += "\n"

            proxy_coach = self.request.get('proxy_coach')
	    if proxy_coach:
                class_data.mailto = proxy_coach
		coach_email = proxy_coach

	    class_data.tz_offset_mins = int(self.request.get('tz_offset'))
	    class_data.access_token = oauth_util.access_token
            class_data.consumer_key = oauth_util.consumer_key
            class_data.consumer_secret = oauth_util.consumer_secret
	    class_data.server_url = oauth_util.server_url
            class_data.list_id = self.request.get('list_id')

            class_data.run()

	    template_values = {
	        "username" : coach_email,
	        "logged_in" : True,
	        "logout_url" : "/logout",
		"done" : True,
	        "coach_email" : coach_email,
	    }

	elif token:
            oauth_util.get_access_token(self)
	    template_values = self.authenticated_response(oauth_util)
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_key",oauth_util.access_token.key,max_age=2629743))
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_secret",oauth_util.access_token.secret,max_age=2629743))

	else:
	    access_token_key = self.request.cookies.get('access_key')
	    access_token_secret = self.request.cookies.get('access_secret')
	    if access_token_key:
	        oauth_util.set_access_token(access_token_key, access_token_secret)
		template_values = self.authenticated_response(oauth_util)

	    else:
	        oauth_url = oauth_util.get_request_token_url(self.request.url)

                template_values = {
	            "callback" : False,
		    "done" : False,
	            "login_url" : oauth_url
	        }

        self.response.out.write(template.render('classreport.html', template_values))
Ejemplo n.º 5
0
    def get(self):
	oauth_util = OAuthUtil()
        token = self.request.get('oauth_token')
        coach_email = self.request.get('coach_email')

        if coach_email:
	    oauth_util.set_access_token(self.request.get('access_token_key'),
			                self.request.get('access_token_secret'))
	    user = json.loads(oauth_util.access_resource("/api/v1/user"))
	    coach_key_email = user['key_email']

            list_id = self.request.get('list_id')
	    student_emails = []
            if list_id and list_id != "allstudents":
                students = json.loads(oauth_util.access_resource(
                                      "/api/v1/user/students?email=%s&list_id=%s" %
                                      (coach_email, list_id)))

	        if students is not None:
	            for student in students:
	                student_emails.append(student['email'])

            query = UserGoals.all()
	    query.filter('coaches =', coach_key_email)
            if list_id and list_id != "allstudents":
                query.filter('user IN', student_emails)
	    user_goals = query.fetch(1000)

            class_goals_report = "Student,Goal 1,Goal 2,Goal 3,Goal 4,Goal 5,Goal 6\n"
	    for goals in user_goals:
                class_goals_report += goals.user
		for goal in goals.goals:
		    class_goals_report += ",%s" % goal
		class_goals_report += "\n"

            self.response.headers['Content-Type'] = "text/csv"
	    self.response.headers['Content-Disposition'] = "attachment; filename=class_goals.csv"

	    self.response.out.write(class_goals_report)

	elif token:
            oauth_util.get_access_token(self)
	    template_values = self.authenticated_response(oauth_util)
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_key",oauth_util.access_token.key,max_age=2629743))
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_secret",oauth_util.access_token.secret,max_age=2629743))

            self.response.out.write(template.render('goalsreport.html', template_values))

	else:
	    access_token_key = self.request.cookies.get('access_key')
	    access_token_secret = self.request.cookies.get('access_secret')
	    if access_token_key:
	        oauth_util.set_access_token(access_token_key, access_token_secret)
	        template_values = self.authenticated_response(oauth_util)

            else:
	        oauth_url = oauth_util.get_request_token_url(self.request.url)

                template_values = {
	            "callback" : False,
		    "done" : False,
	            "login_url" : oauth_url
	        }

            self.response.out.write(template.render('goalsreport.html', template_values))
Ejemplo n.º 6
0
    def get(self):
	oauth_util = OAuthUtil()
        token = self.request.get('oauth_token')
        student_email = self.request.get('student_email')

	if student_email:
	    goal_1 = self.request.get('goal_1')
	    goal_2 = self.request.get('goal_2')
	    goal_3 = self.request.get('goal_3')
	    goal_4 = self.request.get('goal_4')
	    goal_5 = self.request.get('goal_5')
	    goal_6 = self.request.get('goal_6')

            # send an email to the student with their goals
	    send_email = self.request.get('send_email')
	    if send_email == '1':
	        fromaddr = '*****@*****.**'
	        toaddr = student_email
	        subject = 'Khan Academy goals'
	        body = "Hello %s,\n\nYou have set the following exercises as your current Khan Academy goals.\n\n%s\n%s\n%s\n%s\n%s\n%s\n\nWe wish you good luck in attaining these goals\n\nCheers!\nKhan Academy Implementation team" % (student_email.split('@')[0],goal_1,goal_2,goal_3,goal_4,goal_5,goal_6)
	        mail.send_mail(sender=fromaddr,
			       to=toaddr,
			       subject=subject,
			       body=body)

	    oauth_util.set_access_token(self.request.get('access_token_key'),
			                self.request.get('access_token_secret'))
	    user = json.loads(oauth_util.access_resource("/api/v1/user"))

            query = UserGoals.all()
	    query.filter('user ='******'coaches']
	    user_goals.goals = []
	    if goal_1 is not None:
                user_goals.goals.append(goal_1)
	    if goal_2 is not None:
                user_goals.goals.append(goal_2)
	    if goal_3 is not None:
                user_goals.goals.append(goal_3)
	    if goal_4 is not None:
                user_goals.goals.append(goal_4)
	    if goal_5 is not None:
                user_goals.goals.append(goal_5)
	    if goal_6 is not None:
                user_goals.goals.append(goal_6)

	    user_goals.put()

	    template_values = {
	        "username" : student_email,
	        "logged_in" : True,
	        "logout_url" : "/logout",
	        "done" : True,
		"student_email" : student_email,
		"current_goals" : user_goals.goals
	    }

	elif token:
            oauth_util.get_access_token(self)
	    template_values = self.authenticated_response(oauth_util)
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_key",oauth_util.access_token.key,max_age=2629743))
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_secret",oauth_util.access_token.secret,max_age=2629743))

	else:
	    access_token_key = self.request.cookies.get('access_key')
	    access_token_secret = self.request.cookies.get('access_secret')
	    if access_token_key:
	        oauth_util.set_access_token(access_token_key, access_token_secret)
	        template_values = self.authenticated_response(oauth_util)

            else:
	        oauth_url = oauth_util.get_request_token_url(self.request.url)

                template_values = {
	            "callback" : False,
		    "done" : False,
	            "login_url" : oauth_url
	        }

        self.response.out.write(template.render('goals.html', template_values))
Ejemplo n.º 7
0
    def get(self):
	oauth_util = OAuthUtil()
        token = self.request.get('oauth_token')
        coach_email = self.request.get('coach_email')

	if coach_email:
            list_id = self.request.get('list_id')
            if not list_id:
                list_id = "allstudents"
            display_only = self.request.get('display_only')
	    oauth_util.set_access_token(self.request.get('access_token_key'),
                                        self.request.get('access_token_secret'))
            if not display_only:
	        exercises = json.loads(oauth_util.access_resource("/api/v1/exercises"))
	        suggestions = []
                for exercise in exercises:
		    suggestion = self.request.get(exercise['display_name'])
		    if suggestion is not None:
		        if len(suggestion) > 0:
		            suggestions.append(suggestion)

                coach_key_email = json.loads(oauth_util.access_resource("/api/v1/user?email=%s" % coach_email))['key_email']
                query = CoachSuggestions.all()
                query.filter('coach =', coach_key_email)
                query.filter('list_id =', list_id)
                coach_suggestions = query.get()

	        if coach_suggestions is None:
		    coach_suggestions = CoachSuggestions()
		    coach_suggestions.coach = coach_key_email
                    coach_suggestions.list_id = list_id
		    coach_suggestions.suggestions = suggestions
	        else:
		    coach_suggestions.suggestions = suggestions

	        coach_suggestions.put()
            else:
                coach_key_email = json.loads(oauth_util.access_resource("/api/v1/user?email=%s" % coach_email))['key_email']
                query = CoachSuggestions.all()
                query.filter('coach =', coach_key_email)
                query.filter('list_id =', list_id)
                coach_suggestions = query.get()

                suggestions = []
                if coach_suggestions is not None:
                    suggestions = coach_suggestions.suggestions


            student_list = json.loads(oauth_util.access_resource("/api/v1/user/studentlists?email=%s" % coach_email))
            student_list.insert(0, {
                "key" : "allstudents",
                "name" : "All Students"
            })

	    template_values = {
	        "username" : coach_email,
	        "logged_in" : True,
	        "logout_url" : "/logout",
	        "done" : True,
		"coach_email" : json.dumps(coach_email),
	        "access_token_key" : json.dumps(oauth_util.access_token.key),
	        "access_token_secret" : json.dumps(oauth_util.access_token.secret),
		"coach_suggestions" : suggestions,
                "student_list" : student_list,
                "current_suggestions" : json.dumps(""),
                "filter_grade" : json.dumps(""),
                "filter_domain" : json.dumps(""),
		"list_id" : json.dumps(list_id)
	    }

	elif token:
            oauth_util.get_access_token(self)
	    template_values = self.authenticated_response(oauth_util)
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_key",oauth_util.access_token.key,max_age=2629743))
	    self.response.headers.add_header('Set-Cookie',
		cookie_util.set_cookie_value("access_secret",oauth_util.access_token.secret,max_age=2629743))

	else:
	    access_token_key = self.request.cookies.get('access_key')
	    access_token_secret = self.request.cookies.get('access_secret')
	    if access_token_key:
	        oauth_util.set_access_token(access_token_key, access_token_secret)
	        template_values = self.authenticated_response(oauth_util)

            else:
	        oauth_url = oauth_util.get_request_token_url(self.request.url)

                template_values = {
	            "callback" : False,
		    "done" : False,
	            "login_url" : oauth_url
	        }

        self.response.out.write(template.render('suggestgoals.html', template_values))
Ejemplo n.º 8
0
    def get(self):
        template_values = {}
        oauth_util = OAuthUtil()
        token = self.request.get('oauth_token')
        user_email = self.request.get('user_email')
        make_payment = self.request.get('make_payment')

        if make_payment:
            student_email = self.request.get('student_email')
            is_parent_str = self.request.get('is_parent')

            query = SummerStudent.all()
            query.filter('email = ', student_email)
            student = query.get()

            if student is None:
                output_str = 'Please <a href="/summer/application">apply</a> first' % student_email
                self.response.out.write(output_str)
                return

            query = ParentData.all()
            query.filter('email = ', student.parent_email)
            parent = query.get()

            if parent is None:
                logging.error(
                    "Unexpected NULL parent for student <%s> with parent <%s>"
                    % (student_email, student.parent_email))

            if is_parent_str == "True":
                is_parent = True
                payee = parent
            else:
                is_parent = False
                payee = student

            payee_phone_a = ""
            payee_phone_b = ""
            payee_phone_c = ""
            phone_parts = parent.phone.split("-")
            if phone_parts is not None:
                payee_phone_a = phone_parts[0]
                payee_phone_b = phone_parts[1]
                payee_phone_c = phone_parts[2]

            template_values = {
                "authenticated": True,
                "make_payment": True,
                "is_parent": is_parent,
                "is_parent_js": json.dumps(is_parent),
                "student": student,
                "student_js": json.dumps(student.to_dict()),
                "payee": payee,
                "payee_phone_a": payee_phone_a,
                "payee_phone_b": payee_phone_b,
                "payee_phone_c": payee_phone_c,
                "user_email": user_email,
                "username": user_email,
                "logged_in": True,
                "logout_url": "/logout"
            }

        elif user_email:
            first_name = self.request.get('first_name')
            student_email = self.request.get('student_email')

            query = SummerStudent.all()
            query.filter('email = ', student_email)
            student = query.get()
            if student is None:
                student = SummerStudent()
                student.email = student_email
                student.applier_email = user_email

            student.first_name = first_name
            student.last_name = self.request.get('last_name')

            student.date_of_birth = self.request.get('date_of_birth')

            if self.request.get('gender') == "Female":
                student.is_female = True
            else:
                student.is_female = False

            student.grade = self.request.get('grade')
            student.school = self.request.get('school')

            student.address_1 = self.request.get('address_1')
            student.address_2 = self.request.get('address_2')
            student.city = self.request.get('city')
            student.state = self.request.get('state')
            student.zipcode = self.request.get('zip')
            student.country = self.request.get('country')

            student.session_1 = self.request.get('session_1')
            student.session_2 = self.request.get('session_2')
            student.session_3 = self.request.get('session_3')

            session_choices = {"0": [], "1": [], "2": [], "3": []}
            session_choices[student.session_1].append("Session 1")
            session_choices[student.session_2].append("Session 2")
            session_choices[student.session_3].append("Session 3")

            student.no_choice = session_choices["0"]
            student.first_choice = session_choices["1"]
            student.second_choice = session_choices["2"]
            student.third_choice = session_choices["3"]

            student.answer_why = self.request.get('answer_why')
            student.answer_how = self.request.get('answer_how')

            student.processing_fee = self.request.get('fee')
            student.processing_fee_paid = False

            student.tuition = 'TBD'
            student.tuition_paid = False

            student.application_year = '2012'
            student.application_status = 'Processing'

            if user_email == student_email:
                is_parent = False
                student.self_applied = True
            else:
                is_parent = True
                student.self_applied = False

            student.parent_relation = self.request.get('relation')
            student.parent_email = self.request.get('parent_email')

            student.put()

            query = ParentData.all()
            query.filter('email = ', student.parent_email)
            parent = query.get()
            if parent is None:
                parent = ParentData()
                parent.email = student.parent_email

            parent.first_name = self.request.get('parent_first_name')
            parent.last_name = self.request.get('parent_last_name')
            parent.address_1 = self.request.get('parent_address_1')
            parent.address_2 = self.request.get('parent_address_2')
            parent.city = self.request.get('parent_city')
            parent.state = self.request.get('parent_state')
            parent.zipcode = self.request.get('parent_zip')
            parent.country = self.request.get('parent_country')
            parent.phone = self.request.get('parent_phone')
            parent.comments = self.request.get('parent_comments')

            if student.key() not in parent.students:
                parent.students.append(student.key())

            parent.put()

            if is_parent:
                payee = parent
            else:
                payee = student

            payee_phone_a = ""
            payee_phone_b = ""
            payee_phone_c = ""
            phone_parts = parent.phone.split("-")
            if phone_parts is not None:
                payee_phone_a = phone_parts[0]
                payee_phone_b = phone_parts[1]
                payee_phone_c = phone_parts[2]

            template_values = {
                "authenticated": True,
                "make_payment": True,
                "is_parent": is_parent,
                "is_parent_js": json.dumps(is_parent),
                "student": student,
                "student_js": json.dumps(student.to_dict()),
                "parent": parent,
                "parent_js": json.dumps(parent.to_dict()),
                "payee": payee,
                "payee_phone_a": payee_phone_a,
                "payee_phone_b": payee_phone_b,
                "payee_phone_c": payee_phone_c,
                "user_email": user_email,
                "username": user_email,
                "logged_in": True,
                "logout_url": "/logout"
            }

        elif token:
            oauth_util.get_access_token(self)
            template_values = self.authenticated_response(oauth_util)
            self.response.headers.add_header(
                'Set-Cookie',
                cookie_util.set_cookie_value("access_key",
                                             oauth_util.access_token.key,
                                             max_age=2629743))
            self.response.headers.add_header(
                'Set-Cookie',
                cookie_util.set_cookie_value("access_secret",
                                             oauth_util.access_token.secret,
                                             max_age=2629743))

        else:
            access_token_key = self.request.cookies.get('access_key')
            access_token_secret = self.request.cookies.get('access_secret')
            if access_token_key:
                oauth_util.set_access_token(access_token_key,
                                            access_token_secret)
                template_values = self.authenticated_response(oauth_util)

            else:
                oauth_url = oauth_util.get_request_token_url(self.request.url)

                template_values = {
                    "authenticated": False,
                    "apply": False,
                    "login_url": oauth_url
                }

        self.response.out.write(template.render('summer.html',
                                                template_values))