[tor-commits] [compass/master] Add a 'total' line at the bottom of the table

karsten at torproject.org karsten at torproject.org
Tue Sep 18 15:54:51 UTC 2012


commit b894185a7c7770df218436c9d99b6cba1795a134
Author: Sathyanarayanan Gunasekaran <gsathya.ceg at gmail.com>
Date:   Sun Sep 9 20:46:10 2012 +0530

    Add a 'total' line at the bottom of the table
---
 app.py                |   22 ++++++++++++++++++++--
 templates/result.html |    6 +++---
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/app.py b/app.py
index a0d2b05..3a66a79 100644
--- a/app.py
+++ b/app.py
@@ -26,6 +26,7 @@ class Opt(object):
 
 class Result():
     def __init__(self):
+        self.index = None
         self.cw = None
         self.adv_bw = None
         self.p_guard = None
@@ -66,6 +67,7 @@ def parse(output_string, grouping=False, sort_key=None):
             
         # TODO: change inaccurate value of 10
         if len(values) > 10:
+            result.index = id
             result.cw = values[0]
             result.adv_bw = values[1]
             result.p_guard = values[2]
@@ -89,6 +91,23 @@ def parse(output_string, grouping=False, sort_key=None):
                     sorted_results[key] = [result]
             else:
                 results.append(result)
+        else:
+            result.index = ""
+            result.cw = values[0]
+            result.adv_bw = values[1]
+            result.p_guard = values[2]
+            result.p_middle = values[3]
+            result.p_exit = values[4]
+            result.nick = ""
+            result.fp = ' '.join(values[5:])
+            result.exit = ""
+            result.guard = ""
+            result.cc = ""
+            result.as_no = ""
+            result.as_name = ""
+            result.as_info = ""
+            results.append(result)
+
     return results if results else sorted_results
 
 @app.route('/')
@@ -130,7 +149,6 @@ def result():
                    short=None,
                    links=None)
     results = parse(output_string, options.by_country or options.by_as, sort_key)
-    
     if sort_key:
         for key in sorted(results.iterkeys(), reverse=True):
             for value in results[key]:
@@ -138,7 +156,7 @@ def result():
     else:
         relays = results
     
-    return render_template('result.html', results=relays)
+    return render_template('result.html', results=relays, grouping=options.by_as or options.by_country)
     
 if __name__ == '__main__':
     # Bind to PORT if defined, otherwise default to 5000.
diff --git a/templates/result.html b/templates/result.html
index 190e8fc..5fad51c 100644
--- a/templates/result.html
+++ b/templates/result.html
@@ -19,15 +19,15 @@
     <tbody>
       {% for result in results %}
       <tr>
-        <td>{{ loop.index }}</td>
+        <td>{{ result.index }}</td>
         <td>{{ result.cw }}</td>
         <td>{{ result.adv_bw }}</td>
         <td>{{ result.p_guard }}</td>
         <td>{{ result.p_middle }}</td>
         <td>{{ result.p_exit }}</td>
         <td>{{ result.nick }}</td>
-        <!-- this happens when we do groupings-->
-        {% if "relays" in result.fp %}
+        <!-- it's not a fingerprint -->
+        {% if result.fp|length != 40 %}
         <td>{{ result.fp }}</td>
         {% else %}
         <td><a href="https://atlas.torproject.org/#details/{{ result.fp }}">{{ result.fp[:8] }}</a></td>





More information about the tor-commits mailing list