Browse Source

Adding for for querying Github User Data

David Leonard 10 years ago
parent
commit
c3fc3600b3

+ 54 - 102
hackathon_starter/hackathon/templates/hackathon/github.html

@@ -2,109 +2,61 @@
 <html>
 <body>
 	{% include 'hackathon/base.html' %}
-
-    <h1 class="text-center"> Github Resume </h1>
-	<div class="col-lg-12">
-        <div class="table-responsive">
-            <table class="table table-bordered table-hover table-striped tablesorter">
-                <thead>
-                <tr>
-                <th class="header"> Username <i class="icon-sort"></i></th>
-                <th class="header"> Blog <i class="icon-sort"></i></th>
-                <th class="header"> Public Repos <i class="icon-sort"></i></th>
-                <th class="header"> Public Gists <i class="icon-sort"></i></th>
-                <th class="header"> Email <i class="icon-sort"></i></th>
-                <th class="header"> Followers <i class="icon-sort"></i></th>
-                <th class="header"> Following <i class="icon-sort"></i></th>
-                </tr>
-            </thead>
-            <tbody>
-
-            {% for key in data.userData %}
-                <tr>
-                    <td>{{ key.name }}</td>
-                    <td>{{ key.blog }}</td>
-                    <td>{{ key.public_repos }}</td>
-                    <td>{{ key.public_gists }}</td>
-                    <td>{{ key.email }}</td>
-                    <td>{{ key.followers }}</td>
-                    <td>{{ key.following }}</td>
-    			</tr>
-            {% endfor %}
-
-            </tbody>
-            </table>
-        </div>
+    <style>
+      .form-signin {
+        max-width: 550px;
+        padding: 15px;
+        margin: 0 auto;
+      }    
+    </style>
+
+    <h1 class="text-center"> Github User Data </h1>
+
+    <div class="container text-center">
+        <form class="form-signin" id="login_form" method="post" action="/hackathon/githubUser/">
+          {% csrf_token %}
+          {% load bootstrap %}
+          <br>
+          <input type="text" name="user" class="form-control" placeholder="Github User Name, e.g: DrkSephy" value="" required autofocus>
+          <br>
+          <button class="btn btn-lg btn-primary btn-block" type="submit">Get Data</button>
+          <input type="hidden" name="submit" value="submit" />
+        </form>
     </div>
 
-    <div class="col-xs-4">
-        <h2> Top Contributed Repositories </h2>
-        <div class="table-responsive">
-            <table class="table table-bordered table-hover table-striped tablesorter">
-                <thead>
-                <tr>
-                <th class="header"> Repository <i class="icon-sort"></i></th>
-                <th class="header"> Total <i class="icon-sort"></i></th>
-                </tr>
-            </thead>
-            <tbody>
-
-            {% for key in data.filteredData %}
-                <tr>
-                    <td>{{ key.repo_name }}</td>
-                    <td>{{ key.total }}</td>
-                </tr>
-            {% endfor %}
-
-            </tbody>
-            </table>
+    {% if data %}
+    	<div class="col-lg-12">
+            <div class="table-responsive">
+                <table class="table table-bordered table-hover table-striped tablesorter">
+                    <thead>
+                    <tr>
+                    <th class="header"> Username <i class="icon-sort"></i></th>
+                    <th class="header"> Blog <i class="icon-sort"></i></th>
+                    <th class="header"> Public Repos <i class="icon-sort"></i></th>
+                    <th class="header"> Public Gists <i class="icon-sort"></i></th>
+                    <th class="header"> Email <i class="icon-sort"></i></th>
+                    <th class="header"> Followers <i class="icon-sort"></i></th>
+                    <th class="header"> Following <i class="icon-sort"></i></th>
+                    </tr>
+                </thead>
+                <tbody>
+
+                {% for key in data.userData %}
+                    <tr>
+                        <td>{{ key.name }}</td>
+                        <td>{{ key.blog }}</td>
+                        <td>{{ key.public_repos }}</td>
+                        <td>{{ key.public_gists }}</td>
+                        <td>{{ key.email }}</td>
+                        <td>{{ key.followers }}</td>
+                        <td>{{ key.following }}</td>
+        			</tr>
+                {% endfor %}
+
+                </tbody>
+                </table>
+            </div>
         </div>
-    </div>
-    <div class="col-xs-4">
-        <h2> Top Starred Repositories </h2>
-        <div class="table-responsive">
-            <table class="table table-bordered table-hover table-striped tablesorter">
-                <thead>
-                <tr>
-                <th class="header"> Repository <i class="icon-sort"></i></th>
-                <th class="header"> Count <i class="icon-sort"></i></th>
-                </tr>
-            </thead>
-            <tbody>
-
-            {% for key in data.filteredStargazers %}
-                <tr>
-                    <td>{{ key.name }}</td>
-                    <td>{{ key.stargazers_count }}</td>
-                </tr>
-            {% endfor %}
-
-            </tbody>
-            </table>
-        </div>
-    </div>
-
-    <div class="col-xs-4">
-        <h2> Contributions </h2>
-        <div class="table-responsive">
-            <table class="table table-bordered table-hover table-striped tablesorter">
-                <thead>
-                <tr>
-                <th class="header"> Repository <i class="icon-sort"></i></th>
-                </tr>
-            </thead>
-            <tbody>
-
-            {% for key in data.forkedRepos %}
-                <tr>
-                    <td>{{ key.name }}</td>
-                </tr>
-            {% endfor %}
-
-            </tbody>
-            </table>
-        </div>
-    </div>
-
+    {% endif %}
 </body>
-</html>
+</html>

+ 6 - 4
hackathon_starter/hackathon/views.py

@@ -289,10 +289,12 @@ def nytimesarticles(request):
 
 def githubUser(request):
     '''Returns JSON response about a specific Github User'''
-
     parsedData = {}
-    parsedData['userData'] = getUserData('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
-    return JsonResponse({ 'data': parsedData })
+    if request.method == 'POST':
+        user = request.POST.get('user')
+        parsedData['userData'] = getUserData(user, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
+    return render(request, 'hackathon/github.html', {'data': parsedData})
+    # return JsonResponse({ 'data': parsedData })
 
 def githubTopRepositories(request):
     '''Returns JSON response of a User's Top Committed repositories'''
@@ -319,7 +321,7 @@ def githubResume(request):
     allData['filteredData'] = filtered
     allData['filteredStargazers'] = filteredStargazers
     allData['forkedRepos'] = forkedRepos
-    return render(request, 'hackathon/github.html', { 'data': allData })
+    return render(request, 'hackathon/githubResume.html', { 'data': allData })
 
 
 #################