From 751e5d621381119713dd8f6621f7d2b253efbb74 Mon Sep 17 00:00:00 2001 From: Matt Webb Date: Fri, 26 Sep 2014 22:30:04 +0100 Subject: [PATCH] adding some forms --- app/__init__.py | 11 +++++------ app/core/__init__.py | 2 +- app/core/commands.py | 2 +- app/main/__init__.py | 20 ++++++++++++++++---- app/queues.py | 0 app/templates/dump.html | 3 +++ 6 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 app/queues.py diff --git a/app/__init__.py b/app/__init__.py index aca346e..215cca1 100755 --- a/app/__init__.py +++ b/app/__init__.py @@ -12,7 +12,6 @@ bootstrap = Bootstrap() db = SQLAlchemy() sockets = Sockets() - # @TODO # for this to work, I have to put the following line at line 38 of # flask_sockets, to inject it into the environment @@ -29,7 +28,7 @@ def create_app(config_name): bootstrap.init_app(app) db.init_app(app) sockets.init_app(app) - + # maybe this sets the HTTP_SEC_WEBSOCKET_PROTOCOL ? app.protocol_name = protocol_name @@ -41,8 +40,11 @@ def create_app(config_name): app.register_blueprint(admin_blueprint, url_prefix='/admin') #from .core import coresocket - from .core.command_sender import CommandSender from .core.events import process_event + from .core.command_sender import CommandSender + + sender = CommandSender() + sender.run() @sockets.route('/api/v1/connection') def coresocket(ws): @@ -57,8 +59,5 @@ def create_app(config_name): process_event(ws, event, sender) #except Exception, e: # print "Exception: %r" % e - - sender = CommandSender() - sender.run() return app diff --git a/app/core/__init__.py b/app/core/__init__.py index e68eee2..c3872c6 100644 --- a/app/core/__init__.py +++ b/app/core/__init__.py @@ -1,7 +1,7 @@ from app import sockets from .events import process_event -from .command_sender import CommandSender +#from .command_sender import CommandSender import json diff --git a/app/core/commands.py b/app/core/commands.py index 71ae7b7..f32b8aa 100644 --- a/app/core/commands.py +++ b/app/core/commands.py @@ -117,7 +117,7 @@ def set_delivery_and_print(device_address): command = DeviceCommand( device_address=device_address, binary_payload=base64.b64encode(set_delivery_and_print_payload(TEST_FILE_ID, TEST_PNG_FN)), - state='ready', + state=u'ready', deliver_at=datetime.utcnow() ) db.session.add(command) diff --git a/app/main/__init__.py b/app/main/__init__.py index 5ffa889..998fa37 100644 --- a/app/main/__init__.py +++ b/app/main/__init__.py @@ -1,19 +1,31 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, flash +from flask.ext.wtf import Form +from wtforms import StringField, TextAreaField, BooleanField, SelectField,\ + SubmitField from app.models.core import Device +from app.core.commands import set_delivery_and_print import pprint main = Blueprint('main', __name__) +class SendDeliveryForm(Form): + submit = SubmitField('Send Delivery') + @main.route('/') def index(): devices = Device.query.all() return render_template('index.html', devices=devices) -@main.route('/device/') +@main.route('/device/', methods=['GET', 'POST']) def device(device_address): device = Device.query.get_or_404(device_address) - - return render_template('dump.html', dump=pprint.pformat(device)) + form = SendDeliveryForm() + + if form.validate_on_submit(): + flash('Form submitted') + #dc = set_delivery_and_print(device_address) + # now queue it, but where? + return render_template('dump.html', dump=pprint.pformat(device), form=form) diff --git a/app/queues.py b/app/queues.py new file mode 100644 index 0000000..e69de29 diff --git a/app/templates/dump.html b/app/templates/dump.html index 3d8d11d..b752b79 100644 --- a/app/templates/dump.html +++ b/app/templates/dump.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% import "bootstrap/wtf.html" as wtf %} {% block title %}Sirius - Dump{% endblock %} @@ -9,4 +10,6 @@ {{ dump }} +{{ wtf.quick_form(form) }} + {% endblock %} \ No newline at end of file -- 2.47.3