Example #1
0
    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)
Example #2
0
    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)
Example #3
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("../../")
Example #4
0
    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)
Example #5
0
    def formset_valid(self, formset):
        course_id = self.kwargs['course_id']
        course = CanvasCourse.objects.filter(course_id=course_id).first()
        capi = CanvasAPI(term=course.term.term_id)
        creds = UserCredentials()

        cleaned_data = formset.clean()

        for form in formset:
            if form.has_changed():
                form.save()

                assignment_id = form.cleaned_data['id'].assignment_id
                has_override = form.cleaned_data['id'].has_override

                # Fixed time to add to dates
                starttime = time(0, 0, 0)
                endtime = time(23, 59, 00)

                # Get dates from DB
                start_date = form.cleaned_data['start_date']
                due_date = form.cleaned_data['due_date']
                end_date = form.cleaned_data['end_date']

                # Combine date with fixed time and convert to isoformat
                start_date_time = datetime.combine(start_date,
                                                   starttime).isoformat()
                due_date_time = datetime.combine(due_date, endtime).isoformat()
                end_date_time = datetime.combine(end_date, endtime).isoformat()

                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']

                    if has_override:
                        capi.update_assignment_override(
                            course_id, self.assignment_id, self.student_id,
                            due_date_time, start_date_time, end_date_time)
                        self.success_message = "Assignment override updated!"
                    else:
                        capi.create_assignment_override(
                            course_id, self.assignment_id, self.student_id,
                            due_date_time, start_date_time, end_date_time)
                        self.success_message = "Assignment override created!"

                else:
                    if has_override:
                        capi.delete_assignment_overrides(
                            course_id, assignment_id)

                    capi.update_assignment_dates(course_id, assignment_id,
                                                 due_date_time,
                                                 start_date_time,
                                                 end_date_time)

        return super(EditDueDates, self).formset_valid(formset)
Example #6
0
class AnnouncementCreateView(CurrentUserMixin, CCECreateView):
    model = Announcement
    form_class = AnnouncementForm
    page_title = "Add Announcement!"
    sidebar_group = [
        'dashboard',
    ]
    success_message = "Announcement Created Successfully"
    creds = UserCredentials()

    def get_success_url(self):
        return reverse('dashboard')
Example #7
0
    def get_context_data(self, *args, **kwargs):
        course_id = int(self.kwargs['course_id'])
        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']
        data = super(EditDueDates, self).get_context_data(**kwargs)

        course = CanvasCourse.objects.filter(course_id=course_id).first()
        api = CanvasAPI(term=course.term.term_id)
        creds = UserCredentials()

        if (hasattr(self, 'assignment_id') and hasattr(self, 'student_id')):
            data['assignment_id'] = self.assignment_id
            data['assignment_name'] = Assignment.objects.filter(
                assignment_id=self.assignment_id).first()
            if not data['assignment_name']:
                data['assignment_name'] = api.get_assignment(
                    course_id, self.assignment_id)['name']
            data['student_id'] = self.student_id
            data['student_name'] = User.objects.filter(
                canvas_id=self.student_id).first()
            if not data['student_name']:
                data['student_name'] = api.get_user(self.student_id)['name']
            data['is_override_create'] = True
        data['course_id'] = course_id
        data['course_name'] = CanvasCourse.objects.filter(
            course_id=course_id).first()
        if not data['course_name']:
            data['course_name'] = api.get_courses(course_id)['name']

        has_override_dict = {}
        is_quiz_dict = {}
        has_override = False

        for object in data['object_list']:
            if object.is_quiz:
                is_quiz_dict[object.id] = True
            else:
                is_quiz_dict[object.id] = True
        for object in data['object_list']:
            if object.has_override:
                has_override_dict[object.id] = True
                has_override = True
            else:
                has_override_dict[object.id] = True

        data['has_override_dict'] = has_override_dict
        data['is_quiz_dict'] = is_quiz_dict
        data['has_override'] = has_override

        return data
Example #8
0
 def reload_course(self, request, term_id):
     term = Term.objects.filter(term_id = term_id).first()        
     self.model.objects.filter(term = term).delete()
     creds = UserCredentials()
     api = CanvasAPI(term = term_id)
     
     course_list = api.get_courses_by_term()
     for course in course_list:
         subaccount = Subaccount.objects.filter(subaccount_id = course['account_id']).first()
         self.model.objects.filter(course_id = course['id']).delete()
         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()
         
     self.message_user(request, "Course list successfully reloaded!")
     return HttpResponseRedirect("../../")
Example #9
0
 def reload_user(self, request):
     #self.model.objects.all().delete()
     Submission.objects.all().delete()
     creds = UserCredentials()
     api = CanvasAPI()
     
     user_list = api.get_account_users()
     for user in user_list:
         userRecord = self.model.objects.filter(canvas_id = user['id']).first()
         if userRecord is None:
             user_create = self.model.objects.create(canvas_id = user['id'], name = user['name'], sortable_name = user['sortable_name'], short_name = user['short_name'], sis_user_id = user['sis_user_id'], login_id = user['login_id']) 
             user_create.save()
         
     self.message_user(request, "Canvas User list successfully reloaded!")
     return HttpResponseRedirect("../")
Example #10
0
    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
Example #11
0
 def reload_subaccounts(self, request):
     self.model.objects.all().delete()
     creds = UserCredentials()
     api = CanvasAPI()
     
     first_iteration = api.get_subaccounts()
     for sub_account in first_iteration:
         sub_account_create = self.model.objects.create(subaccount_id = sub_account['id'], name = sub_account['name'])
         sub_account_create.save()
 
     second_iteration = api.get_subaccounts()
     for sub_account in second_iteration:
         sub_account_parent = self.model.objects.filter(subaccount_id = sub_account['parent_account_id']).first()
         sub_account_child = self.model.objects.filter(subaccount_id = sub_account['id']).first()
         sub_account_child.parent = sub_account_parent
         sub_account_child.save()
         
     self.message_user(request, "Subaccounts successfully reloaded!")
     return HttpResponseRedirect("../")
Example #12
0
    def reload_student(self, request):
        self.model.objects.all().delete()
        Submission.objects.all().delete()
        creds = UserCredentials()
        api = CanvasAPI()

        student_list = api.get_account_users()
        for student in student_list:
            student_create = self.model.objects.create(
                canvas_id=student['id'],
                name=student['name'],
                sortable_name=student['sortable_name'],
                short_name=student['short_name'],
                sis_user_id=student['sis_user_id'],
                login_id=student['login_id'])
            student_create.save()

        self.message_user(request, "Student list successfully reloaded!")
        return HttpResponseRedirect("../")
Example #13
0
 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)
Example #14
0
 def get_queryset(self):
     creds = UserCredentials()
     return super(
         UserManager,
         self).get_queryset().filter(created_by=creds.get_OUNetID())
Example #15
0
    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)
Example #16
0
 def can_delete(self, user_obj):
     creds = UserCredentials()
     return self.created_by == creds.get_OUNetID() or creds.is_admin()
Example #17
0
class PACSModel(models.Model):
    """
    Abstract model with fields for the user and timestamp of a row's creation
    and last update.
    .. note:: - 
    """
    creds = UserCredentials()

    last_updated_by = models.CharField(max_length=8,
                                       default=creds.get_OUNetID(),
                                       blank=True,
                                       null=True)
    last_updated_at = models.DateTimeField(auto_now=True)
    created_by = models.CharField(max_length=8,
                                  default=creds.get_OUNetID(),
                                  blank=True,
                                  null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    objects = models.Manager()
    user_objects = UserManager()

    class Meta:
        abstract = True

    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)

    @property
    def tz_last_updated_at(self):
        from django.utils.timezone import localtime
        return localtime(self.last_updated_at)

    @property
    def tz_created_at(self):
        from django.utils.timezone import localtime
        return localtime(self.created_at)

    def __unicode__(self):
        return u'%s' % self.name

    def is_owner(self, user_obj):
        creds = UserCredentials()
        return self.created_by == creds.get_OUNetID()

    def can_update(self, user_obj):
        return True

    def can_delete(self, user_obj):
        creds = UserCredentials()
        return self.created_by == creds.get_OUNetID() or creds.is_admin()

    def can_create(self, user_obj):
        return True

    def can_view_list(self, user_obj):
        return True

    def can_view(self, user_obj):
        return True
Example #18
0
 def save(self, *args, **kwargs):
     creds = UserCredentials()
     self.author = creds.get_FirstName() + " " + creds.get_LastName()
     self.short_school = self.fillshort()
     return super(Announcement, self).save(*args, **kwargs)
Example #19
0
 def wrap(request, *args, **kwargs):
     creds = UserCredentials()
     if creds.is_member(groups) or creds.is_admin():
         return function(request, *args, **kwargs)
     else:
         raise PermissionDenied
Example #20
0
 def is_owner(self, user_obj):
     creds = UserCredentials()
     return self.created_by == creds.get_OUNetID()