[hamster-applet] added alternative, handier formats for durations and times to allow scripting. also pointing to temp
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] added alternative, handier formats for durations and times to allow scripting. also pointing to temp
- Date: Sun, 6 Jun 2010 08:28:07 +0000 (UTC)
commit d52ad1947e96e2c4157ce4a566435375cf0a0857
Author: Toms Bauģis <toms baugis gmail com>
Date: Sun Jun 6 09:28:00 2010 +0100
added alternative, handier formats for durations and times to allow scripting. also pointing to templates to allow discovery
data/html_template/by_date_row.html | 5 +++-
data/html_template/by_date_total_row.html | 5 +++-
data/html_template/fact_row.html | 20 +++++++++++++++---
data/html_template/main.html | 14 ++++++++++--
src/hamster/reports.py | 30 +++++++++++++++++++++++-----
5 files changed, 59 insertions(+), 15 deletions(-)
---
diff --git a/data/html_template/by_date_row.html b/data/html_template/by_date_row.html
index 1612b74..2ac36cb 100644
--- a/data/html_template/by_date_row.html
+++ b/data/html_template/by_date_row.html
@@ -1,4 +1,7 @@
<tr>
<td>$activity ($category)</td>
- <td style="text-align: right">$duration</td>
+ <td style="text-align: right">
+ <!-- there is also duration_decimal and duration_minutes -->
+ $duration
+ </td>
</tr>
diff --git a/data/html_template/by_date_total_row.html b/data/html_template/by_date_total_row.html
index 53e07da..45ec44f 100644
--- a/data/html_template/by_date_total_row.html
+++ b/data/html_template/by_date_total_row.html
@@ -1,4 +1,7 @@
<tr>
<td>$category</td>
- <td style="text-align: right">$duration</td>
+ <td style="text-align: right">
+ <!-- there is also duration_decimal and duration_minutes -->
+ $duration
+ </td>
</div>
diff --git a/data/html_template/fact_row.html b/data/html_template/fact_row.html
index ab3c052..c7c337d 100644
--- a/data/html_template/fact_row.html
+++ b/data/html_template/fact_row.html
@@ -1,10 +1,22 @@
<tr>
- <td>$date</td>
+ <td>
+ <!-- there is also date_iso -->
+ $date
+ </td>
<td>$activity</td>
<td>$category</td>
<td>$tags</td>
- <td>$start</td>
- <td>$duration</td>
+ <td>
+ <!-- there is also start_iso -->
+ $start
+ </td>
+ <td>
+ <!-- there is also end_iso -->
+ $end
+ </td>
+ <td>
+ <!-- there is also duration_decimal and duration_minutes -->
+ $duration
+ </td>
<td>$description</td>
</tr>
-
diff --git a/data/html_template/main.html b/data/html_template/main.html
index 5793693..8a9303b 100644
--- a/data/html_template/main.html
+++ b/data/html_template/main.html
@@ -51,6 +51,10 @@
div.by_day_controls {
display: none;
}
+
+ p.template-instructions {
+ display: none;
+ }
</style>
<script type="text/javascript">
@@ -82,8 +86,6 @@
<h1>$title</h1>
-
-
<div id="tabs">
<ul>
<li><a href="#tabs-1">$totals_by_day_title</a></li>
@@ -94,7 +96,7 @@
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>
@@ -117,6 +119,7 @@
<th>$header_category</th>
<th>$header_tags</th>
<th>$header_start</th>
+ <th>$header_end</th>
<th>$header_duration</th>
<th>$header_description</th>
</tr>
@@ -124,3 +127,8 @@
</table>
</div>
</div>
+
+<p class="template-instructions">
+ <a href="file:///$data_dir/html_template">$show_templates</a>.
+ $template_instructions.
+</p>
diff --git a/src/hamster/reports.py b/src/hamster/reports.py
index af16071..86682f8 100644
--- a/src/hamster/reports.py
+++ b/src/hamster/reports.py
@@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
import stuff
-import os
+import os, sys
import datetime as dt
from xml.dom.minidom import Document
import csv
@@ -202,9 +202,10 @@ class HTMLWriter(ReportWriter):
def _write_fact(self, report, fact):
# no having end time is fine
- end_time_str = ""
+ end_time_str, end_time_iso_str = "", ""
if fact["end_time"]:
end_time_str = fact["end_time"].strftime('%H:%M')
+ end_time_iso_str = fact["end_time"].isoformat()
category = ""
if fact["category"] != _("Unsorted"): #do not print "unsorted" in list
@@ -212,17 +213,22 @@ class HTMLWriter(ReportWriter):
data = dict(
- date = fact["start_time"].strftime(
+ date = fact["date"].strftime(
# date column format for each row in HTML report
# Using python datetime formatting syntax. See:
# http://docs.python.org/library/time.html#time.strftime
C_("html report","%b %d, %Y")),
+ date_iso = fact["date"].isoformat(),
activity = fact["name"],
category = category,
tags = fact["tags"],
start = fact["start_time"].strftime('%H:%M'),
+ start_iso = fact["start_time"].isoformat(),
end = end_time_str,
+ end_iso = end_time_iso_str,
duration = stuff.format_duration(fact["delta"]) or "",
+ duration_minutes = "%d" % (stuff.duration_minutes(fact["delta"])),
+ duration_decimal = "%.2f" % (stuff.duration_minutes(fact["delta"]) / 60.0),
description = fact["description"] or ""
)
self.fact_rows.append(Template(self.fact_row_template).safe_substitute(data))
@@ -246,7 +252,11 @@ class HTMLWriter(ReportWriter):
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),
+ duration_minutes = "%d" % (stuff.duration_minutes(fact["delta"])),
+ duration_decimal = "%.2f" % (stuff.duration_minutes(fact["delta"]) / 60.0),
+ )
+ ))
by_date_total_rows = []
for category, c_facts in itertools.groupby(by_name, lambda fact:fact['category']):
@@ -257,7 +267,11 @@ class HTMLWriter(ReportWriter):
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),
+ duration_minutes = "%d" % (stuff.duration_minutes(fact["delta"])),
+ duration_decimal = "%.2f" % (stuff.duration_minutes(fact["delta"]) / 60.0),
+ )
+ ))
@@ -289,7 +303,11 @@ class HTMLWriter(ReportWriter):
header_description = _("Description"),
all_record_rows = "\n".join(self.fact_rows),
- by_date_rows = "\n".join(by_date)
+ by_date_rows = "\n".join(by_date),
+
+ data_dir = runtime.data_dir,
+ show_templates = _("Show templates"),
+ template_instructions = _("You can override them by storing your version in %s" % runtime.home_data_dir),
)
report.write(Template(self.main_template).safe_substitute(data))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]