Add multicheckbox with the tests.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 13 Sep 2015 09:24:02 +0000 (11:24 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 13 Sep 2015 09:24:02 +0000 (11:24 +0200)
app.py
templates/index.html

diff --git a/app.py b/app.py
index 4fd87c8..c389f78 100755 (executable)
--- 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)
 
 
index 36d5602..1302dc9 100644 (file)
@@ -3,6 +3,20 @@
 
 <head>
     <title>OCCI Compliance Tests</title>
+    <script>
+        function tests_all(state) {
+            checkboxes = document.getElementsByName('tests')
+            for (var i=0, n=checkboxes.length; i<n; i++) {
+                checkboxes[i].checked = state;
+            }
+        }
+        function tests_defaults(state) {
+            checkboxes = document.getElementsByName('tests')
+            for (var i=0, n=checkboxes.length; i<n; i++) {
+                checkboxes[i].checked = checkboxes[i].defaultChecked;
+            }
+        }
+    </script>
 </head>
 
 <body>
             <tr>
                 <td>{{ form.password.label }}</td><td>{{ form.password(size=20, password=True) }}</td>
             </tr>
+            <tr>
+                <td>{{ form.tests.label }}</td>
+                <td>
+                    <table>
+                        <tr>
+                            <td colspan=3>
+                                <input type="button" name="tests-default" onclick="tests_defaults('')" value="Default"/>
+                                <input type="button" name="tests-all" onclick="tests_all('TRUE')" value="All"/>
+                                <input type="button" name="tests-none" onclick="tests_all('')" value="None"/>
+                            </td>
+                        </tr>
+{% for subfield in form.tests %}
+                        <tr><td>{{ subfield }}</td><td>{{ subfield.label }}</td></tr>
+{% endfor %}
+                    </table>
+                </td>
+            </tr>
         </table>
+
         {{ form.submit }}
     </form>
 </body>