Пример #1
0
def edit(department_code, course_number):
    try:
        course = Course.select().join(Department).where(
            Department.code == department_code,
            Course.number == course_number).get()
    except model.DoesNotExist:
        abort(404)

    form = CourseForm(obj=course)
    form.department.choices = [(d.id, d.name) for d in Department.select()]
    if form.validate_on_submit():
        form.populate_obj(course)
        course.save()

        return redirect(course.absolute_url())

    return render_template('course/form.html', title="Edit course", form=form)
Пример #2
0
def create():
    form = CourseForm()

    # WTForms doesn't handle relationships between objects well
    # their documentation suggests this for populating the deparment select list
    # FIXME: move this to a constructor (?) on the CourseForm object
    form.department.choices = [(d.id, d.name) for d in Department.select()]

    if form.validate_on_submit():
        course = Course()
        form.populate_obj(course)
        course.save()

        return redirect(course.absolute_url())

    return render_template('course/form.html',
                           title="Add new course",
                           form=form)