Skip to content
Browse files

Styling brought much closer to desired layout for messages. Submit to…

… Twilio working, with response committed to DB. On-page status update working via jQuery.
  • Loading branch information...
1 parent bbefefe commit 637c5a39a7903c031de0035a9c870a6c78c2e7aa @akavlie committed
View
3 sms/model.py
@@ -12,9 +12,10 @@ class Sent(db.Model):
message = db.Column(db.String)
status = db.Column(db.String)
- def __init__(self, phone, message):
+ def __init__(self, phone, message, status):
self.phone = phone
self.message = message
+ self.status = status
class Message(db.Model):
""" Frequently used SMS messages """
View
BIN sms/model.pyc
Binary file not shown.
View
37 sms/static/style.css
@@ -1,13 +1,23 @@
body {
font-family: sans-serif;
+ font-size: 16px;
}
#page {
margin: 50px 200px;
}
+.clear {
+ clear: both;
+}
+
h1 {
- font-size: 30pt;
+ font-size: 40px;
+}
+
+h2 {
+ padding-bottom: 5px;
+ border-bottom: 1px solid gray;
}
.flash {
@@ -19,16 +29,31 @@ h1 {
/* SENT MESSAGES */
#sent_message_list {
+ width: 80%;
}
.sent_message {
position: relative;
+ margin-bottom: 10px;
+ border: 1px solid black;
+ height: 120px;
}
.sent_message .status {
+ padding: 5px;
+ border-bottom: 1px solid black;
}
- .sent_message .phone {
- }
- .sent_message .time {
- }
- .sent_message .message_text {
+ .sent_message .sent_body {
+ padding: 5px;
}
+ .sent_message .phone {
+ float: left;
+ width: 300px;
+ }
+ .sent_message .time {
+ float: right;
+ text-align: right;
+ width: 200px;
+ }
+ .sent_message .message_text {
+ margin-top: 15px;
+ }
View
29 sms/templates/index.html
@@ -7,14 +7,11 @@
$(function() {
$("#sms_form").submit(function() {
- //$.post("/sms", $("#sms_form").serialize());
- //$("#sent_messages td").animate({top: '+=50'}, 'slow');
- $("#sent_messages td").slideOut();
+ $.post("/sms", $("#sms_form").serialize(),
+ function(data) {
+ $('#status').html(data.status);
+ }, 'json');
return false;
- });
-
- $('#go').click(function() {
- $("#play").animate({top: '+=50'}, 'slow');
});
});
@@ -28,15 +25,27 @@
<input type="submit" value="Send" /></p>
</form>
+<div id="test">
+ <p id="status">null</p>
+ <p id="phone">null</p>
+ <p id="message">null</p>
+</div>
+
{% if sent_messages %}
+ <div id="sent_message_list">
+ <h2>Message History</h2>
{% for message in sent_messages %}
<div class="sent_message">
<div class="status">{{ message.status }}</div>
- <div class="phone">{{ message.phone }}</div>
- <div class="time">{{ message.date }}</div>
- <div class="message_text">{{ message.message }}</div>
+ <div class="sent_body">
+ <div class="phone">{{ message.phone }}</div>
+ <div class="time">{{ message.date }}</div>
+ <div class="clear"></div>
+ <div class="message_text"><p>{{ message.message }}</p></div>
+ </div>
</div>
{% endfor %}
+ </div>
{% else %}
No messages yet!
{% endif %}
View
8 sms/tw_send.py
@@ -10,6 +10,8 @@ def twilio_send(phone_number, message):
account = twilio.Account(app.config['ACCOUNT_SID'],
app.config['ACCOUNT_TOKEN'])
- account.request('/%s/Accounts/%s/SMS/Messages' % (app.config['API_VERSION'],
- app.config['ACCOUNT_SID']),
- 'POST', data)
+ tw_response = account.request('/%s/Accounts/%s/SMS/Messages.json' %
+ (app.config['API_VERSION'], app.config['ACCOUNT_SID']),
+ 'POST', data)
+
+ return tw_response
View
BIN sms/tw_send.pyc
Binary file not shown.
View
16 sms/views.py
@@ -1,3 +1,5 @@
+import json
+
from sms import app
from flask import render_template, request, redirect, url_for, flash
from model import db, Sent, Message
@@ -11,10 +13,16 @@ def index():
@app.route('/sms', methods=['POST'])
def sms():
- twilio_send(request.form['phone_number'], request.form['message'])
- sms = Sent(request.form['phone_number'], request.form['message'])
+ # Send to Twilio
+ tw_response = twilio_send(request.form['phone_number'], request.form['message'])
+
+ # Convert JSON from Twilio to Python dict
+ sms_data = json.loads(tw_response)
+
+ # Commit to database
+ sms = Sent(sms_data['to'], sms_data['body'], sms_data['status'])
db.session.add(sms)
db.session.commit()
- flash('SMS sent to %s' % request.form['phone_number'])
- #return redirect(url_for('index'))
+ # flash('SMS sent to %s' % request.form['phone_number'])
+ return tw_response
View
BIN sms/views.pyc
Binary file not shown.

0 comments on commit 637c5a3

Please sign in to comment.
Something went wrong with that request. Please try again.