示例#1
0
def enrollment():

    if not session.get('username'):
        return redirect(url_for('login'))

    courseID = request.form.get('courseID')
    courseTitle = request.form.get('title')
    user_id = session.get('user_id')

    if courseID:
        if Enrollment.objects(user_id=user_id, courseID=courseID):
            flash(f"You had already registered for this course {courseTitle}",
                  "warning")
            return redirect(url_for("courses"))
        else:
            Enrollment(user_id=user_id, courseID=courseID).save()
            flash(f"You have been successfully enrolled for {courseTitle}",
                  "success")

    classes = list(
        User.objects.aggregate(*[{
            '$lookup': {
                'from': 'enrollment',
                'localField': 'user_id',
                'foreignField': 'user_id',
                'as': 'r1'
            }
        }, {
            '$unwind': {
                'path': '$r1',
                'includeArrayIndex': 'r1_id',
                'preserveNullAndEmptyArrays': False
            }
        }, {
            '$lookup': {
                'from': 'course',
                'localField': 'r1.courseID',
                'foreignField': 'courseID',
                'as': 'r2'
            }
        }, {
            '$unwind': {
                'path': '$r2',
                'preserveNullAndEmptyArrays': False
            }
        }, {
            '$match': {
                'user_id': user_id
            }
        }, {
            '$sort': {
                'courseID': 1
            }
        }]))
    # term = request.form.get('term')
    return render_template("enrollment.html",
                           title="Enrollment",
                           enrollment=1,
                           classes=classes)
示例#2
0
def enrollment():
    if not session.get("username"):
        flash(f"You need to log in to view your schedule.", "warning")
        return redirect(url_for("login"))

    courseID = request.form.get("courseID")
    courseTitle = request.form.get("title")
    user_id = session.get("user_id")

    if courseID:
        if Enrollment.objects(user_id=user_id, courseID=courseID):
            flash(
                f"Oops! You are already enrolled in the course {courseTitle}!",
                "warning")
            return redirect(url_for("courses"))
        else:
            Enrollment(user_id=user_id, courseID=courseID).save()
            flash(f"You are now enrolled in {courseTitle}!", "success")

    classes = list(
        User.objects.aggregate(*[{
            '$lookup': {
                'from': 'enrollment',
                'localField': 'user_id',
                'foreignField': 'user_id',
                'as': 'result_1'
            }
        }, {
            '$unwind': {
                'path': '$result_1',
                'includeArrayIndex': 'string',
                'preserveNullAndEmptyArrays': False
            }
        }, {
            '$lookup': {
                'from': 'course',
                'localField': 'result_1.courseID',
                'foreignField': 'courseID',
                'as': 'result_2'
            }
        }, {
            '$unwind': {
                'path': '$result_2',
                'preserveNullAndEmptyArrays': False
            }
        }, {
            '$match': {
                'user_id': user_id
            }
        }, {
            '$sort': {
                'courseID': 1
            }
        }]))

    enrollment_page = render_template("enrollment.html",
                                      enrollment=True,
                                      classes=classes)
    return enrollment_page
示例#3
0
def course(courseId):

    course = Course.query.get(courseId)
    coursename = course.name
    description = course.description

    cform = CourseForm()

    # if (course) :
    #     #enrolledcourses = Enrollment.query.filter_by(and_(Enrollment.related_user==current_user ,Enrollment.state==True))

    if (request.method == 'POST'):

        if 'enroll' in request.form:
            en = Enrollment.query.filter(
                and_(Enrollment.related_course == course,
                     Enrollment.related_user == current_user)).first()
            if en is None:
                enrollment = Enrollment(course_id=course.id,
                                        user_id=current_user.id,
                                        state=True)
                db.session.add(enrollment)
                db.session.commit()
                flash('You are successfully enrolled in %s course!' %
                      coursename)
                return redirect(url_for('viewCourse', courseId=course.id))
            else:
                if en.state == False:
                    en.state = True
                    db.session.add(en)
                    db.session.commit()
                    return redirect(url_for('viewCourse', courseId=course.id))

        if 'remind' in request.form:
            en = Enrollment.query.filter(
                and_(Enrollment.related_course == course,
                     Enrollment.related_user == current_user)).first()
            if en is None:
                remind = Enrollment(course_id=course.id,
                                    user_id=current_user.id,
                                    state=False)
                db.session.add(remind)
                db.session.commit()
                flash('You have added %s course to your goals.' % coursename)
                return redirect(url_for('my_courses'))
            else:
                return redirect(url_for('my_courses'))

    return render_template('landing_page/course-details.html',
                           title='%s' % coursename,
                           course=course)
示例#4
0
def add_participant(event_id, participant_id):
    event = events_service.get_by_id(event_id)

    if event is None or len(event.participants) >= event.seats:
        return False

    participant = participants_service.get_by_id(participant_id)

    if participant is None:
        return False

    existed_enrollment = get_by_event_id_and_participant_id(
        event_id, participant_id)

    if existed_enrollment is not None:
        return False

    enrollment = Enrollment(event_id=event_id,
                            participant_id=participant_id,
                            timestamp=datetime.datetime.now())

    db.session.add(enrollment)
    db.session.commit()

    return True
示例#5
0
def create_test_enrollment(user_id, section_id):
    """ Enrolls USER_ID to SECTION_ID. """
    session = disposable_session()
    new_enrollment = Enrollment(user_id=user_id, section_id=section_id)
    session.add(new_enrollment)
    session.commit()
    session.close()
示例#6
0
def enrollment():

    # If not signed in, goto login page
    if not session.get('username'):
        return redirect(url_for('login'))
    courseID = request.form.get("courseID")
    courseTitle = request.form.get("title")
    user_id = session.get('user_id') 

    if courseID:
        if Enrollment.objects(user_id=user_id, courseID=courseID):
            flash("Oops, you are already registered in this course {}".format(courseTitle), "danger")
            return redirect(url_for("courses"))
        else:
            Enrollment(user_id=user_id, courseID=courseID).save()
            flash("You are enrolled in {}".format(courseTitle), "success")
    
    classes = course_list()
    return render_template(
        "enrollment.html", enrollment=True, title="Enrollment", classes=classes
    )
示例#7
0
 def post(self):
     json_data = request.get_json()
     if not json_data:
         raise RequestException("No input data", 400)
     try:
         data = enrollment_schema.load(json_data)
     except ValidationError as err:
         raise RequestException("Invalid input data", 400, err.messages)
     enrollment = Enrollment.create(**data)
     result = enrollment_schema.dump(enrollment)
     response = jsonify(
         {APIConst.MESSAGE: 'created new enrollment',
          APIConst.DATA: result})
     
     return response
    def test_enrollment(self):
        self.test_class()
        with self.app.app_context():
            cs0 = db.session.query(ClassSession).first()
            cs1 = db.session.query(ClassSession)[1]

            d0 = Dependent(first_name='adela', last_name='zhu')
            u0 = User(username='******',
                      email='*****@*****.**',
                      first_name='xue',
                      last_name='zheng')
            u0.dependents.append(d0)
            em0 = Enrollment(class_session=cs0,
                             enrolled_person=d0,
                             initiator=u0)

            d1 = Dependent(first_name='dudu', last_name='zhu')
            u1 = User(username='******',
                      email='*****@*****.**',
                      first_name='john',
                      last_name='lu')
            u1.dependents.append(d1)
            em1 = Enrollment(class_session=cs0,
                             enrolled_person=d1,
                             initiator=u1)
            em2 = Enrollment(class_session=cs1,
                             enrolled_person=d1,
                             initiator=u1)

            db.session.add_all([em0, em1, em2])
            db.session.commit()

            ems = Enrollment.get_enrollments(cs0.id)
            print(ems)

            ems = Enrollment.get_enrollments(enrolled_person_id=d0.id)
            print(ems)

            ems = Enrollment.get_enrollments(enrolled_person_id=d1.id)
            print(ems)

            ems = Enrollment.get_enrollments(initiator_id=u1.id)
            print(ems)

            ems = Enrollment.get_enrollments(cs1.id, d1.id)
            print(ems)
示例#9
0
 def patch(self, id):
     enrollment = self.get_resource_with_ids(Enrollment, id)
     json_data = request.get_json()
     try:
         data = enrollment_patch_schema.load(json_data, partial=True)
     except ValidationError as err:
         raise RequestException("Invalid input data", 400, err.messages)
     try:
         enrollment.update(**data)
     except Exception as err:
         raise RequestException(
             payload={APIConst.INPUT: json_data}) from err
     result = enrollment_schema.dump(Enrollment.get_with_id(
         enrollment.id))
     response = jsonify({APIConst.MESSAGE: 'updated enrollment {}'.format(
         id), APIConst.DATA: result})
     
     return response
示例#10
0
def result(coursename):
    course = Course.query.filter_by(name=coursename).first_or_404()
    form = None
    if course.assessment_file == 'rpp_test.html':
        form = RPPForm()
        result = 0
        if form.question1.data == "2":
            result += 1
        if form.question2.data == "2":
            result += 1
        if form.question3.data == "1":
            result += 1
        if form.question4.data == "1":
            result += 1
        if form.question5.data == "3":
            result += 1
        score = int(result / 5 * 100)
        new = Enrollment(course_id=course.id,
                         user_id=current_user.id,
                         score=score,
                         course_name=course.name)
        db.session.add(new)
        db.session.commit()
    return render_template('result.html', result=score)
示例#11
0
def enroll_user_in_class (user_id, turma_id):
    if Enrollment.query.filter(Enrollment.user_id==user_id).filter(Enrollment.turma_id==turma_id).first() is None:
        new_enrollment = Enrollment(user_id = user_id, turma_id = turma_id)
        db.session.add(new_enrollment)
        db.session.commit()
示例#12
0
def generate_fake():
    User.generate_fake()
    Activity.generate_fake()
    Enrollment.generate_fake()
    Comment.generate_fake()
    print("[Info]:Generate fake info Done!")
示例#13
0
def handler(request):
    try:
        career = request.POST.get('career')
        if (not career):
            raise Exception
    except:
        return ApiFailure(MALFORMED_REQUEST)

    try:
        user_id = request.session['user']['id']

        if (not user_id):
            raise Exception
    except:
        return ApiFailure(NEED_LOGIN)

    try:
        user = User.objects.get(id=user_id)
        career = Career.objects.get(id=career)

    except:
        return ApiFailure(BAD_PARAMS)

    try:
        if (user.user_type == 1):
            raise Exception
    except:
        return ApiFailure(NOT_A_STUDENT)

    try:
        e = Enrollment.objects.get(student=user, career=career)
    except:

        sprint = Sprint()
        sprint.save()

        generated_sprint = generate_sprint(career.tickets.all())
        for ticket_id in generated_sprint:
            t = Ticket.objects.get(id=ticket_id)
            tis = TicketInsideSprint(ticket=t)
            tis.save()

            sprint.tickets.add(tis)
            sprint.save()


        try:
            e = Enrollment(
                student=user,
                career=career,
            )
            e.save()

            e.sprints.add(sprint)
            e.save()

        except:
            return ApiFailure(ENROLL_FAILURE)


        return ApiSuccess()

    return ApiFailure(ALREADY_ENROLLED)