Permalink
Browse files

WTForms for forms.

  • Loading branch information...
1 parent 50ed9e5 commit 7d33a2af82d02770c62a475fe3baffd6760adacd @oremj oremj committed Nov 11, 2011
Showing with 33 additions and 14 deletions.
  1. +12 −11 chief.py
  2. +9 −0 forms.py
  3. +12 −3 templates/index.html
View
@@ -7,14 +7,15 @@
from flask import Flask, Response, abort, request, render_template
import settings
+from forms import DeployForm
app = Flask(__name__)
os.environ['PYTHONUNBUFFERED'] = 'go time'
-def do_update(app_name, app_settings, webapp_tag, who):
+def do_update(app_name, app_settings, webapp_ref, who):
deploy = app_settings['script']
log_dir = os.path.join(settings.OUTPUT_DIR, app_name)
if not os.path.isdir(log_dir):
@@ -26,17 +27,17 @@ def run(task, output):
def pub(event):
redis = redislib.Redis(**settings.REDIS_BACKENDS['master'])
- d = {'event': event, 'ref': webapp_tag, 'who': who}
+ d = {'event': event, 'ref': webapp_ref, 'who': who}
redis.publish(app_settings['pubsub_channel'], json.dumps(d))
try:
pub('BEGIN')
- yield 'Updating! revision: %s\n' % webapp_tag
+ yield 'Updating! revision: %s\n' % webapp_ref
log_file = os.path.join(log_dir,
- re.sub('[^A-z0-9]', '.', webapp_tag))
+ re.sub('[^A-z0-9]', '.', webapp_ref))
output = open(log_file, 'a')
- run('pre_update:%s' % webapp_tag, output)
+ run('pre_update:%s' % webapp_ref, output)
pub('PUSH')
yield 'We have the new code!\n'
@@ -59,13 +60,13 @@ def index(webapp):
else:
app_settings = settings.WEBAPPS[webapp]
- if request.method == 'POST':
- post = request.form
- assert sorted(post.keys()) == ['password', 'tag', 'who']
- assert post['password'] == app_settings['password']
+ form = DeployForm(request.form)
+ if request.method == 'POST' and form.validate():
+ if form.password.data != app_settings['password']:
+ abort(403)
return Response(do_update(webapp, app_settings,
- post['tag'], post['who']),
+ form.ref.data, form.who.data),
direct_passthrough=True,
mimetype='text/plain')
- return render_template("index.html", app_name=webapp)
+ return render_template("index.html", app_name=webapp, form=form)
View
@@ -0,0 +1,9 @@
+from wtforms import Form, TextField, PasswordField, validators
+
+import settings
+
+
+class DeployForm(Form):
+ ref = TextField('git ref', [validators.Required()])
+ password = PasswordField('secret', [validators.Required()])
+ who = TextField('identify yourself', [validators.Required()])
View
@@ -56,10 +56,19 @@
}
</style>
<h1>Hi, I'm the chief of {{ app_name }}.</h1>
+{% if form.errors %}
+ <ul class="errors">
+ {% for field_name, field_errors in form.errors if field_errors %}
+ {% for error in field_errors %}
+ <li>{{ form[field_name].label }}: {{ error }}</li>
+ {% endfor %}
+ {% endfor %}
+ </ul>
+{% endif %}
<form method="post" action="">
- <input name="tag" placeholder="git tag">
- <input name="password" type="password" placeholder="secret">
- <input name="who" placeholder="identify yourself">
+ {{ form.tag(placeholder=form.tag.label) }}
+ {{ form.password(placeholder=form.password.label) }}
+ {{ form.who(placeholder=form.who.label) }}
<br>
<button title="BIG RED BUTTON"></button>
</form>

0 comments on commit 7d33a2a

Please sign in to comment.