Skip to content

Commit

Permalink
Record a log of sent reports
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Sep 9, 2015
1 parent aafe254 commit 861fc14
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions mockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,20 @@ def on_send_report(self, action, parameter):
if not body:
return
if self.email(sender, recipient, body):
self.record_sent_email(self.report_view.get_report_kind(),
self.report_view.get_report_id(),
recipient)
self.on_cancel_report()

def record_sent_email(self, report_kind, report_id, recipient):
filename = Settings().get_report_log_file()
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
try:
with open(filename, 'a') as f:
f.write("{},{},{},{}\n".format(timestamp, report_kind, report_id, recipient))
except IOError as e:
self.complain("Couldn't append to {}: {}".format(filename, e))

def on_cancel_report(self, action=None, parameter=None):
self.main_stack.set_visible_child_name('entry')
self.headerbar.get_style_context().remove_class('selection-mode')
Expand Down Expand Up @@ -1181,6 +1193,25 @@ def get_time_window(self):
def get_report_text(self):
return self.get_buffer().props.text

def get_report_id(self):
if self.time_range == 'day':
return self.date.strftime('%Y-%m-%d')
elif self.time_range == 'week':
# I'd prefer the ISO 8601 format (2015-W31 instead of 2015/31), but
# let's be compatible with https://github.com/ProgrammersOfVilnius/gtimesheet
return '{}/{}'.format(self.date.year, self.date.isocalendar()[1])
elif self.time_range == 'month':
return self.date.strftime('%Y-%m')

def get_report_kind(self):
# Let's be compatible with https://github.com/ProgrammersOfVilnius/gtimesheet
if self.time_range == 'day':
return 'daily'
elif self.time_range == 'week':
return 'weekly'
elif self.time_range == 'month':
return 'monthly'

def populate_report(self):
self._update_pending = False
self.get_buffer().set_text('')
Expand Down
3 changes: 3 additions & 0 deletions src/gtimelog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def get_timelog_file(self):
def get_time_log(self):
return TimeLog(self.get_timelog_file(), self.virtual_midnight)

def get_report_log_file(self):
return os.path.join(self.get_data_dir(), 'sentreports.log')

def get_task_list_file(self):
return os.path.join(self.get_data_dir(), 'tasks.txt')

Expand Down

0 comments on commit 861fc14

Please sign in to comment.