Bladeren bron

Rendering top committed repository data through template

David Leonard 10 jaren geleden
bovenliggende
commit
322bc72a4c

+ 1 - 2
hackathon_starter/hackathon/scripts/github.py

@@ -5,7 +5,6 @@ for interacting with Github data.
 
 import requests
 import simplejson as json
-import heapq
 
 ########################
 # GITHUB API CONSTANTS #
@@ -85,7 +84,7 @@ def getTopContributedRepositories(repos):
 
 def filterCommits(data):
 	maxCommits = []
-	for i in range(1, 5):
+	for i in range(1, 10):
 		maxCommitedRepo = max(data, key=lambda x:x['total'])
 		maxCommits.append(maxCommitedRepo)
 		index = data.index(maxCommitedRepo)

+ 53 - 28
hackathon_starter/hackathon/templates/hackathon/github.html

@@ -3,37 +3,62 @@
 <body>
 	{% include 'hackathon/base.html' %}
 
+    <h2> Generic Information </h2>
 	<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>
+        <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 %}
-            <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 %}
+            {% 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>
+            </tbody>
+            </table>
+        </div>
+    </div>
+
+    <h2> Top Contributed Repositories </h2>
+    <div class="col-lg-12">
+        <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>
+        </div>
     </div>
-</div>
 </body>
 </html>

+ 10 - 1
hackathon_starter/hackathon/views.py

@@ -117,11 +117,20 @@ def steam(request):
     return render(request,'hackathon/steam.html', {"game": game })
 
 def github(request):
+    allData = {}
+    # Get generic user data
     userData = getUserData()
+    # Get a list of all the user's repositories
     repositories = getUserRepositories()
+    # Get a list of all commit statistics for all repositories
     list = getTopContributedRepositories(repositories)
+    # Get a list of the top 10 most committed repositories
     filtered = filterCommits(list)
-    return render(request, 'hackathon/github.html', { 'data': userData })
+    # Store data into a dictionary for rendering
+    allData['userData'] = userData
+    allData['filteredData'] = filtered
+    
+    return render(request, 'hackathon/github.html', { 'data': allData })
 
 def tumblr(request):
     context = {'title': 'Tumblr Example'}