diff --git a/sms/__init__.pyc b/sms/__init__.pyc deleted file mode 100644 index b248034..0000000 Binary files a/sms/__init__.pyc and /dev/null differ diff --git a/sms/config.pyc b/sms/config.pyc deleted file mode 100644 index 1ca3a8b..0000000 Binary files a/sms/config.pyc and /dev/null differ diff --git a/sms/model.pyc b/sms/model.pyc deleted file mode 100644 index 0b32b83..0000000 Binary files a/sms/model.pyc and /dev/null differ diff --git a/sms/static/sms.js b/sms/static/sms.js index bc4a84d..2ced1ec 100644 --- a/sms/static/sms.js +++ b/sms/static/sms.js @@ -1,42 +1,37 @@ var status_checker = 0; -$(function() { - $('#test').click(function() { - $('.sent_message:first').slideToggle(1000); - }); - - $("#sms_form").submit(function() { - // Post form data via AJAX - $.post($SCRIPT_ROOT + "/sms", $("#sms_form").serialize(), - function(data) { - // Insert returned HTML before the first message - $('#sent_message_list h2').after(data); - // Animate height expansion, then opacity - $('.new').animate({height: 'toggle'}) - .animate({opacity: 1}) - // Remove class so it doesn't catch animation again - .removeClass('new'); - // Check status of new messages at set interval - if(status_checker==0) { - status_checker = setInterval('checkStatus()', 5000); - } - }); - return false; - }); - +$("#sms_form").submit(function() { + // Post form data via AJAX + $.post($SCRIPT_ROOT + "/sms", $("#sms_form").serialize(), + function(data) { + // Insert returned HTML after the heading + $('#sent_message_list h2').after(data); + // Animate height expansion, then opacity + $('.new').animate({height: 'toggle'}) + .animate({opacity: 1}) + // Remove class so it doesn't catch animation again + .removeClass('new'); + // Check status of new messages at set interval + if(status_checker==0) { + status_checker = setInterval('checkStatus()', 5000); + } + }); + return false; }); function checkStatus() { - $('.queued, .sending, .fake').children('.status').each(function(i) { - if ($(this).text() == 'fake') { - $(this).html('TEST'); - } else { - $(this).html('FAIL'); - } - $(this).parent().removeClass('queued sending fake'); + // Check every message on the page with status "queued" or "sending" -- + // Twilio's status possibilities for unsent messsages + $('.queued, .sending').children('.status').each(function(i) { + var sid = $(this).parent().find('.sid').html(); + // Update status based on check with twilio + $(this).load($SCRIPT_ROOT + '/sms/update/' + sid, function(status) { + // Add class based on current status; remove former status class + $(this).parent().addClass(status).removeClass('queued sending'); }); - // Stop checking message status - clearInterval(status_checker); - status_checker = 0; + }); + // Stop checking message status + clearInterval(status_checker); + status_checker = 0; } diff --git a/sms/templates/index.html b/sms/templates/index.html index 8d9328f..214f1d7 100644 --- a/sms/templates/index.html +++ b/sms/templates/index.html @@ -17,14 +17,14 @@

Message History

{% for message in sent_messages %} -
+
{{ message.status }}
{{ message.phone }}
{{ message.date }}

{{ message.message }}

- +
{% endfor %} diff --git a/sms/templates/sent_message.html b/sms/templates/sent_message.html index c5f4081..9619a65 100644 --- a/sms/templates/sent_message.html +++ b/sms/templates/sent_message.html @@ -5,6 +5,6 @@
{{ sms.date_created }}

{{ sms.body }}

- +
diff --git a/sms/tw_send.py b/sms/tw_send.py index b5ee553..23071e1 100644 --- a/sms/tw_send.py +++ b/sms/tw_send.py @@ -20,16 +20,12 @@ def twilio_send(phone_number, message): def twilio_update(sid): """Update status for a given SMS. """ - data = {'From': app.config['CALLER_ID'], - 'To': phone_number, - 'Body': message} - account = twilio.Account(app.config['ACCOUNT_SID'], app.config['ACCOUNT_TOKEN']) tw_response = account.request('/%s/Accounts/%s/SMS/Messages/%s.json' % (app.config['API_VERSION'], app.config['ACCOUNT_SID'], sid), - 'GET', data) + 'GET') return tw_response diff --git a/sms/tw_send.pyc b/sms/tw_send.pyc deleted file mode 100644 index bc53878..0000000 Binary files a/sms/tw_send.pyc and /dev/null differ diff --git a/sms/views.py b/sms/views.py index 555e279..e44522d 100644 --- a/sms/views.py +++ b/sms/views.py @@ -5,7 +5,7 @@ from model import db, User, SentMessage, FrequentText from datetime import datetime -from tw_send import twilio_send +from tw_send import twilio_send, twilio_update @app.route('/') def index(): @@ -32,17 +32,17 @@ def sms(): # flash('SMS sent to %s' % request.form['phone_number']) return render_template('sent_message.html', sms=sms_data) -@app.route('/sms/update/', methods=['POST']) +@app.route('/sms/update/') def sms_update(sid): """Update an SMS based on query from Twilio. """ tw_response = twilio_update(sid) sms_data = json.loads(tw_response) - sms = SentMessage.query.filter_by('sid=%s' % sid).one() - sms.status = sms_data.status + sms = SentMessage.query.filter_by(sid=sid).one() + sms.status = sms_data['status'] db.session.commit() - return sms_data.status + return sms.status diff --git a/sms/views.pyc b/sms/views.pyc deleted file mode 100644 index 9db25e1..0000000 Binary files a/sms/views.pyc and /dev/null differ