[hamster-applet] layout adjustments, using Template substitution; bit of interactivity



commit 8c12754d70e80948503c707dc55326b8c0f845cf
Author: Toms Bauģis <toms baugis gmail com>
Date:   Sat Jun 5 17:24:07 2010 +0100

    layout adjustments, using Template substitution; bit of interactivity

 data/html_template/by_date.html           |   18 +++--
 data/html_template/by_date_row.html       |    4 +-
 data/html_template/by_date_total_row.html |    6 +-
 data/html_template/fact_row.html          |   14 ++--
 data/html_template/main.html              |  109 +++++++++++++++++++----------
 src/hamster/reports.py                    |   22 ++++---
 6 files changed, 108 insertions(+), 65 deletions(-)
---
diff --git a/data/html_template/by_date.html b/data/html_template/by_date.html
index 9e1e5c7..528cac9 100644
--- a/data/html_template/by_date.html
+++ b/data/html_template/by_date.html
@@ -1,11 +1,15 @@
 <tr valign="top">
-    <td>%(date)s</td>
-    <td style="padding: 0; margin: 0">
-        <table style="padding: 0; margin: 0">
-            %(by_date_rows)s
-
-            %(by_date_total_rows)s
+    <td>$date</td>
+    <td class="by_date_row">
+        <table width="100%%">
+            $by_date_rows
+        </table>
+    </td>
+    <td class="by_date_total_row">
+        <table width="100%%">
+            $by_date_total_rows
         </table>
     </td>
+
 </tr>
-<tr><td colspan="2">&nbsp</td></tr>
+<tr><td colspan="3">&nbsp</td></tr>
diff --git a/data/html_template/by_date_row.html b/data/html_template/by_date_row.html
index be95a21..1612b74 100644
--- a/data/html_template/by_date_row.html
+++ b/data/html_template/by_date_row.html
@@ -1,4 +1,4 @@
 <tr>
-    <td>%(activity)s (%(category)s)</td>
-    <td>%(duration)s</td>
+    <td>$activity ($category)</td>
+    <td style="text-align: right">$duration</td>
 </tr>
diff --git a/data/html_template/by_date_total_row.html b/data/html_template/by_date_total_row.html
index ecf2486..53e07da 100644
--- a/data/html_template/by_date_total_row.html
+++ b/data/html_template/by_date_total_row.html
@@ -1,4 +1,4 @@
 <tr>
-    <td><b>Total %(category)s</b></td>
-    <td>%(duration)s</td>
-</tr>
+    <td>$category</td>
+    <td style="text-align: right">$duration</td>
+</div>
diff --git a/data/html_template/fact_row.html b/data/html_template/fact_row.html
index cb8a3a2..ab3c052 100644
--- a/data/html_template/fact_row.html
+++ b/data/html_template/fact_row.html
@@ -1,10 +1,10 @@
 <tr>
-    <td>%(date)s</td>
-    <td>%(activity)s</td>
-    <td>%(category)s</td>
-    <td>%(tags)s</td>
-    <td>%(start)s</td>
-    <td>%(duration)s</td>
-    <td>%(description)s</td>
+    <td>$date</td>
+    <td>$activity</td>
+    <td>$category</td>
+    <td>$tags</td>
+    <td>$start</td>
+    <td>$duration</td>
+    <td>$description</td>
 </tr>
 
diff --git a/data/html_template/main.html b/data/html_template/main.html
index 541a7a3..5793693 100644
--- a/data/html_template/main.html
+++ b/data/html_template/main.html
@@ -6,10 +6,10 @@
     <meta name="author" content="hamster-applet" />
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";></script>
     <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js";></script>
-    <link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css"; rel="stylesheet" /> 
-    
-    
-    <title>%(title)s</title>
+    <link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css"; rel="stylesheet" />
+
+
+    <title>$title</title>
     <style type="text/css">
         body {
             font-family: "sans-serif";
@@ -24,8 +24,6 @@
         }
         th, td {
             text-align: left;
-            padding-top: none
-            padding: 3px;
             padding-right: 24px;
         }
 
@@ -33,59 +31,96 @@
             padding-top: 12px;
         }
 
-        ul {padding-bottom: 12px; margin-left: 12px; padding-left: 0px; list-style: none}
-        li {padding: 2px 0px; margin: 0}
-
         .even {background-color: #eee;}
-        .odd {background-color: #ffffff;}
+        .odd {background-color: #fff;}
+
+        .by_day_controls {
+            margin-bottom: 24px;
+        }
     </style>
 
     <style type="text/css" media="print">
         div#tabs ul {
             display: none;
         }
-        
+
         div#tabs {
             border: none;
         }
+
+        div.by_day_controls {
+            display: none;
+        }
     </style>
-    
+
     <script type="text/javascript">
         $(document).ready(function() {
             $("#tabs").tabs()
+
+            $("#show_details").click(function() {
+                if ($(this).attr("checked")) {
+                    $(".by_date_row").show();
+                } else {
+                    $(".by_date_row").hide();
+                }
+
+            })
+
+            $("#show_totals").click(function() {
+                if ($(this).attr("checked")) {
+                    $(".by_date_total_row").show();
+                } else {
+                    $(".by_date_total_row").hide();
+                }
+
+
+            })
         });
     </script>
 </head>
 <body>
 
-<h1>%(title)s</h1>
+<h1>$title</h1>
 
 
 
-<div id="tabs"> 
-	<ul> 
-		<li><a href="#tabs-1">%(totals_by_day_title)s</a></li> 
-		<li><a href="#tabs-2">%(activity_log_title)s</a></li> 
-	</ul> 
-	<div id="tabs-1"> 
-        <table>
-            %(by_date_rows)s
-        </table>
+<div id="tabs">
+	<ul>
+            <li><a href="#tabs-1">$totals_by_day_title</a></li>
+            <li><a href="#tabs-2">$activity_log_title</a></li>
+	</ul>
+	<div id="tabs-1">
+            <div class="by_day_controls">
+                Show:
+                <input type="checkbox" id="show_details" checked="checked"></input>
+                <label for="show_details">$activity_totals_heading</label>
+                
+                <input type="checkbox" id="show_totals" checked="checked"></input>
+                <label for="show_totals">$category_totals_heading</label>
+            </div>
+
+            <table>
+                <tr>
+                    <th>Date</th>
+                    <th class="by_date_row">$activity_totals_heading</th>
+                    <th class="by_date_total_row">$category_totals_heading</th>
+                <tr>
+
+                $by_date_rows
+            </table>
 	</div>
-	<div id="tabs-2"> 
-        <table>
-            <tr>
-                <th>%(header_date)s</th>
-                <th>%(header_activity)s</th>
-                <th>%(header_category)s</th>
-                <th>%(header_tags)s</th>
-                <th>%(header_start)s</th>
-                <th>%(header_duration)s</th>
-                <th>%(header_description)s</th>
-            </tr>
-            %(all_record_rows)s
-        </table>
+	<div id="tabs-2">
+            <table>
+                <tr>
+                    <th>$header_date</th>
+                    <th>$header_activity</th>
+                    <th>$header_category</th>
+                    <th>$header_tags</th>
+                    <th>$header_start</th>
+                    <th>$header_duration</th>
+                    <th>$header_description</th>
+                </tr>
+                $all_record_rows
+            </table>
 	</div>
 </div>
-
-
diff --git a/src/hamster/reports.py b/src/hamster/reports.py
index d0adf5e..af16071 100644
--- a/src/hamster/reports.py
+++ b/src/hamster/reports.py
@@ -26,9 +26,10 @@ import csv
 from hamster.i18n import C_
 from hamster.configuration import runtime
 import copy
-import StringIO
 import itertools
 
+from string import Template
+
 def simple(facts, start_date, end_date, format, path):
     facts = copy.deepcopy(facts) # dont want to do anything bad to the input
     report_path = stuff.locale_from_utf8(path)
@@ -224,7 +225,7 @@ class HTMLWriter(ReportWriter):
             duration = stuff.format_duration(fact["delta"]) or "",
             description = fact["description"] or ""
         )
-        self.fact_rows.append(self.fact_row_template % data)
+        self.fact_rows.append(Template(self.fact_row_template).safe_substitute(data))
 
 
     def _finish(self, report, facts):
@@ -242,10 +243,10 @@ class HTMLWriter(ReportWriter):
                     duration += fact['delta']
 
 
-                by_date_rows.append(self.by_date_row_template %
+                by_date_rows.append(Template(self.by_date_row_template).safe_substitute(
                                     dict(activity = activity,
                                          category = category,
-                                         duration = stuff.format_duration(duration)))
+                                         duration = stuff.format_duration(duration))))
 
             by_date_total_rows = []
             for category, c_facts in itertools.groupby(by_name, lambda fact:fact['category']):
@@ -254,13 +255,13 @@ class HTMLWriter(ReportWriter):
                     duration += fact['delta']
 
 
-                by_date_total_rows.append(self.by_date_total_row_template %
+                by_date_total_rows.append(Template(self.by_date_total_row_template).safe_substitute(
                                           dict(category = category,
-                                               duration = stuff.format_duration(duration)))
+                                               duration = stuff.format_duration(duration))))
 
 
 
-            by_date.append(self.by_date_template %
+            by_date.append(Template(self.by_date_template).safe_substitute(
                            dict(date = fact["date"].strftime(
                                        # date column format for each row in HTML report
                                        # Using python datetime formatting syntax. See:
@@ -268,13 +269,16 @@ class HTMLWriter(ReportWriter):
                                        C_("html report","%b %d, %Y")),
                                 by_date_rows = "\n".join(by_date_rows),
                                 by_date_total_rows = "\n".join(by_date_total_rows),
-                           ))
+                           )))
 
         data = dict(
             title = self.title,
             totals_by_day_title = _("Totals by Day"),
             activity_log_title = _("Activity Log"),
 
+            activity_totals_heading = _("totals by activity"),
+            category_totals_heading = _("totals by category"),
+
             header_date = _("Date"),
             header_activity = _("Activity"),
             header_category = _("Category"),
@@ -288,6 +292,6 @@ class HTMLWriter(ReportWriter):
             by_date_rows = "\n".join(by_date)
         )
 
-        report.write(self.main_template % data)
+        report.write(Template(self.main_template).safe_substitute(data))
 
         return



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]