def get(self, request, *args, **kwargs): creds = UserCredentials() api = CanvasAPI() activeTerms = ActiveTerm.objects.order_by('-active_term') for activeTerm in activeTerms: term = activeTerm.active_term canvasID = api.get_canvasID(creds.get_OUNetID()) api_response = api.get_class_by_teacher(canvasID, term.term_id) api_list = list(api_response) for course in api_list: course_id = int(course['id']) course_found = self.model.objects.filter( course_id=course_id).first() if course_found is None: subaccount = Subaccount.objects.filter( subaccount_id=course['account_id']).first() course_create = self.model.objects.create( course_id=course_id, name=course['name'], course_code=course['course_code'], term=term, subaccount=subaccount) course_create.save() return super(CourseListView, self).get(request, *args, **kwargs)
def get_queryset(self): creds = UserCredentials() api = CanvasAPI() canvasID = api.get_canvasID(creds.get_OUNetID()) api_response = api.get_class_by_teacher(canvasID) api_list = list(api_response) course_ids = [] for course in api_list: course_ids.append(int(course['id'])) return self.model.objects.filter(course_id__in=course_ids)
def get_context_data(self, **kwargs): auth = UserCredentials() context = {} context = super(CurrentUserMixin, self).get_context_data(**kwargs) context['user_full_name'] = auth.get_FirstName( ) + " " + auth.get_LastName() context['user_ounetid'] = auth.get_OUNetID() context['user_email'] = auth.get_Email() for membership in auth.MemberOf: context['user_is_' + str(membership.lower())] = True context['user_is_admin'] = auth.is_admin() context['user_groups'] = auth.MemberOf context['server_type'] = settings.SERVER_TYPE return context
def get_queryset(self): creds = UserCredentials() api = CanvasAPI() activeTerms = ActiveTerm.objects.order_by('-active_term') canvasID = api.get_canvasID(creds.get_OUNetID()) course_ids = [] for activeTerm in activeTerms: term = activeTerm.active_term api_response = api.get_class_by_teacher(canvasID, term.term_id) api_list = list(api_response) for course in api_list: course_ids.append(int(course['id'])) return self.model.objects.filter(course_id__in=course_ids)
def get(self, request, *args, **kwargs): creds = UserCredentials() course_id = int(self.kwargs['course_id']) course = CanvasCourse.objects.filter(course_id=course_id).first() api = CanvasAPI(term=course.term.term_id) logging.warning("Term Set as : " + str(course.term.term_id)) api.is_teacher_of_course(course_id, creds.get_OUNetID()) if not api.is_teacher_of_course(course_id, creds.get_OUNetID()): raise PermissionDenied if ('assignment_id' in self.kwargs and 'student_id' in self.kwargs): self.assignment_id = self.kwargs['assignment_id'] self.student_id = self.kwargs['student_id'] self.page_title = "Extend Due Dates" json_data = api.get_assignment(course_id, self.assignment_id) override = api.get_assignment_override(course_id, self.assignment_id, self.student_id) if override: if 'due_at' in override: json_data['due_at'] = override['due_at'] else: json_data['due_at'] = None if 'unlock_at' in override: json_data['unlock_at'] = override['unlock_at'] else: json_data['unlock_at'] = None if 'lock_at' in override: json_data['lock_at'] = override['lock_at'] else: json_data['lock_at'] = None json_data['has_overrides'] = True else: json_data['has_overrides'] = False json_list = [json_data] #the data from canvas else: 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'] is_quiz = assignment['is_quiz_assignment'] has_override = assignment['has_overrides'] 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_record = self.model.objects.filter( assignment_id=assignment_id) if assignment_record is None or not assignment_record: self.model.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) else: assignment_record.update(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) return super(EditDueDates, self).get(request, *args, **kwargs)
def can_delete(self, user_obj): creds = UserCredentials() return self.created_by == creds.get_OUNetID() or creds.is_admin()
def is_owner(self, user_obj): creds = UserCredentials() return self.created_by == creds.get_OUNetID()
def save(self, *args, **kwargs): creds = UserCredentials() self.last_updated_by = creds.get_OUNetID() if self.created_by is None: self.created_by = creds.get_OUNetID() return super(PACSModel, self).save(*args, **kwargs)
def get_queryset(self): creds = UserCredentials() return super( UserManager, self).get_queryset().filter(created_by=creds.get_OUNetID())