Esempio n. 1
0
 def approve_or_deny(self,*kw,**kwargs):
     try:
         contentID = kw[0]
         course = get_course_by_id(contentID)
         if course.content['private']:
             googleID = str(user.get_current_user().user_id())
             if googleID not in course.content['approved_students']:
                 raise Exception('not approved to view this course')
     except Exception as e:
         self.write_json({'error': str(e)})
     else:
         decorated_function(self, *kw, **kwargs)
Esempio n. 2
0
 def create_new_approval(self):
     """
     a helper class for quickly creating a new approval item
     """
     teacher = self.create_and_return_local_user()
     course_id = new_course({
         'teacher': teacher.key.id(),
         'title': 'foo course',
         'body': 'hey look mom',
     })
     new_approval_request(course=get_course_by_id(course_id),
                          googleID='123',
                          formalName='John Doe',
                          email='*****@*****.**')
 def create_new_approval(self):
     """
     a helper class for quickly creating a new approval item
     """
     teacher = self.create_and_return_local_user()
     course_id = new_course({
         'teacher' : teacher.key.id(),
         'title' : 'foo course',
         'body' : 'hey look mom',
         })
     new_approval_request(
         course = get_course_by_id(course_id), 
         googleID='123', 
         formalName='John Doe', 
         email='*****@*****.**')
Esempio n. 4
0
def user_to_dict(user):
    """
    return a dictionary object based on the user model passed
    """
    data = {}

    data['username'] = user.username
    data['username_lower'] = user.username_lower
    data['id'] = user.key.id()
    data['googleID'] = user.googleID
    data['formal_name'] = user.formalName
    data['email'] = user.email
    data['bio'] = user.bio
    data['stripeID'] = user.stripeID
    data['courses'] = []
    if user.courses:
        for course_id in user.courses:
            course = get_course_by_id(course_id)
            data['courses'].append(content_to_dict(course))

    return data
Esempio n. 5
0
def user_to_dict(user):
    """
    return a dictionary object based on the user model passed
    """
    data = {}

    data['username'] = user.username
    data['username_lower'] = user.username_lower
    data['id'] = user.key.id()
    data['googleID'] = user.googleID
    data['formal_name'] = user.formalName
    data['email'] = user.email
    data['bio'] = user.bio
    data['stripeID'] = user.stripeID
    data['courses'] = []
    if user.courses:
        for course_id in user.courses:
            course = get_course_by_id(course_id)
            data['courses'].append(content_to_dict(course))

    return data
    def create_several_approvals_for_course(self, number_of_courses=1):
        """
        create a course then approve several googleID's to access the course

        a helper method for the tests in this class; returns the course for 
        which the approvals were generated. If more than 1 course is created, 
        return the user instead of course/ids
        """
        teacher = self.create_and_return_local_user()
        for N in range(number_of_courses):
            course_id = new_course({
                'teacher': teacher.key.id(),
                'title': 'foo course',
                'body': 'hey look mom',
            })
            list_of_ids_to_approve = [1, 2, 3, 4, 5]
            course = get_course_by_id(course_id)
            for i in list_of_ids_to_approve:
                new_approval_request(course=course,
                                     googleID=i,
                                     formalName='John Doe %s' % i,
                                     email='*****@*****.**' % i)
    def create_several_approvals_for_course(self, number_of_courses = 1):
        """
        create a course then approve several googleID's to access the course

        a helper method for the tests in this class; returns the course for 
        which the approvals were generated. If more than 1 course is created, 
        return the user instead of course/ids
        """
        teacher = self.create_and_return_local_user()
        for N in range(number_of_courses):
            course_id = new_course({
                'teacher' : teacher.key.id(),
                'title' : 'foo course',
                'body' : 'hey look mom',
                })
            list_of_ids_to_approve = [1,2,3,4,5]
            course = get_course_by_id(course_id)
            for i in list_of_ids_to_approve:
                new_approval_request(
                    course = course, 
                    googleID=i, 
                    formalName='John Doe %s' % i, 
                    email='*****@*****.**' % i
                    )