Example #1
0
def editcourse(course_id):
    if current_user.tof == 1:
        return redirect(url_for('index'))
    else:
        form = CourseForm()
        course = Course.query.filter_by(id=course_id).first()
        if form.validate_on_submit():
            course.subject = form.subject.data
            course.number = form.number.data
            course.title = form.title.data
            course.gpareq = form.gpareq.data
            course.prevgrade = form.prevgrade.data
            course.numslots = form.numslots.data
            course.addinfo = form.addinfo.data
            db.session.commit()
            flash("You have updated your course!")
            return redirect(url_for('managecourses'))
        elif request.method == 'GET':
            form.subject.data = course.subject
            form.number.data = course.number
            form.title.data = course.title
            form.gpareq.data = course.gpareq
            form.prevgrade.data = course.prevgrade
            form.numslots.data = course.numslots
            form.addinfo.data = course.addinfo
        return render_template('editcourse.html',
                               title='Edit Course',
                               form=form,
                               course=course)
Example #2
0
def editCourse(courseId):
    form = CourseForm()
    course = db.session.query(Course).filter_by(id=courseId).first_or_404()
    if form.validate_on_submit():
        course.name = form.name.data
        course.description = form.description.data
        formElToAppendLessons(form.lessonsIncluded, course)
        if request.files['imgFile']:
            if stopFileUpload(request, 'Image'):
                return render_template(url_for('editCourse'), courseId=courseId, title='Edit Course', form=form)
            course.imgFileLoc = changeFileReturnFileName(request, 'Image', course.imgFileLoc)
        db.session.commit()
        flash('Your changes were saved')
        return redirect(url_for('editCourse', courseId=courseId))
    elif request.method == 'GET':
        lessonGroups = findLessonsGroups(course)
        lessonIDsInCourse = set([lesson.id for lesson in lessonGroups['lessonsInCourse']])
        form.name.data = course.name
        form.description.data = course.description
        form.lessonsIncluded.data = ''.join(str(lessonID) + ',' for lessonID in lessonIDsInCourse ) 
    return render_template('editCourse.html', title='Edit Course', course=course, form=form,
        lessonsInCourse=lessonGroups['lessonsInCourse'], 
        lessonsUserCreated=lessonGroups['lessonsUserCreated'], 
        lessonsOthersCreated=lessonGroups['lessonsOthersCreated'], 
        lessonIDsInCourse=lessonIDsInCourse)
Example #3
0
def saveEditCourse(course_id, teacher_id):
    """process course edit form"""
    form = CourseForm(request.form)
    course = {}
    if request.method == 'POST' and form.validate():
        course['title'] = request.form['title']
        course['section'] = request.form['section']
        course['department'] = request.form['department']
        course['description'] = request.form['description']
        course['units'] = request.form['units']

        db_conn = db_pool.getconn()
        cursor = db_conn.cursor()
        cursor.execute(
            f"UPDATE course SET title = %s, section = %s, department = %s, "
            f"description = %s, units = %s WHERE course_id = %s;",
            (course['title'],
             course['section'],
                course["department"],
                course["description"],
                course["units"],
                course_id))
        db_conn.commit()
        cursor.close()
        db_pool.putconn(db_conn)

    return redirect(url_for('renderTeachers', teacher_id=teacher_id))
Example #4
0
def update():
    form = CourseForm()
    if form.validate_on_submit():
        q.enqueue(main_function, form.class_name.data, current_user.email,
                  form.url.data, int(form.seats.data))
        flash('Congratulations course has been tracked!')
        return redirect(url_for('index'))
    return render_template('update.html', title='update', form=form)
Example #5
0
def addcourse():
    form = CourseForm()
    form.ic_id.choices = [(str(i[0]), i[1]) for i in Faculty.get_all_faculty()]
    if form.validate_on_submit():
        Course.create_course(form.course_id.data, form.course_name.data,
                             int(form.ic_id.data))
        flash('The course has been added successfully')
        return redirect(url_for('index'))
    return render_template('courseForm.html', title='Add Course', form=form)
def add_course():
    form = CourseForm()
    course = Course()
    if request.method == 'POST' and form.validate_on_submit():
        course.course_title = form.course_title.data
        course.course_name = form.course_name.data
        course.add_course()
        flash(f'Successfully Added course of title "{form.course_title.data}"',
              category='success')
        return redirect(url_for('courses'))
    else:
        return render_template('add_course.html', form=form)
Example #7
0
def create_course():
    form = CourseForm()
    if form.validate_on_submit():
        course = Courses(title=form.title.data,
                         startdate=form.startdate.data,
                         enddate=form.enddate.data,
                         semester=form.semester.data,
                         professor_id=current_user._get_current_object().id)
        db.session.add(course)
        db.session.commit()
        flash("Your course is created!")
        return redirect(url_for('show_courses'))
    return render_template('create_course.html', form=form)
Example #8
0
def addCourse(teacher_id):
    """display add course form"""
    addCourseForm = CourseForm()
    return render_template(
        'addcourse.html',
        addCourseForm=addCourseForm,
        teacher_id=teacher_id)
Example #9
0
def addcourse():
    form = CourseForm()
    if form.validate_on_submit():
        course = Course(subject=form.subject.data,
                        number=form.number.data,
                        title=form.title.data,
                        gpareq=form.gpareq.data,
                        prevgrade=form.prevgrade.data,
                        numslots=form.numslots.data,
                        addinfo=form.addinfo.data,
                        professor=current_user)
        db.session.add(course)
        db.session.commit()
        flash("You have created a new course!")
        return redirect(url_for('Facindex'))
    return render_template('addcourse.html', title='Create Course', form=form)
Example #10
0
 def post(self,request):
     data=request.body
     dict_data = json.loads(data)
     print(dict_data)
     CourseForm()
     #CourseModel(name=dict_data['name'],fee=dict_data['fee']).save()
     json_response=json.dumps({"message":"data saved sucessfully"})
     return HttpResponse(json_response, content_type="application/json")
Example #11
0
def createCourse():
    form = CourseForm()
    lessonGroups = findLessonsGroups(course=None)   
    if form.validate_on_submit():
        user = current_user
        if stopFileUpload(request, 'Image'):
            return render_template('createCourse.html', title='Create Course', form=form)
        imgFilename = saveFileReturnFileName(request, 'Image')
        course = Course(name=form.name.data, description=form.description.data, 
                        imgFileLoc=imgFilename, createdBy=user.id )
        formElToAppendLessons(form.lessonsIncluded, course)
        db.session.add(course)
        db.session.commit()
        flash('Course created successfully.')
        return redirect(url_for('admin', username=current_user.username))
    return render_template('createCourse.html', title='Create Course', form=form,
        lessonsInCourse=lessonGroups['lessonsInCourse'], 
        lessonsUserCreated=lessonGroups['lessonsUserCreated'], 
        lessonsOthersCreated=lessonGroups['lessonsOthersCreated'])
Example #12
0
def edit_course(course_id=None):
    if course_id:
        course = Course.query.get(course_id)
    else:
        course = Course()
    if not course:
        abort(404)
    latest_term = course.latest_term
    if not latest_term:
        abort(404)
    course_form = CourseForm(formdata=request.form, obj=course)
    if course_form.validate_on_submit():
        course_form.introduction.data = sanitize(course_form.introduction.data)
        course_form.populate_obj(latest_term)
        if not latest_term.homepage.startswith('http'):
            latest_term.homepage = 'http://' + course.homepage
        latest_term.save()
        db.session.commit()
        return redirect(url_for('course.view_course', course_id=course.id))
    return render_template('course-edit.html', form=course_form, course=course)
Example #13
0
def index():
    form = CourseForm()
    update_course = User.query.filter_by(id=current_user.id).first()
    update_course.student_courses = form.student_courses.data
    flash('Looking for students with the same course')
    found_buddy = User.query.filter_by(
        student_courses=update_course.student_courses)
    return render_template('index.html',
                           title='User_Home',
                           form=form,
                           found_buddy=found_buddy)
Example #14
0
def add_course():
    r = request.args.get('redir')
    if r in REDIR_PAGES:
        session['origin'] = url_for(REDIR_PAGES[r])
    elif r == 'edit' and 'examination_edit_id' in session:
        session['origin'] = '/examination/edit/{}'.format(
            session['examination_edit_id'])

    if not ModuleAPI.can_write('examination', True):
        session['prev'] = 'examination.add_course'
        return abort(403)

    form = CourseForm(request.form)

    if request.method == 'POST':
        if form.validate_on_submit():
            title = form.title.data
            course = Course.query.filter(Course.name == title).first()
            if not course:
                description = form.description.data
                new_course = Course(title, description)
                db.session.add(new_course)
                db.session.commit()
                flash("'%s': " % title + _('Course succesfully added.'),
                      'success')
            else:
                flash("'%s': " % title + _('Already exists in the database'),
                      'danger')

                return render_template('course/edit.htm', new=True, form=form)

            if 'origin' in session:
                redir = session['origin']
            else:
                redir = url_for('examination.add')
            return redirect(redir)
        else:
            flash_form_errors(form)

    return render_template('course/edit.htm', new=True, form=form)
Example #15
0
def edit_course(course_id=None):
    if not current_user.is_admin:
        abort(403)
    if course_id:
        course = Course.query.get(course_id)
    else:
        course = Course()
    if not course:
        abort(404)
    latest_term = course.latest_term
    if not latest_term:
        abort(404)
    course_form = CourseForm(request.form, course)
    if course_form.validate_on_submit():
        course_form.introduction.data = sanitize(course_form.introduction.data)
        course_form.populate_obj(latest_term)
        if not latest_term.homepage.startswith("http"):
            latest_term.homepage = "http://" + course.homepage
        latest_term.save()
        db.session.commit()
        return redirect(url_for("course.view_course", course_id=course.id))
    return render_template("course-edit.html", form=course_form, course=course)
Example #16
0
def createcourse(request):
    if request.method == "GET":
        form = CourseForm()
        return render(request, 'createCourses.html', {'form': form})
    if request.method == "POST":
        form = CourseForm(request.POST)
        form.save()
        return HttpResponseRedirect('/courses')
Example #17
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)
Example #18
0
def editCourse(course_id):
    """display edit course form"""
    db_conn = db_pool.getconn()
    dict_cur = db_conn.cursor(cursor_factory=extras.DictCursor)
    dict_cur.execute(f'SELECT * FROM course '
                     f'WHERE course_id = {course_id}')
    course = dict_cur.fetchone()
    dict_cur.close()
    db_pool.putconn(db_conn)
    editCourseForm = CourseForm()

    return render_template(
        'editcourse.html',
        editCourseForm=editCourseForm,
        course=course)
Example #19
0
def index():
    form = CourseForm()

    grades = [10, 20, 30, 5]

    if request.method == 'POST':
        department = request.form['DepartmentInput']
        course_subject = str(request.form['CourseSubjectInput']).upper()
        catalog_number = request.form['CatalogNumberInput']

        gd_urls = link(department, course_subject, catalog_number)
        class_name = make_course_name(department, course_subject,
                                      catalog_number)
        gd_dataframe = table_data(gd_urls, class_name)

        avg_gpa = round(gd_dataframe['CLS GPA'].mean(), 2)

        flash("Avg Grade Distribution: {}, {}, {}, {}".format(
            round(gd_dataframe['A%'].mean(), 2),
            round(gd_dataframe['B%'].mean(), 2),
            round(gd_dataframe['C%'].mean(), 2),
            round(gd_dataframe['D%'].mean(), 2)))
        flash("Avg Class GPA: {}".format(avg_gpa))

        grades = [
            round(gd_dataframe['A%'].mean(), 2),
            round(gd_dataframe['B%'].mean(), 2),
            round(gd_dataframe['C%'].mean(), 2),
            round(gd_dataframe['D%'].mean(), 2)
        ]

        course = "{}-{} {}".format(department, course_subject, catalog_number)

        list_of_teachers = gd_dataframe['Instructor'].unique()
        teacher_ratings = []
        for teacher in list_of_teachers:
            teacher_rating = find_teachergrade(teacher)
            teacher_ratings.append(teacher_rating)

        return render_template('index.html',
                               form=form,
                               grades=grades,
                               course=course,
                               teachers=teacher_ratings)

    return render_template('index.html', form=form, grades=grades)
Example #20
0
def edit_course(course_id):
    r = request.args.get('redir')
    if r in REDIR_PAGES:
        session['origin'] = url_for(REDIR_PAGES[r])
    elif r == 'edit' and 'examination_edit_id' in session:
        session['origin'] = '/examination/edit/{}'.format(
            session['examination_edit_id'])

    if not ModuleAPI.can_write('examination', True):
        session['prev'] = 'examination.edit_course'
        return abort(403)

    course = Course.query.get(course_id)

    if not course:
        flash(_('Course could not be found.'), 'danger')
        return redirect(url_for('examination.view_courses'))

    exam_count = Examination.query.filter(Examination.course == course).count()
    if 'delete' in request.args:
        if exam_count > 0:
            flash(_('Course still has examinations in the database.'),
                  'danger')
            form = CourseForm(title=course.name,
                              description=course.description)
            return render_template('course/edit.htm', new=False,
                                   form=form,
                                   course=course, redir=r,
                                   exam_count=exam_count)

        Course.query.filter_by(id=course_id).delete()
        db.session.commit()

        flash(_('Course succesfully deleted.'), 'success')
        if 'origin' in session:
            redir = session['origin']
        else:
            redir = url_for('examination.add')
        return redirect(redir)

    if request.method == 'POST':
        form = CourseForm(request.form)
        if form.validate_on_submit():
            title = form.title.data
            if title != course.name and Course.query.filter(
                    Course.name == title).count() >= 1:
                flash("'%s': " % title + _('Already exists in the database'),
                      'danger')
                return render_template('course/edit.htm', new=False,
                                       form=form, redir=r,
                                       course=course,
                                       exam_count=exam_count)
            else:
                description = form.description.data
                course.name = title
                course.description = description

                db.session.commit()
                flash(_('Course succesfully saved.'),
                      'success')

                if 'origin' in session:
                    redir = session['origin']
                else:
                    redir = url_for('examination.add')
                return redirect(redir)
        else:
            flash_form_errors(form)
    else:
        form = CourseForm(title=course.name, description=course.description)

    return render_template('course/edit.htm', new=False,
                           form=form, redir=r, course=course,
                           exam_count=exam_count)
Example #21
0
def edit_education(education_id):
    r = request.args.get('redir')
    if r in REDIR_PAGES:
        session['origin'] = url_for(REDIR_PAGES[r])
    elif r == 'edit' and 'examination_edit_id' in session:
        session['origin'] = '/examination/edit/{}'.format(
            session['examination_edit_id'])

    if not ModuleAPI.can_write('examination', True):
        session['prev'] = 'examination.edit_education'
        return abort(403)

    education = Education.query.get(education_id)

    if not education:
        flash(_('Education could not be found.'), 'danger')
        return redirect(url_for('examination.view_educations'))

    exam_count = Examination.query.filter(
        Examination.education == education).count()

    if 'delete' in request.args:
        if exam_count > 0:
            flash(_('Education still has examinations in the database.'),
                  'danger')
            form = CourseForm(title=education.name)
            return render_template('education/edit.htm', new=False,
                                   form=form, education=education,
                                   redir=r, exam_count=exam_count)

        Education.query.filter_by(id=education_id).delete()
        db.session.commit()

        flash(_('Education succesfully deleted.'), 'success')
        if 'origin' in session:
            redir = session['origin']
        else:
            redir = url_for('examination.add')
        return redirect(redir)

    if request.method == 'POST':
        form = EducationForm(request.form)
        if form.validate_on_submit():
            name = form.title.data
            if name != education.name and Education.query.filter(
                    Education.name == name).count() >= 1:
                flash("'%s': " % name + _('Already exists in the database'),
                      'danger')
                return render_template('education/edit.htm', new=False,
                                       form=form, redir=r,
                                       exam_count=exam_count,
                                       education=education)
            else:
                education.name = name

                db.session.commit()
                flash("'%s': " % name + _('Education succesfully saved.'),
                      'success')

                if 'origin' in session:
                    redir = session['origin']
                else:
                    redir = url_for('examination.view_educations')
                return redirect(redir)

        else:
            flash_form_errors(form)
    else:
        form = CourseForm(title=education.name)

    return render_template('education/edit.htm', new=False,
                           form=form, redir=r, exam_count=exam_count,
                           education=education)