예제 #1
0
def edit_fabfile_handler(fabfile_id):

    fabfile = FabFile.query.filter_by(id=fabfile_id).first()
    with io.open(os.path.join(current_app.config['FABRIC_FILE_PATH'], '%s.py' % fabfile.name), mode='rt',
                 encoding='utf-8') as f:
        fabfile.script = f.read()

    form = FabFileForm(id=fabfile.id, name=fabfile.name, desc=fabfile.desc,
                       groups=fabfile.groups, script=fabfile.script)

    if request.method == 'POST' and form.validate():

        with io.open(os.path.join(current_app.config['FABRIC_FILE_PATH'], '%s.py' % form.name.data), mode='wt',
                  encoding='utf-8') as f:
            f.write(form.script.data.replace('\r\n', '\n').replace('\r', '\n'))

        if form.desc.data != fabfile.desc:
            fabfile.desc = form.desc.data

        fabfile.set_groups(form.groups.data)

        db.session.commit()

        flash(u'Edit fabfile successfully', 'success')
        return redirect(url_for('dashboard.list_fabfile_handler'))

    else:
        return render_template('dashboard/fabfile_manager.html', form=form, action='edit')
예제 #2
0
def create_fabfile_handler():

    form = FabFileForm()
    if request.method == 'POST' and form.validate():

        with io.open(os.path.join(current_app.config['FABRIC_FILE_PATH'], '%s.py' % form.name.data), mode='wt',
                    encoding='utf-8') as f:
            f.write(form.script.data.replace('\r\n', '\n').replace('\r', '\n'))

        fabfile = FabFile(form.name.data, form.desc.data, current_user.id, form.groups.data)
        db.session.add(fabfile)
        db.session.commit()

        flash(u'Create fabfile successfully', 'success')
        return redirect(url_for('dashboard.list_fabfile_handler'))

    else:
        return render_template('dashboard/fabfile_manager.html', form=form, action='create')
예제 #3
0
def edit_fabfile_handler(fabfile_id):

    fabfile = FabFile.query.filter_by(id=fabfile_id).first()

    if fabfile.author_id != current_user.id:
        flash(u'Don\'t have permission to access this link', 'error')
        return redirect(url_for('account.index_handler'))

    with io.open(os.path.join(current_app.config['FABRIC_FILE_PATH'],
                              '%s.py' % fabfile.name),
                 mode='rt',
                 encoding='utf-8') as f:
        fabfile.script = f.read()

    form = FabFileForm(id=fabfile.id,
                       name=fabfile.name,
                       desc=fabfile.desc,
                       groups=fabfile.groups,
                       script=fabfile.script)

    if request.method == 'POST' and form.validate():

        with io.open(os.path.join(current_app.config['FABRIC_FILE_PATH'],
                                  '%s.py' % form.name.data),
                     mode='wt',
                     encoding='utf-8') as f:
            f.write(form.script.data.replace('\r\n', '\n').replace('\r', '\n'))

        fabfile.set_groups(form.groups.data)

        if form.desc.data != fabfile.desc:
            fabfile.desc = form.desc.data

        db.session.commit()

        flash(u'Edit fabfile successfully', 'success')
        return redirect(url_for('account.list_fabfile_handler'))

    else:
        return render_template('account/fabfile_manager.html',
                               form=form,
                               action='edit')
예제 #4
0
def create_fabfile_handler():

    form = FabFileForm()
    if request.method == 'POST' and form.validate():

        with io.open(os.path.join(current_app.config['FABRIC_FILE_PATH'],
                                  '%s.py' % form.name.data),
                     mode='wt',
                     encoding='utf-8') as f:
            f.write(form.script.data.replace('\r\n', '\n').replace('\r', '\n'))

        fabfile = FabFile(form.name.data, form.desc.data, current_user.id,
                          form.groups.data)
        db.session.add(fabfile)
        db.session.commit()

        flash(u'Create fabfile successfully', 'success')
        return redirect(url_for('dashboard.list_fabfile_handler'))

    else:
        return render_template('dashboard/fabfile_manager.html',
                               form=form,
                               action='create')