Package: gtimelog
Version: 0.0+svn88-2
Severity: wishlist
Tags: patch

Hiya,

gtimelog is very useful for me already, but...

We have a silly web-based timesheet entry system at work, which needs
aggregate times on various tasks entering into the system,
*summarised* per-day but entered into a form that has space for a
whole week. I've added support for generating such a summary into my
own local version of gtimelog. In case it's useful for others, the
diff is attached here.

-- 
Steve McIntyre, Amino                                [EMAIL PROTECTED]
"They say that you play Cambridge twice - once on the way up and once on the
 way down. It's nice to be back..." --- Armstrong & Miller
--- /usr/share/gtimelog/gtimelog.glade	2008-03-20 21:30:20.000000000 +0000
+++ bin/gtimelog.glade	2008-07-15 17:58:32.000000000 +0100
@@ -275,6 +275,27 @@
 		  </child>
 
 		  <child>
+		    <widget class="GtkImageMenuItem" id="previous_week_summary">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Weekly Summary for a Pre_vious Week</property>
+		      <property name="use_underline">True</property>
+		      <signal name="activate" handler="on_previous_week_summary_activate" last_modification_time="Wed, 13 Apr 2005 17:51:25 GMT"/>
+
+		      <child internal-child="image">
+			<widget class="GtkImage" id="image30">
+			  <property name="visible">True</property>
+			  <property name="stock">gtk-indent</property>
+			  <property name="icon_size">1</property>
+			  <property name="xalign">0.5</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+		      </child>
+		    </widget>
+		  </child>
+
+		  <child>
 		    <widget class="GtkImageMenuItem" id="monthly_report">
 		      <property name="visible">True</property>
 		      <property name="label" translatable="yes">_Monthly Report</property>
--- /usr/bin/gtimelog	2008-03-20 21:30:20.000000000 +0000
+++ bin/gtimelog	2008-07-15 18:54:03.000000000 +0100
@@ -333,7 +333,7 @@
         work.sort()
         writer.writerows(work)
 
-    def daily_report(self, output, email, who):
+    def daily_report(self, output, email, who, headers=True):
         """Format a daily report.
 
         Writes a daily report template in RFC-822 format to output.
@@ -343,12 +343,14 @@
         weekday_names = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
         weekday = weekday_names[self.min_timestamp.weekday()]
         week = self.min_timestamp.strftime('%V')
-        print >> output, "To: %(email)s" % {'email': email}
-        print >> output, ("Subject: %(date)s report for %(who)s"
-                          " (%(weekday)s, week %(week)s)"
-                          % {'date': self.min_timestamp.strftime('%Y-%m-%d'),
-                             'weekday': weekday, 'week': week, 'who': who})
-        print >> output
+        if headers:
+            print >> output, "To: %(email)s" % {'email': email}
+            print >> output, ("Subject: %(date)s report for %(who)s"
+                              " (%(weekday)s, week %(week)s)"
+                              % {'date': self.min_timestamp.strftime('%Y-%m-%d'),
+                                 'weekday': weekday, 'week': week, 'who': who})
+            print >> output
+
         items = list(self.all_entries())
         if not items:
             print >> output, "No work done today."
@@ -1152,6 +1154,35 @@
             window = self.weekly_window(day=day)
             self.mail(window.weekly_report)
 
+    def on_previous_week_summary_activate(self, widget):
+        """File -> Daily Summary for a Previous Week"""
+        weekday_names = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
+        day = self.choose_date()
+        if day:
+            min = datetime.datetime.combine(day, self.timelog.virtual_midnight)
+            window = self.timelog.window_for(min, min+datetime.timedelta(1))
+            week = window.min_timestamp.strftime('%V')
+            summaryfn = tempfile.mktemp(suffix='gtimelog') # XXX unsafe!
+            summary = open(summaryfn, 'w')
+            print >> summary, "To: %(email)s" % {'email': self.settings.email}
+            print >> summary, ("Subject: Weekly summary for %(who)s "
+                               "(week %(week)s, starting Mon %(date)s)"
+                          % {'week': week, 'who': self.settings.name,
+                             'date': window.min_timestamp.strftime('%Y-%m-%d')})
+            print >> summary
+
+            i = 0
+            while i < 7:
+                print >> summary, "%(dayname)s:\n----" % {'dayname': weekday_names[i]}
+                window = self.timelog.window_for(min, min+datetime.timedelta(1))
+                window.daily_report(summary, self.settings.email, self.settings.name, False)
+                min += datetime.timedelta(1)
+                i += 1
+                print >> summary
+            summary.close()
+            self.spawn(self.settings.mailer, summaryfn)
+            # XXX rm summaryfn when done -- but how?
+
     def monthly_window(self, day=None):
         if not day:
             day = self.timelog.day

Reply via email to