def config(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('index')) form = ConfigForm(request.form) if request.method == 'POST' and form.validate(): config = ConfigData(form.bucket.data, form.region.data,form.s3key.data, form.s3user.data, form.avldb.data,form.avluserid.data,form.avlpasswd.data,form.ec2pubkey.data) db_session.add(config) db_session.commit() flash('Config Data has been Saved') return redirect(url_for('index')) fo = open("/home/pythonautomate/Automate/automate.cfg", "w") cnx = MySQLdb.connect(**CONFIG.DATABASE) cur=cnx.cursor(MySQLdb.cursors.DictCursor) cur.execute("SELECT bucket,region,s3key,avldb,avluserid,avlpasswd,ec2pubkey from configdata") for row in cur.fetchall(): form.bucket.data=row['bucket'] form.region.data=row['region'] form.s3key.data=row['s3key'] form.s3user.data=row['avluserid'] form.avldb.data=row['avldb'] form.avluserid.data=row['avluserid'] form.avlpasswd.data=row['avlpasswd'] form.ec2pubkey.data=row['ec2pubkey'] # form.bucket.data = str[1].translate(None, "'")+ str[2].translate(None, "'") return render_template('config.html', form=form)
def post(self, *args, **kwargs): print self.request.arguments form = ConfigForm(self.request.arguments) if form.validate(): print 'here' data = create_yaml(self.request.arguments) data.seek(0) self.set_header('Content-Type', 'text/yaml') self.set_header('Content-Disposition', 'attachment; filename=config.yml') self.write(data.read()) self.finish() else: return self.render('form.html', context={'form': form})