def get(self, request, *args, **kwargs): course_id = int(self.kwargs['course_id']) StudentCourse.objects.filter(course__course_id=course_id).delete() course = CanvasCourse.objects.filter(course_id=course_id).first() api = CanvasAPI() assignment_id = self.kwargs['assignment_id'] json_data = api.get_students(course_id) json_list = list(json_data) #the data from canvas for student_record in json_list: #get the stuff i need from the canvas data student_id = student_record['id'] student = Student.objects.filter(canvas_id=int(student_id)).first() if student is not None: StudentCourse.user_objects.create(student=student, course=course) return super(StudentListView, self).get(request, *args, **kwargs)
def get(self, request, *args, **kwargs): course_id = None if 'course_id' in self.kwargs: course_id = int(self.kwargs['course_id']) reload = request.GET.get('reload', False) == "True" if course_id is not None: existing_records = self.model.objects.filter( course__course_id=course_id).first() if existing_records is None or reload: api = CanvasAPI() course = Course.objects.filter(course_id=course_id).first() self.model.objects.filter(course=course).all().delete() student_list = api.get_students(course_id) for student in student_list: localstudent = Student.objects.filter( canvas_id=int(student['id'])).first() if localstudent is not None: self.model.user_objects.create(student=localstudent, course=course) return super(StudentCourseListView, self).get(request, *args, **kwargs)
def get(self, request, *args, **kwargs): course_id = int(self.kwargs['course_id']) reload = request.GET.get('reload', False) == "True" existing_records = self.model.objects.filter( assignment__course__course_id=course_id).first() course = CanvasCourse.objects.filter(course_id=course_id).first() if existing_records is None or reload: api = CanvasAPI(course.term.term_id) # Delete existing data self.model.objects.filter(assignment__course=course).all().delete() Assignment.objects.filter(course=course).all().delete() UserCourse.objects.filter(course=course).all().delete() json_data = api.get_assignments(course_id) json_list = list(json_data) #the data from canvas for assignment in json_list: #get the stuff i need from the canvas data assignment_id = assignment['id'] assignment_name = assignment['name'] has_override = assignment['has_overrides'] is_quiz = assignment['is_quiz_assignment'] td = timedelta(hours=6) #adjust to local time if assignment['unlock_at'] is not None: unlockCanvas = datetime.strptime( assignment['unlock_at'], '%Y-%m-%dT%H:%M:%SZ') #save in datetime object unlockCanvas = unlockCanvas - td #adjust time. else it goes past midnight altering the date start_date = datetime.strftime( unlockCanvas, '%Y-%m-%d' ) #remove time and save just the date as a string else: start_date = None if assignment['due_at'] is not None: dueCanvas = datetime.strptime(assignment['due_at'], '%Y-%m-%dT%H:%M:%SZ') dueCanvas = dueCanvas - td due_date = datetime.strftime( dueCanvas, '%Y-%m-%d' ) #saving date as string and in m/d/y for use with datepicker else: due_date = None if assignment['lock_at'] is not None: lockCanvas = datetime.strptime(assignment['lock_at'], '%Y-%m-%dT%H:%M:%SZ') lockCanvas = lockCanvas - td end_date = datetime.strftime(lockCanvas, '%Y-%m-%d') else: end_date = None Assignment.user_objects.create(assignment_id=assignment_id, name=assignment_name, start_date=start_date, due_date=due_date, end_date=end_date, has_override=has_override, is_quiz=is_quiz, course=course) student_list = api.get_students(course_id) for student in student_list: localstudent = User.objects.filter( canvas_id=int(student['id'])).first() if localstudent is not None: usercourse = UserCourse.objects.filter( course=course).filter(user=localstudent).first() if usercourse is None: UserCourse.user_objects.create(user=localstudent, course=course) json_data = api.get_submissions(course_id) json_list = list(json_data) #the data from canvas for sub in json_list: student_id = sub['user_id'] student = User.objects.filter(canvas_id=student_id).first() assignment_id = sub['assignment_id'] assignment = Assignment.objects.filter( assignment_id=assignment_id).first() submitted = False if sub['workflow_state'] != 'unsubmitted': submitted = True late = sub['late'] self.model.user_objects.create(student=student, assignment=assignment, submitted=submitted, late=late) return super(SubmissionListView, self).get(request, *args, **kwargs)