コード例 #1
0
ファイル: handlers.py プロジェクト: Hao-Hsuan/KhanLatest
    def authenticated_response(self):
        user_data = UserData.current()
        user_email = user_data.user_email
        nickname = ""
        if facebook_util.is_facebook_user_id(user_email):
            nickname = facebook_util.get_facebook_nickname(user_email)

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

        students = []
        is_parent = False

        if student is None:
            query = SummerParentData.all()
            query.filter('email = ', user_email)
            parent = query.get()
            if parent is None:
                return None

            is_parent = True
            number_of_students = 0
            for student_key in parent.students:
                student = SummerStudent.get(student_key)
                students.append(student)
                if student.accepted and not student.tuition_paid:
                    number_of_students += 1

        else:
            number_of_students = 1
            students.append(student)

        template_values = {
            "authenticated" : True,
            "is_parent" : is_parent,
            "students" : students,
            "number_of_students": json.dumps(number_of_students),
            "student" : students[0],
            "user_email" : user_email,
            "nickname" : nickname,
        }

        return template_values
コード例 #2
0
ファイル: handlers.py プロジェクト: Hao-Hsuan/KhanLatest
    def authenticated_response(self):
        user_data = UserData.current()
        user_email = user_data.user_email
        nickname = ""
        if facebook_util.is_facebook_user_id(user_email):
            nickname = facebook_util.get_facebook_nickname(user_email)

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

        students = []
        is_parent = False

        if student is None:
            query = SummerParentData.all()
            query.filter('email = ', user_email)
            parent = query.get()
            if parent is None:
                return None

            is_parent = True
            for student_key in parent.students:
                students.append(SummerStudent.get(student_key))

        else:
            students.append(student)

        template_values = {
            "authenticated" : True,
            "is_parent" : is_parent,
            "students" : students,
            "user_email" : user_email,
            "nickname" : nickname,
        }

        return template_values
コード例 #3
0
ファイル: handlers.py プロジェクト: Hao-Hsuan/KhanLatest
    def authenticated_response(self):
        user_data = UserData.current()
        user_email = user_data.user_email
        nickname = ""
        if facebook_util.is_facebook_user_id(user_email):
            nickname = facebook_util.get_facebook_nickname(user_email)

        students = []
        is_parent = False
        query = SummerStudent.all()
        query.filter('email = ', user_email)
        student = query.get()

        if student is not None:
            students.append(student)
        else:
            query = SummerParentData.all()
            query.filter('email = ', user_email)
            parent = query.get()
            if parent is not None:
                is_parent = True
                for student_key in parent.students:
                    students.append(SummerStudent.get(student_key))

        if len(students) > 0:
            applied = True
            student_email = self.request.get('student_email')
            query = SummerStudent.all()
            query.filter('email = ', student_email)
            student = query.get()
            if student is None:
                logging.error("Student <%s> not expected to be NULL in datastore, but it is" % student_email)
                student = students[0]

            query = SummerParentData.all()
            query.filter('email = ', student.parent_email)
            parent = query.get()
            assert(parent != None)

            student_js = json.dumps(student.to_dict())
            parent_js = json.dumps(parent.to_dict())
        else:
            applied = False
            student = None
            parent = None
            student_js = json.dumps(student)
            parent_js = json.dumps(parent)

        template_values = {
            "authenticated" : True,
            "applied" : applied,
            "is_parent" : is_parent,
            "is_parent_js" : json.dumps(is_parent),
            "students" : students,
            "student" : student,
            "student_js" : student_js,
            "parent" : parent,
            "parent_js" : parent_js,
            "user_email_js" : json.dumps(user_email),
            "user_email" : user_email,
            "nickname" : nickname,
        }

        return template_values
コード例 #4
0
ファイル: handlers.py プロジェクト: Hao-Hsuan/KhanLatest
    def get(self):
        logging.info("Accessing %s" % self.request.path)
        txn_id = self.request.get('txn_id')
        student_email = self.request.get('custom')

        charset = self.request.get('charset')
        parameters = dict((arg, self.request.get(arg).encode(charset)) for arg in self.request.arguments())
        parameters['cmd'] = "_notify-validate"
        req = urllib2.Request(PAYPAL_URL, urllib.urlencode(parameters))
        req.add_header("Content-type", "application/x-www-form-urlencoded")

        response = urllib2.urlopen(req)
        status = response.read()
        if status == "VERIFIED":
            query = SummerPaypalTransaction.all()
            query.filter('transaction_id = ', txn_id)
            paypal_txn = query.get()

            if paypal_txn is None:
                paypal_txn = SummerPaypalTransaction()
                paypal_txn.transaction_id = txn_id
                paypal_txn.status = "Initiated"

            paypal_txn.student_email = student_email
            if 'payment_status' in parameters:
                paypal_txn.status = parameters['payment_status']

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

            if student is None:
                logging.error("Student not found in DB for email <%s>" % student_email)
            else:
                if 'mc_gross' in parameters:
                    total_amount = int(parameters['mc_gross'])
                    if total_amount >= 1000:
                        # This is tuition
                        parent = SummerParentData.all().filter('email =', student.parent_email).get()
                        number_of_students = 0
                        students = []
                        for skey in parent.students:
                            s = SummerStudent.get(skey)
                            if s.accepted and not s.tuition_paid:
                               students.append(s)
                               number_of_students += 1

                        fee_per_student = int(total_amount/number_of_students)
                        if fee_per_student < 1000:
                            # Tuition is paid using the student's account
                            student.tuition = parameters['mc_gross']

                            if paypal_txn.status == "Completed":
                                student.tuition_paid = True
                            else:
                                student.tuition_paid = False

                            student.put()

                        else:
                            # Tuition paid using parent's account. This works because
                            # if paying via parent, then tuition for all students have
                            # to be paid together
                            for student in students:
                                student.tuition = str(fee_per_student)

                                if paypal_txn.status == "Completed":
                                    student.tuition_paid = True
                                else:
                                    student.tuition_paid = False

                                student.put()
                    else:
                        student.processing_fee = parameters['mc_gross']

                        if paypal_txn.status == "Completed":
                            student.processing_fee_paid = True
                        else:
                            student.processing_fee_paid = False

                        student.put()

            paypal_txn.put()
        else:
            logging.error("Paypal did not verify the IPN response transaction id <%s>" % txn_id)

        return
コード例 #5
0
ファイル: handlers.py プロジェクト: Hao-Hsuan/KhanLatest
                        nvp = output[i].split('=')
                        paypal_attr[nvp[0]] = nvp[1]

                    if 'payment_status' in paypal_attr:
                        paypal_txn.status = paypal_attr['payment_status']

                    if 'mc_gross' in paypal_attr:
                        total_amount = int(paypal_attr['mc_gross'])
                        if total_amount >= 1000:
                            # This is tuition
                            parent = SummerParentData.all().filter('email =', student.parent_email).get()

                            number_of_students = 0
                            students = []
                            for skey in parent.students:
                                s = SummerStudent.get(skey)
                                if s.accepted and not s.tuition_paid:
                                    students.append(s)
                                    number_of_students += 1

                            fee_per_student = int(total_amount/number_of_students)
                            if fee_per_student < 1000:
                                # Tuition is paid using student's account
                                student.tuition = paypal_attr['mc_gross']

                                if paypal_txn.status == "Completed":
                                    student.tuition_paid = True
                                else:
                                    student.tuition_paid = False

                                student.put()