コード例 #1
0
def edit_experiment(id):
    """
    Edit a experiment
    """

    add_experiment = False

    experiment = Experiment.query.filter_by(id=id).first()
    form = ExperimentForm(obj=experiment)
    if form.validate_on_submit():
        experiment.name = form.name.data
        experiment.description = form.description.data
        experiment.content = form.content.data
        experiment.courseNums = form.courseNums.data.courseNums
        # type(form.courseNums.data) is app.models.course
        experiment.containerName = form.containerName.data# .name
        # type(form.containerName.data) is unicode
        db.session.commit()
        flash(u'实验修改成功')

        # redirect to the experiments page
        return redirect(url_for('admin.list_experiments'))

    experiment.name = form.name.data
    experiment.description = form.description.data
    experiment.content = form.content.data
    experiment.courseNums = form.courseNums.data# .courseNums
    experiment.containerName = form.containerName.data
    return render_template('admin/experiments/experiment.html', add_experiment=add_experiment,
                           form=form, title="Edit experiment")
コード例 #2
0
def add_experiment():
    """
    Add a experiment
    """

    add_experiment = True

    form = ExperimentForm()
    if form.validate_on_submit():
        experiment = Experiment(name=form.name.data,description=form.description.data,
                    content=form.content.data,courseNums=form.courseNums.data.courseNums,
                    containerName=form.containerName.data, teacherName=current_user.name)  # .name)
        try:
            db.session.add(experiment)
            db.session.commit()
            flash(u'实验创建完成')
        except:
            flash(u'实验创建失败')
            return redirect(url_for('admin.add_experiment'))
            

        # redirect to the experiments page
        return redirect(url_for('admin.list_experiments'))

    return render_template('admin/experiments/experiment.html', add_experiment=add_experiment,
                           form=form, title="Add experiment")
コード例 #3
0
def experiments_create():
    form = ExperimentForm()
    if form.validate_on_submit():
        return 'Yay!'
    else:
        return render_template('experiments/new.html', form=form)