Пример #1
0
def enrollment(cid):
    courses, current_course = get_courses(cid)
    form = forms.EnrollmentForm()
    if form.validate_on_submit():
        email, role = form.email.data, form.role.data
        Enrollment.enroll_from_form(cid, form)
        flash("Added {email} as {role}".format(
            email=email, role=role), "success")

    students = (Enrollment.query.options(db.joinedload('user'))
                .filter_by(course_id=cid, role=STUDENT_ROLE)
                .order_by(Enrollment.created.desc())
                .all())

    staff = (Enrollment.query.options(db.joinedload('user'))
             .filter(Enrollment.course_id == cid, Enrollment.role.in_(STAFF_ROLES))
             .all())

    lab_assistants = (Enrollment.query.options(db.joinedload('user'))
                      .filter_by(course_id=cid, role=LAB_ASSISTANT_ROLE)
                      .order_by(Enrollment.created.desc())
                      .all())

    return render_template('staff/course/enrollment/enrollment.html',
                           enrollments=students, staff=staff,
                           lab_assistants=lab_assistants,
                           form=form,
                           unenroll_form=forms.CSRFForm(),
                           courses=courses,
                           current_course=current_course)
Пример #2
0
 def test_enroll_from_form(self):
     self.setup_course()
     
     Enrollment.enroll_from_form(self.course.id, make_enrollment_form(self.studentB))
     
     user = User.lookup(self.studentB['email'])
     self.studentB['id'] = user.id
     
     self.enrollment_matches_info(user, self.studentB)
Пример #3
0
    def test_create(self):
        self.setup_course()

        user = User(name=self.studentA['name'], email=self.studentA['email'])
        db.session.add(user)
        db.session.commit()
        self.studentA['id'] = user.id

        Enrollment.create(self.course.id, [self.studentA])

        self.enrollment_matches_info(user, self.studentA)
Пример #4
0
    def test_create(self):
        self.setup_course()

        user = User(name=self.studentA['name'], email=self.studentA['email'])
        db.session.add(user)
        db.session.commit()
        self.studentA['id'] = user.id

        Enrollment.create(self.course.id, [self.studentA])

        self.enrollment_matches_info(user, self.studentA)
Пример #5
0
    def test_enroll_from_form(self):
        self.setup_course()

        Enrollment.enroll_from_form(self.course.id, make_enrollment_form(self.studentB))

        user = User.lookup(self.studentB['email'])
        self.studentB['id'] = user.id

        self.enrollment_matches_info(user, self.studentB)

        Enrollment.enroll_from_form(self.course.id, make_enrollment_form(self.lab_assistantA))
        lab_assistant = User.lookup(self.lab_assistantA['email'])
        self.lab_assistantA['id'] = lab_assistant.id

        self.enrollment_matches_info(lab_assistant, self.lab_assistantA)
Пример #6
0
    def test_enroll_from_csv(self):
        self.setup_course()

        template = "{email},{name},{sid},{class_account},{section}"
        form = BatchEnrollmentForm()
        form.csv.data = template.format(**self.studentA) + "\n" + template.format(**self.studentB)

        Enrollment.enroll_from_csv(self.course.id, form)

        user_a = User.lookup(self.studentA['email'])
        self.studentA['id'] = user_a.id
        self.enrollment_matches_info(user_a, self.studentA)

        user_b = User.lookup(self.studentB['email'])
        self.studentB['id'] = user_b.id
        self.enrollment_matches_info(user_b, self.studentB)
Пример #7
0
 def make_student(self, n, section=None):
     user = User(email='student{0}@aol.com'.format(n))
     participant = Enrollment(user=user,
                              course=self.course,
                              section=section)
     db.session.add(participant)
     return user
Пример #8
0
def enroll_students(canvas_course_id):
    logger = jobs.get_job_logger()
    row_format = '{email!s:<35} {name!s:<35} {sid!s:<11}'
    canvas_course = CanvasCourse.query.get(canvas_course_id)
    enrollment_info = []
    logger.info(row_format.format(email='EMAIL', name='NAME', sid='SID'))
    for student in api.get_students(canvas_course):
        if not student.get("email"):
            logger.warn(
                "Student {} not enrolled, missing email address".format(
                    student))
            continue
        info = {
            'email': student['email'],
            'name': student['name'],
            'sid': student['sis_user_id'],
            'class_account': '',
            'section': '',
        }
        logger.info(row_format.format(**info))
        enrollment_info.append(info)
    created, updated = Enrollment.create(canvas_course.course_id,
                                         enrollment_info)
    message = 'Added {new}, updated {old} student enrollments'.format(
        new=created, old=updated)
    logger.info(message)
    return message
Пример #9
0
    def test_enroll_from_csv(self):
        self.setup_course()

        template = "{email},{name},{sid},{class_account},{section}"
        form = BatchEnrollmentForm()
        form.csv.data = template.format(**self.studentA) + "\n" + template.format(**self.studentB)

        Enrollment.enroll_from_csv(self.course.id, form)

        user_a = User.lookup(self.studentA['email'])
        self.studentA['id'] = user_a.id
        self.enrollment_matches_info(user_a, self.studentA)

        user_b = User.lookup(self.studentB['email'])
        self.studentB['id'] = user_b.id
        self.enrollment_matches_info(user_b, self.studentB)
Пример #10
0
    def test_unenroll(self):
        self.setup_course()

        user = User(name=self.studentA['name'], email=self.studentA['email'])
        db.session.add(user)
        db.session.commit()
        self.studentA['id'] = user.id

        Enrollment.create(self.course.id, [self.studentA])
        enrollment = Enrollment.query.filter_by(course_id=self.course.id,
                                                user_id=user.id).one_or_none()
        assert enrollment is not None

        Enrollment.unenroll(enrollment)
        enrollment = Enrollment.query.filter_by(course_id=self.course.id,
                                                user_id=user.id).one_or_none()
        assert enrollment is None
Пример #11
0
 def make_staff(self, n, role=constants.STAFF_ROLE, section=None):
     user = User(email='staff{0}@bitdiddle.net'.format(n))
     participant = Enrollment(user=user,
                              course=self.course,
                              role=role,
                              section=section)
     db.session.add(participant)
     return user
Пример #12
0
    def test_enroll_twice(self):
        self.setup_course()

        form = make_enrollment_form(self.studentB)
        Enrollment.enroll_from_form(self.course.id, form)

        user = User.lookup(self.studentB['email'])
        self.studentB['id'] = user.id

        self.enrollment_matches_info(user, self.studentB)

        form = make_enrollment_form(self.studentB_alt)
        Enrollment.enroll_from_form(self.course.id, form)

        user_updated = User.lookup(self.studentB['email'])
        self.studentB_alt['id'] = user_updated.id
        assert user.id == user_updated.id

        self.enrollment_matches_info(user, self.studentB_alt)
Пример #13
0
    def test_enroll_twice(self):
        self.setup_course()

        form = make_enrollment_form(self.studentB)
        Enrollment.enroll_from_form(self.course.id, form)

        user = User.lookup(self.studentB['email'])
        self.studentB['id'] = user.id

        self.enrollment_matches_info(user, self.studentB)

        form = make_enrollment_form(self.studentB_alt)
        Enrollment.enroll_from_form(self.course.id, form)

        user_updated = User.lookup(self.studentB['email'])
        self.studentB_alt['id'] = user_updated.id
        assert user.id == user_updated.id

        self.enrollment_matches_info(user, self.studentB_alt)
Пример #14
0
    def test_unenroll(self):
        self.setup_course()

        user = User(name=self.studentA['name'], email=self.studentA['email'])
        db.session.add(user)
        db.session.commit()
        self.studentA['id'] = user.id

        Enrollment.create(self.course.id, [self.studentA])
        enrollment = Enrollment.query.filter_by(
            course_id=self.course.id,
            user_id=user.id).one_or_none()
        assert enrollment is not None

        Enrollment.unenroll(enrollment)
        enrollment = Enrollment.query.filter_by(
            course_id=self.course.id,
            user_id=user.id).one_or_none()
        assert enrollment is None
Пример #15
0
def batch_enroll(cid):
    courses, current_course = get_courses(cid)
    batch_form = forms.BatchEnrollmentForm()
    if batch_form.validate_on_submit():
        new, updated = Enrollment.enroll_from_csv(cid, batch_form)
        msg = ("Added {new}, Updated {old} {role} enrollments"
               .format(new=new, role=batch_form.role.data, old=updated))
        flash(msg, "success")
        return redirect(url_for(".enrollment", cid=cid))

    return render_template('staff/course/enrollment/enrollment.batch.html',
                           batch_form=batch_form,
                           courses=courses,
                           current_course=current_course)
Пример #16
0
def batch_enroll(cid):
    courses, current_course = get_courses(cid)
    batch_form = forms.BatchEnrollmentForm()
    if batch_form.validate_on_submit():
        new, updated = Enrollment.enroll_from_csv(cid, batch_form)
        msg = ("Added {new}, Updated {old} {role} enrollments"
               .format(new=new, role=batch_form.role.data, old=updated))
        flash(msg, "success")
        return redirect(url_for(".enrollment", cid=cid))

    return render_template('staff/course/enrollment.batch.html',
                           batch_form=batch_form,
                           courses=courses,
                           current_course=current_course)
Пример #17
0
def enrollment(cid):
    courses, current_course = get_courses(cid)
    single_form = forms.EnrollmentForm(prefix="single")
    if single_form.validate_on_submit():
        email, role = single_form.email.data, single_form.role.data
        Enrollment.enroll_from_form(cid, single_form)
        flash("Added {email} as {role}".format(
            email=email, role=role), "success")

    students = (Enrollment.query.options(db.joinedload('user'))
                .filter_by(course_id=cid, role=STUDENT_ROLE)
                .order_by(Enrollment.created.desc())
                .all())

    staff = (Enrollment.query.options(db.joinedload('user'))
             .filter(Enrollment.course_id == cid, Enrollment.role.in_(STAFF_ROLES))
             .all())

    return render_template('staff/course/enrollment.html',
                           enrollments=students, staff=staff,
                           single_form=single_form,
                           courses=courses,
                           current_course=current_course)
Пример #18
0
def create_course():
    courses, current_course = get_courses()
    form = forms.NewCourseForm()
    if form.validate_on_submit():
        new_course = Course()
        form.populate_obj(new_course)

        # Add user as instructor, can be changed later
        enroll = Enrollment(course=new_course, user_id=current_user.id,
                            role=INSTRUCTOR_ROLE)
        db.session.add(new_course)
        db.session.add(enroll)

        db.session.commit()

        flash(new_course.offering + " created successfully.", "success")
        return redirect(url_for(".course", cid=new_course.id))
    return render_template('staff/course/course.new.html', form=form,
                           courses=courses)
Пример #19
0
def gen_enrollment(user, course):
    role = weighted_choice([
        ('student', 100),
        ('grader', 2),
        ('staff', 20),
        ('lab assistant', 20),
        ('instructor', 2),
    ])
    sid = ''.join(random.choice(string.digits) for _ in range(8))
    class_account = '{0}-{1}'.format(
        course.offering.split('/')[1],
        ''.join(random.choice(string.ascii_lowercase) for _ in range(3)))
    section = random.randrange(5)
    return Enrollment(user_id=user.id,
                      course_id=course.id,
                      role=role,
                      sid=gen_maybe(sid, 0.4),
                      class_account=gen_maybe(class_account, 0.4),
                      section=section)
Пример #20
0
def enroll_students(canvas_course_id):
    logger = jobs.get_job_logger()
    row_format = '{email!s:<35} {name!s:<35} {sid!s:<11}'
    canvas_course = CanvasCourse.query.get(canvas_course_id)
    enrollment_info = []
    logger.info(row_format.format(email='EMAIL', name='NAME', sid='SID'))
    for student in api.get_students(canvas_course):
        info = {
            'email': student['email'],
            'name': student['name'],
            'sid': student['sis_user_id'],
            'class_account': '',
            'section': '',
        }
        logger.info(row_format.format(**info))
        enrollment_info.append(info)
    created, updated = Enrollment.create(canvas_course.course_id, enrollment_info)
    message = 'Added {new}, updated {old} student enrollments'.format(
        new=created, old=updated)
    logger.info(message)
    return message
Пример #21
0
 def make_lab_assistant(self, n, role=constants.LAB_ASSISTANT_ROLE):
     user = User(email='lab_assistant{0}@labassist.net'.format(n))
     participant = Enrollment(user=user, course=self.course, role=role)
     db.session.add(participant)
     return user