From: František Dvořák Date: Sun, 13 Sep 2015 09:24:02 +0000 (+0200) Subject: Add multicheckbox with the tests. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=823d9f8b9641103202c12631ba9adbe716718349;p=pOCCI-flask.git Add multicheckbox with the tests. --- diff --git a/app.py b/app.py index 4fd87c8..c389f78 100755 --- a/app.py +++ b/app.py @@ -5,7 +5,8 @@ import cStringIO from flask import Flask, request, url_for, redirect, render_template from flask.ext.wtf import Form -from wtforms.fields import PasswordField, StringField, SubmitField +from wtforms.fields import BooleanField, FormField, PasswordField, SelectMultipleField, StringField, SubmitField +from wtforms import widgets import pOCCI import pOCCI.occi @@ -23,10 +24,23 @@ app = Flask(__name__) app.config['SECRET_KEY'] = 'please, tell nobody' +class MultiCheckboxField(SelectMultipleField): + """ + A multiple-select, except displays a list of checkboxes. + + Iterating the field will produce subfields, allowing custom rendering of + the enclosed checkbox fields. + """ + widget = widgets.ListWidget(prefix_label=False) + option_widget = widgets.CheckboxInput() + + class SubmitForm(Form): url = StringField(u'OCCI URL') user = StringField(u'User') password = PasswordField(u'Password') + + tests = MultiCheckboxField(u'Tests') submit = SubmitField(u'Launch tests') @@ -35,12 +49,14 @@ def launch(): error = None if request.method == 'POST': - opts = ['-t', 'OCCI/CORE/READ/001'] + opts = [] for p in params.keys(): if p in request.form and request.form[p]: opts.append(params[p]) opts.append(request.form[p]) - print opts + opts.append('-t') + opts.append(','.join(request.form.getlist('tests'))) + #print opts out = [cStringIO.StringIO(), cStringIO.StringIO()] sys.stdout = out[0] @@ -50,13 +66,17 @@ def launch(): except SystemExit as se: if se.args[0] >= 2: error = 'Fatal error.' - sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ return render_template('output.html', result = out[0].getvalue() + out[1].getvalue(), error = error) form = SubmitForm() + + tests_all = sorted(pOCCI.pOCCI.tests_definitions.keys()) + form.tests.choices = [(t, t) for t in tests_all] + form.tests.data = [(t) for t in sorted(list(set(tests_all)- pOCCI.pOCCI.tests_skipped))] + return render_template('index.html', form = form) diff --git a/templates/index.html b/templates/index.html index 36d5602..1302dc9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,6 +3,20 @@ OCCI Compliance Tests + @@ -18,7 +32,25 @@ {{ form.password.label }}{{ form.password(size=20, password=True) }} + + {{ form.tests.label }} + + + + + +{% for subfield in form.tests %} + +{% endfor %} +
+ + + +
{{ subfield }}{{ subfield.label }}
+ + + {{ form.submit }}