Exemple #1
0
 def reload_usercourse(self, request, term_id):
     term = Term.objects.filter(term_id = term_id).first()        
     #self.model.objects.filter(course__term = term).delete()
     creds = UserCredentials()
     api = CanvasAPI(term = term_id)
     
     course_list = Course.objects.filter(term = term)
     for course in course_list:
         course_users = api.get_course_enrollments(course.course_id)
         for user in course_users:
             localuser = User.objects.filter(canvas_id = user["user_id"]).first()
             if localuser is not None:
                 isTeacher = False
                 if (user["type"] == "TeacherEnrollment"):
                     isTeacher = True
                     
                 usercourse_record = self.model.objects.filter(user = localuser, course = course).first()
                 if usercourse_record is None: 
                     #logging.warning("Creating UserCourse record for: " + str(localuser))
                     usercourse_create = self.model.objects.create(user = localuser, course = course, is_teacher = isTeacher)
                     usercourse_create.save()
                 else:
                     usercourse_record.is_teacher = isTeacher
                     usercourse_record.save()
         
     self.message_user(request, "User Course (Enrollments) list successfully reloaded!")
     return HttpResponseRedirect("../../")
Exemple #2
0
def load_usercourse_data_for_term(term_id):
    if term_id is not None:
        term = Term.objects.filter(term_id=term_id).first()
        UserCourse.objects.filter(course__term=term).delete()
        api = CanvasAPI(term_id)

        course_list = Course.objects.filter(term=term)
        for course in course_list:
            course_users = api.get_course_enrollments(course.course_id)
            for user in course_users:
                localuser = User.objects.filter(
                    canvas_id=user["user_id"]).first()
                if localuser is not None:
                    isTeacher = False
                    if (user["type"] == "TeacherEnrollment"):
                        isTeacher = True
                    usercourse_create = UserCourse.objects.create(
                        user=localuser, course=course, is_teacher=isTeacher)
                    usercourse_create.save()