[hamster-applet] took some shortcuts. for that changed tag word separator from dash to underscore



commit c466029f06a914a32b283d6b03732d862dcf3368
Author: Toms Bauģis <toms baugis gmail com>
Date:   Sun Jun 6 14:29:02 2010 +0100

    took some shortcuts. for that changed tag word separator from dash to underscore

 data/report_template.html |   16 ++++++++--------
 src/hamster/reports.py    |   36 ++++++++++++------------------------
 2 files changed, 20 insertions(+), 32 deletions(-)
---
diff --git a/data/report_template.html b/data/report_template.html
index e0f80df..be3c7b7 100644
--- a/data/report_template.html
+++ b/data/report_template.html
@@ -108,12 +108,12 @@
                     <th class="by_date_total_row">$category_totals_heading</th>
                 <tr>
 
-                    <by-date>
+                    <by_date>
                         <tr valign="top">
                             <td>$date</td>
                             <td class="by_date_row">
                                 <table width="100%">
-                                    <by-date-activity>
+                                    <by_date_activity>
                                         <tr>
                                             <td>$activity ($category)</td>
                                             <td style="text-align: right">
@@ -121,24 +121,24 @@
                                                 $duration
                                             </td>
                                         </tr>
-                                    </by-date-activity>
+                                    </by_date_activity>
                                 </table>
                             </td>
                             <td class="by_date_total_row">
                                 <table width="100%">
-                                    <by-date-category>
+                                    <by_date_category>
                                         <tr>
                                             <td>$category</td>
                                             <td style="text-align: right">
                                                 <!-- there is also duration_decimal and duration_minutes -->
                                                 $duration
                                             </td>
-                                    </by-date-category>
+                                    </by_date_category>
                                 </table>
                             </td>
                         </tr>
                         <tr><td colspan="3">&nbsp</td></tr>
-                    </by-date>
+                    </by_date>
             </table>
 	</div>
 	<div id="tabs-2">
@@ -153,7 +153,7 @@
                     <th>$header_duration</th>
                     <th>$header_description</th>
                 </tr>
-                <all-activities>
+                <all_activities>
                     <tr>
                         <td>
                             <!-- there is also date_iso -->
@@ -176,7 +176,7 @@
                         </td>
                         <td>$description</td>
                     </tr>
-                </all-activities>
+                </all_activities>
             </table>
 	</div>
 </div>
diff --git a/src/hamster/reports.py b/src/hamster/reports.py
index 7744969..5c4839d 100644
--- a/src/hamster/reports.py
+++ b/src/hamster/reports.py
@@ -191,16 +191,12 @@ class HTMLWriter(ReportWriter):
             self.main_template =f.read()
 
 
-        self.fact_row_re = re.compile('<all-activities>(.*)</all-activities>', re.DOTALL)
+        self.fact_row_template = self._extract_template('all_activities')
 
-        self.fact_row_template = self.fact_row_re.search(self.main_template)
+        self.by_date_row_template = self._extract_template('by_date_activity')
+        self.by_date_total_row_template = self._extract_template("by_date_category")
 
-        self.fact_row_template = self._extract_template('all-activities')
-
-        self.by_date_row_template = self._extract_template('by-date-activity')
-        self.by_date_total_row_template = self._extract_template("by-date-category")
-
-        self.by_date_template = self._extract_template('by-date')
+        self.by_date_template = self._extract_template('by_date')
 
         self.fact_rows = []
 
@@ -210,15 +206,11 @@ class HTMLWriter(ReportWriter):
         match = pattern.search(self.main_template)
 
         if match:
-            self.main_template = self.main_template.replace(match.group(), "<the-actual-%s>" % name)
+            self.main_template = self.main_template.replace(match.group(), "$%s_rows" % name)
             return match.groups()[0]
 
         return ""
 
-    def _replace_template(self, target, name, value):
-        return target.replace('<the-actual-%s>' % name, value)
-
-
 
     def _write_fact(self, report, fact):
         # no having end time is fine
@@ -299,12 +291,10 @@ class HTMLWriter(ReportWriter):
                                        # 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"))
+                                       C_("html report","%b %d, %Y")),
+                                by_date_activity_rows = "\n".join(by_date_rows),
+                                by_date_category_rows = "\n".join(by_date_total_rows)
                            ))
-
-            res = self._replace_template(res, 'by-date-activity', "\n".join(by_date_rows))
-            res = self._replace_template(res, 'by-date-category', "\n".join(by_date_total_rows))
-
             by_date.append(res)
 
 
@@ -329,13 +319,11 @@ class HTMLWriter(ReportWriter):
             data_dir = runtime.data_dir,
             show_template = _("Show template"),
             template_instructions = _("You can override them by storing your version in %s" % runtime.home_data_dir),
-        )
 
-        self.main_template = Template(self.main_template).safe_substitute(data)
-        self.main_template = self._replace_template(self.main_template, 'all-activities', "\n".join(self.fact_rows))
-        self.main_template = self._replace_template(self.main_template, 'by-date', "\n".join(by_date))
-
-        report.write(self.main_template)
+            all_activities_rows = "\n".join(self.fact_rows),
+            by_date_rows = "\n".join(by_date)
+        )
+        report.write(Template(self.main_template).safe_substitute(data))
 
 
         return



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