Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error in untouched tasks plugin #927

Merged
merged 2 commits into from
Oct 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions GTG/plugins/untouched_tasks/untouchedTasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright (c) 2012 - Tom Kadwill <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it under
Expand Down Expand Up @@ -26,7 +25,6 @@


class UntouchedTasksPlugin():

DEFAULT_PREFERENCES = {'max_days': 30,
'is_automatic': False,
'default_tag': 'untouched'}
Expand All @@ -51,11 +49,11 @@ def __init__(self):
self.builder.get_object("pref_tag_name")
SIGNAL_CONNECTIONS_DIC = {
"on_preferences_dialog_delete_event":
self.on_preferences_cancel,
self.on_preferences_cancel,
"on_btn_preferences_cancel_clicked":
self.on_preferences_cancel,
self.on_preferences_cancel,
"on_btn_preferences_ok_clicked":
self.on_preferences_ok,
self.on_preferences_ok,
}

self.builder.connect_signals(SIGNAL_CONNECTIONS_DIC)
Expand All @@ -80,7 +78,7 @@ def deactivate(self, plugin_api):
"""
plugin_api.remove_menu_item(self.menu_item)

# CORE FUNCTIONS ##############################################################
# CORE FUNCTIONS ##############################################################
def schedule_autopurge(self):
self.timer = Timer(self.TIME_BETWEEN_PURGES,
self.add_untouched_tag)
Expand All @@ -100,7 +98,7 @@ def add_untouched_tag(self, action=None, param=None):
tag_name = self.preferences['default_tag']

log.debug("Starting process for adding %s", tag_name)
today = datetime.datetime.now()
today = datetime.date.today()
max_days = self.preferences["max_days"]
requester = self.plugin_api.get_requester()
closed_tree = requester.get_tasks_tree(name='inactive')
Expand All @@ -110,7 +108,11 @@ def add_untouched_tag(self, action=None, param=None):
# Add untouched tag to all tasks where new_date < time now
for task in closed_tasks:
modified_time = task.get_modified()
# get_modified might return a gtg.core.Date or a datetime.datetime. The validity of the comparison depends
# on which one we get, so check explicitly. This should probably be fixed in Task, eventually.
new_time = modified_time + datetime.timedelta(days=max_days)
if type(new_time) == datetime.datetime:
new_time = new_time.date()
if new_time < today:
log.debug('Adding %r tag to: %r as last time it was modified '
'was %r', tag_name, task.get_title(), modified_time)
Expand All @@ -120,7 +122,7 @@ def add_untouched_tag(self, action=None, param=None):
if self.is_automatic:
self.schedule_autopurge()

# Preferences methods #########################################################
# Preferences methods #########################################################
def is_configurable(self):
"""A configurable plugin should have this method and return True"""
return True
Expand Down