Bläddra i källkod

Merged DrkSephy/django-hackathon-starter into default

Eswari Pravallika Swarna 10 år sedan
förälder
incheckning
1a0bd69d9f

+ 1 - 1
README.md

@@ -95,7 +95,7 @@ As of `Django 1.7x`, there is a new method called `JsonResponse` which allows th
 
 As of `April 11th, 2015`, there is now a sample AngularJS client which pulls data from the Django sample API endpoint: `http://127.0.0.1:8000/hackathon/snippets/`. To test it, do the following:
 
-* Within the `public/` directory, run `python -m SimpleHTTPServer 80`. You may need `sudo` on your respective Operating System.
+* Within the `angular/` directory, run `python -m SimpleHTTPServer 80`. You may need `sudo` on your respective Operating System.
 * Navigate to: `http://localhost/#/snippets`. Here you will see whatever content was stored within the database model, `Snippet`. If nothing shows up, go back to the `RESTful endpoints` step to populate your database with some `Snippet` objects. 
 
 The following other links are available on the AngularJS Client:

+ 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(){                       
            

+ 20 - 0
hackathon_starter/hackathon/scripts/census.py

@@ -0,0 +1,20 @@
+'''
+Module containing a handful of methods for 
+aggregating U.S. Census data. 
+'''
+
+import requests
+import simplejson as json
+
+########################
+# CENSUS API CONSTANTS #
+########################
+
+API_BASE_URL = 'http://api.census.gov/data/2013/pep/natstprc'
+
+def getPopulationEstimate(url):
+	req = requests.get(url)
+	print len(req.text)
+	#print req.text
+
+getPopulationEstimate('http://api.census.gov/data/2013/pep/monthlynatchar5?get=AGE,SEX,DATE,RACE5,HISP,POP,UNIVERSE&key=1286203d2772de1f09f13392cc42a0197b2cd414')

+ 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  #
@@ -237,6 +230,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 #
 ######################