瀏覽代碼

Merged DrkSephy/django-hackathon-starter into default

Wan Kim Mok 10 年之前
父節點
當前提交
454e5dd6d9
共有 3 個文件被更改,包括 44 次插入16 次删除
  1. 1 1
      angular/index.html
  2. 27 8
      hackathon_starter/hackathon/templates/hackathon/twilio.html
  3. 16 7
      hackathon_starter/hackathon/views.py

+ 1 - 1
angular/index.html

@@ -23,7 +23,7 @@
         <script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
 
         <!-- Front-end JavaScript -->
-        <script src="jquery.navgoco.js"></script>
+        <script src="js/jquery.navgoco.js"></script>
         <script>
         $(document).ready(function(){                       
            

+ 27 - 8
hackathon_starter/hackathon/templates/hackathon/twilio.html

@@ -1,12 +1,31 @@
 <!DOCTYPE html>
 <html>
-<body>
-	{% include 'hackathon/base.html' %}
+    {% include 'hackathon/base.html' %}
+    <style>
+      .form-signin {
+        max-width: 550px;
+        padding: 15px;
+        margin: 0 auto;
+      }    
+    </style>
 
-    <h1 class="text-center"> Twilio Messages </h1>
-    {{ context }}
-    </div>
-    
+    <body>
 
-</body>
-</html>
+      {{ context }}
+      <h1 class="text-center"> Twilio Messages </h1>
+      <div class="container text-center">
+        <form class="form-signin" id="login_form" method="post" action="/hackathon/twilio/">
+          {% csrf_token %}
+          {% load bootstrap %}
+          <br>
+          <input type="text" name="number" class="form-control" placeholder="Phone Number - e.g: +13473282978" value="" required autofocus>
+          <br>
+          <input type="text" name="message" class="form-control" placeholder="Message - e.g: Hello World!" value="" required>
+          <br>
+          <button class="btn btn-lg btn-primary btn-block" type="submit">Send Message</button>
+          <input type="hidden" name="submit" value="submit" />
+        </form>
+      </div>
+
+    </body>
+</html>

+ 16 - 7
hackathon_starter/hackathon/views.py

@@ -37,13 +37,6 @@ def index(request):
     context = {'hello': 'world'}
     return render(request, 'hackathon/index.html', context)
 
-##################
-#   Twilio API   #
-##################
-
-def twilio(request):
-    sendSMS('Meow', '+13473282978', '+13473781813')
-    return render(request, 'hackathon/twilio.html')
 
 ##################
 #  API Examples  #
@@ -255,6 +248,22 @@ def snippet_list(request):
         return JSONResponse(serializer.data)
 
 
+##################
+#   Twilio API   #
+##################
+
+def twilio(request):
+    # Test credentials
+    # sendSMS('Meow', '+13473282978', '+13473781813')
+    if request.method == 'POST':
+        number = request.POST.get('number')
+        message = request.POST.get('message')
+        sendSMS(str(message), str(number), '+13473781813')
+        context = {'message': 'Your message has been sent successfully!'}
+        return HttpResponseRedirect('/hackathon/api/')
+    return render(request, 'hackathon/twilio.html')
+
+
 ######################
 # Registration Views #
 ######################